diff --git a/bson/datetime_ms.py b/bson/datetime_ms.py index f3e25ed05..925087a5a 100644 --- a/bson/datetime_ms.py +++ b/bson/datetime_ms.py @@ -12,7 +12,10 @@ # implied. See the License for the specific language governing # permissions and limitations under the License. -"""Tools for representing the BSON datetime type.""" +"""Tools for representing the BSON datetime type. + +.. versionadded:: 4.3 +""" import calendar import datetime @@ -31,26 +34,28 @@ EPOCH_NAIVE = datetime.datetime.utcfromtimestamp(0) class DatetimeMS: + """Represents a BSON UTC datetime.""" + __slots__ = ("_value",) def __init__(self, value: Union[int, datetime.datetime]): """Represents a BSON UTC datetime. - BSON UTC datetimes are defined as an int64 of milliseconds since the Unix - epoch. The principal use of DatetimeMS is to represent datetimes outside - the range of the Python builtin :class:`~datetime.datetime` class when + BSON UTC datetimes are defined as an int64 of milliseconds since the + Unix epoch. The principal use of DatetimeMS is to represent + datetimes outside the range of the Python builtin + :class:`~datetime.datetime` class when encoding/decoding BSON. - To decode UTC datetimes as a ``DatetimeMS``,`datetime_conversion` in + To decode UTC datetimes as a ``DatetimeMS``, `datetime_conversion` in :class:`~bson.CodecOptions` must be set to 'datetime_ms' or - 'datetime_auto'. See :ref:`handling-out-of-range-datetimes` for details. + 'datetime_auto'. See :ref:`handling-out-of-range-datetimes` for + details. :Parameters: - `value`: An instance of :class:`datetime.datetime` to be - represented as milliseconds since the Unix epoch, or int of - milliseconds since the Unix epoch. - - .. versionadded:: 4.3 + represented as milliseconds since the Unix epoch, or int of + milliseconds since the Unix epoch. """ if isinstance(value, int): if not (-(2**63) <= value <= 2**63 - 1): diff --git a/doc/api/bson/datetime_ms.rst b/doc/api/bson/datetime_ms.rst index 254f115eb..1afaad69f 100644 --- a/doc/api/bson/datetime_ms.rst +++ b/doc/api/bson/datetime_ms.rst @@ -1,4 +1,6 @@ :mod:`datetime_ms` -- Support for BSON UTC Datetime =================================================== + .. automodule:: bson.datetime_ms + :synopsis: Support for BSON UTC datetimes. :members: