You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from datetime import datetime
from freezegun import freeze_time
now = datetime.now()
epochtime1 = now.timestamp()
with freeze_time(now):
epochtime2 = datetime.now().timestamp()
print(epochtime2 - epochtime1)
The output is:
3600.0
I would expect the output to be 0
I have a workaround, but feels weird:
from datetime import datetime
from freezegun import freeze_time
now = datetime.now()
# epochtime1 = now.timestamp() # This is of no use, because of the freezegun bug
with freeze_time(now):
now = datetime.now() # Because of a (potential?) freezegun bug, we need to get "now" again after freezing
epochtime1 = now.timestamp() # Now we get the reference epoch again
epochtime2 = datetime.now().timestamp() # This happens deep in my code. Here for demonstration purposes
print(epochtime2 - epochtime1)
The text was updated successfully, but these errors were encountered:
I am also puzzled by the fact that, while time is frozen, datetime.datetime.utcnow() and datetime.datetime.now() are both equal. I'm not sure if my issue is related to OP's, but it surely feels like it has something to do with the timezone.
I have tried setting a tz_offset when freezing time, but that would just give wrong results when dealing with daylight saving time (DST).
The output is:
I would expect the output to be
0
I have a workaround, but feels weird:
The text was updated successfully, but these errors were encountered: