Closed d3dave closed 1 year ago
@roi-granulate Please test, thanks.
LGTM. What's between
datetime.now()
anddatetime.utcnow()
btw?
utcnow()
returns a TZ-unaware object. now()
returns a TZ-aware object. So if you try to get timestamp()
of TZ-unaware object, it will assume it is in local time and you'd get a wrong result:
In [5]: datetime.now(tz=timezone.utc)
Out[5]: datetime.datetime(2023, 3, 6, 14, 8, 39, 670833, tzinfo=datetime.timezone.utc)
In [6]: _.timestamp()
Out[6]: 1678111719.670833
In [7]: datetime.utcnow()
Out[7]: datetime.datetime(2023, 3, 6, 14, 8, 48, 270091)
In [8]: _.timestamp()
Out[8]: 1678104528.270091
LGTM. What's between
datetime.now()
anddatetime.utcnow()
btw?
utcnow()
returns a TZ-unaware object.now()
returns a TZ-aware object. So if you try to gettimestamp()
of TZ-unaware object, it will assume it is in local time and you'd get a wrong result:In [5]: datetime.now(tz=timezone.utc) Out[5]: datetime.datetime(2023, 3, 6, 14, 8, 39, 670833, tzinfo=datetime.timezone.utc) In [6]: _.timestamp() Out[6]: 1678111719.670833 In [7]: datetime.utcnow() Out[7]: datetime.datetime(2023, 3, 6, 14, 8, 48, 270091) In [8]: _.timestamp() Out[8]: 1678104528.270091
Oh wow. TIL
time.monotonic does not represent current time.