Last active
January 1, 2016 01:19
-
-
Save tleach/8072406 to your computer and use it in GitHub Desktop.
How BSON encodes a datetime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if isinstance(value, datetime.datetime): | |
if value.utcoffset() is not None: | |
value = value - value.utcoffset() | |
millis = int(calendar.timegm(value.timetuple()) * 1000 + | |
value.microsecond / 1000) | |
return BSONDAT + name + struct.pack("<q", millis) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment