Skip to content

time.localtime returns unexpected values #204

@azmeuk

Description

@azmeuk

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions