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

time.localtime returns unexpected values #204

Open
azmeuk opened this issue Aug 30, 2017 · 1 comment · May be fixed by #526
Open

time.localtime returns unexpected values #204

azmeuk opened this issue Aug 30, 2017 · 1 comment · May be fixed by #526
Labels

Comments

@azmeuk
Copy link
Contributor

azmeuk commented Aug 30, 2017

Freezegun mocked time.localtime seems to depend on the environment timezone.

# localtime.py
import freezegun, time
with freezegun.freeze_time("1970-07-01 00:00:01"):
    print(time.localtime())
$ env TZ=CET python localtime.py
time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=1, tm_min=0, tm_sec=1, tm_wday=3, tm_yday=1, tm_isdst=-1)

$ env TZ=UTC python localtime.py
time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=1, tm_wday=3, tm_yday=1, tm_isdst=-1)

$ env TZ=CET faketime "1970-01-01 00:00:01" python -c "import time; print(time.localtime())"
time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=1, tm_wday=3, tm_yday=1, tm_isdst=0)

$ env TZ=UTC faketime "1970-01-01 00:00:01" python -c "import time; print(time.localtime())"
time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=1, tm_wday=3, tm_yday=1, tm_isdst=0)

In CET it produces tm_hour=1 but I think it should be tm_hour=0 like it is in UTC. I believe that freezegun takes the environment timezone into account when mocking localtime, when I would expect it to consider a default UTC timezone.

I also noticed that libfaketime produce a tm_isdst=0 when Freezegun produce tm_isdst=-1 but I am not sure what I am thinking about that.

@boxed
Copy link
Contributor

boxed commented Sep 29, 2018

The problem is at https://github.com/spulec/freezegun/blob/master/freezegun/api.py#L175

This code explicitly leaks the local time zone offset.

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

Successfully merging a pull request may close this issue.

3 participants