Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bson/objectid.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def from_datetime(cls, generation_time):
generation_time = generation_time - generation_time.utcoffset()
timestamp = calendar.timegm(generation_time.timetuple())
oid = struct.pack(
">i", int(timestamp)) + b"\x00\x00\x00\x00\x00\x00\x00\x00"
">L", int(timestamp) & 0xFFFFFFFF) + b"\x00\x00\x00\x00\x00\x00\x00\x00"
return cls(oid)

@classmethod
Expand All @@ -184,7 +184,7 @@ def __generate(self):
"""

# 4 bytes current time
oid = struct.pack(">i", int(time.time()))
oid = struct.pack(">L", int(time.time()) & 0xFFFFFFFF)

# 3 bytes machine
oid += ObjectId._machine_bytes
Expand Down
2 changes: 1 addition & 1 deletion bson/tests/test_objectid.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ def test_from_datetime(self):
if 'PyPy 1.8.0' in sys.version:
# See https://bugs.pypy.org/issue1092
raise SkipTest("datetime.timedelta is broken in pypy 1.8.0")
d = datetime.datetime.utcnow()
d = datetime.datetime.utcfromtimestamp(2000000000)
d = d - datetime.timedelta(microseconds=d.microsecond)
oid = ObjectId.from_datetime(d)
self.assertEqual(d, oid.generation_time.replace(tzinfo=None))
Expand Down