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

tz_offset doesn't work with dateutil.tz #405

Open
mkenigs opened this issue Jul 15, 2021 · 0 comments · Fixed by priezz/freezegun#1 · May be fixed by #406
Open

tz_offset doesn't work with dateutil.tz #405

mkenigs opened this issue Jul 15, 2021 · 0 comments · Fixed by priezz/freezegun#1 · May be fixed by #406

Comments

@mkenigs
Copy link

mkenigs commented Jul 15, 2021

datetime.now(UTC) and datetime.utcnow() produce the same output in general, and they both have an offset from datetime.now(). But with freeze_time, datetime.now(UTC) does not have the offset:

datetime.now(): 2021-07-15 15:18:42.491281
datetime.now(UTC): 2021-07-15 20:18:42.491302+00:00
datetime.utcnow(): 2021-07-15 20:18:42.491311
datetime.now(): 2020-01-01 01:00:00
datetime.now(UTC): 2020-01-01 01:00:00+00:00
datetime.utcnow(): 2020-01-01 00:00:00
from datetime import datetime
from dateutil.tz import UTC
from freezegun import freeze_time

print(f'datetime.now(): {datetime.now()}')
print(f'datetime.now(UTC): {datetime.now(UTC)}')
print(f'datetime.utcnow(): {datetime.utcnow()}')
with freeze_time("2020-01-01T00:00:00Z", tz_offset=1):
    print(f'datetime.now(): {datetime.now()}')
    print(f'datetime.now(UTC): {datetime.now(UTC)}')
    print(f'datetime.utcnow(): {datetime.utcnow()}')
mkenigs added a commit to mkenigs/freezegun that referenced this issue Jul 23, 2021
now(tz) should return the same time utcnow returns adjusted by whatever
offset is contained by tz. Currently, the offset to freeze_time is also
added, which is removed by this change

Closes spulec#405
@mkenigs mkenigs linked a pull request Jul 23, 2021 that will close this issue
mkenigs added a commit to mkenigs/freezegun that referenced this issue Nov 3, 2021
now(tz) should return the same time utcnow returns adjusted by whatever
offset is contained by tz. Currently, the offset to freeze_time is also
added, which is removed by this change

Closes spulec#405
mkenigs added a commit to mkenigs/freezegun that referenced this issue Nov 3, 2021
now(tz) should return the same time utcnow returns adjusted by whatever
offset is contained by tz. Currently, the offset to freeze_time is also
added, which is removed by this change

The current unit test is wrong because the utc time is 2:00:00, so GMT5
should be 7:00:00, not 3:00:00

Closes spulec#405
mkenigs added a commit to mkenigs/freezegun that referenced this issue Nov 3, 2021
now(tz) should return the same time utcnow returns adjusted by whatever
offset is contained by tz. Currently, the offset to freeze_time is also
added, which is removed by this change

The current unit test is wrong because the UTC time is 2:00:00, so GMT5
should be 7:00:00, not 3:00:00

Closes spulec#405
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

Successfully merging a pull request may close this issue.

1 participant