MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / _datetime_to_millis

Function _datetime_to_millis

bson/datetime_ms.py:116–120  ·  view source on GitHub ↗

Convert datetime to milliseconds since epoch UTC.

(dtm: datetime.datetime)

Source from the content-addressed store, hash-verified

114
115
116def _datetime_to_millis(dtm: datetime.datetime) -> int:
117 """Convert datetime to milliseconds since epoch UTC."""
118 if dtm.utcoffset() is not None:
119 dtm = dtm - dtm.utcoffset() # type: ignore
120 return int(calendar.timegm(dtm.timetuple()) * 1000 + dtm.microsecond // 1000)
121
122
123_MIN_UTC = datetime.datetime.min.replace(tzinfo=utc)

Callers 11

test_clampingMethod · 0.90
test_tz_clamping_utcMethod · 0.90
test_datetime_autoMethod · 0.90
from_datetimeMethod · 0.90
_encode_datetimeFunction · 0.90
_encode_datetimeFunction · 0.90
__init__Method · 0.85
datetime_ms.pyFile · 0.85

Calls 1

utcoffsetMethod · 0.45

Tested by 6

test_clampingMethod · 0.72
test_tz_clamping_utcMethod · 0.72
test_datetime_autoMethod · 0.72