pillar.api.utils.utcnow() now truncates microseconds to milliseconds
MongoDB stores datetimes in millisecond precision, to keep datetimes the same when roundtripping via MongoDB we now truncate the microseconds.
This commit is contained in:
parent
a67527d6af
commit
40c19a3cb0
@ -245,4 +245,10 @@ def random_etag() -> str:
|
||||
|
||||
|
||||
def utcnow() -> datetime.datetime:
|
||||
return datetime.datetime.now(tz=bson.tz_util.utc)
|
||||
"""Construct timezone-aware 'now' in UTC with millisecond precision."""
|
||||
now = datetime.datetime.now(tz=bson.tz_util.utc)
|
||||
|
||||
# MongoDB stores in millisecond precision, so truncate the microseconds.
|
||||
# This way the returned datetime can be round-tripped via MongoDB and stay the same.
|
||||
trunc_now = now.replace(microsecond=now.microsecond - (now.microsecond % 1000))
|
||||
return trunc_now
|
||||
|
Loading…
x
Reference in New Issue
Block a user