Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent behaviour for freeze_time #377

Open
gonvaled opened this issue Dec 24, 2020 · 1 comment
Open

Inconsistent behaviour for freeze_time #377

gonvaled opened this issue Dec 24, 2020 · 1 comment

Comments

@gonvaled
Copy link

gonvaled commented Dec 24, 2020

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)
@ccrisan
Copy link

ccrisan commented Dec 24, 2020

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants