Created
December 21, 2013 17:27
-
-
Save tleach/8072327 to your computer and use it in GitHub Desktop.
How BSON decodes 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
def _get_date(data, position, as_class, tz_aware, uuid_subtype): | |
millis = struct.unpack("<q", data[position:position + 8])[0] | |
diff = millis % 1000 | |
seconds = (millis - diff) / 1000 | |
position += 8 | |
if tz_aware: | |
dt = EPOCH_AWARE + datetime.timedelta(seconds=seconds) | |
else: | |
dt = EPOCH_NAIVE + datetime.timedelta(seconds=seconds) | |
return dt.replace(microsecond=diff * 1000), position |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment