PYTHON-3377 datetime_ms documentation page is empty (#1026)

Co-authored-by: Ben Warner <ben.warner@mongodb.com>
This commit is contained in:
Ben Warner 2022-07-29 12:07:04 -07:00 committed by GitHub
parent 0c56d56658
commit 3c18c20795
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 10 deletions

View File

@ -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):

View File

@ -1,4 +1,6 @@
:mod:`datetime_ms` -- Support for BSON UTC Datetime
===================================================
.. automodule:: bson.datetime_ms
:synopsis: Support for BSON UTC datetimes.
:members: