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

datetime_to_fakedatetime function ignores fold parameter #422

Open
alexander-doroshenko opened this issue Oct 31, 2021 · 1 comment · May be fixed by #424
Open

datetime_to_fakedatetime function ignores fold parameter #422

alexander-doroshenko opened this issue Oct 31, 2021 · 1 comment · May be fixed by #424

Comments

@alexander-doroshenko
Copy link

alexander-doroshenko commented Oct 31, 2021

since python 3.6 version to datetime class was added fold argument to disambiguate the times during a repeated interval.

An example of where it can hurt :

from datetime import timezone, datetime
from freezegun import api

d = datetime(2021, 10, 30, 23, tzinfo=timezone.utc)
fd = api.FakeDatetime(2021, 10, 30, 23, tzinfo=timezone.utc)
isr = tz.gettz('Israel')
d.astimezone(isr).dst() == fd.astimezone(isr).dst()
>> False
@emontnemery emontnemery linked a pull request Nov 2, 2021 that will close this issue
@couling
Copy link

couling commented Sep 26, 2023

In real terms this is particularly frustrating because we can't test TZ changes in our code. This is one of the big use cases for us.

>>> from datetime import datetime
>>> from zoneinfo import ZoneInfo
>>>
>>> from freezegun import freeze_time
>>>
>>> UTC = ZoneInfo("UTC")
>>> UK = ZoneInfo("Europe/London")
>>>
>>> before_change = datetime(2023, 10, 29, 0, 30, tzinfo=UTC)
>>> with freeze_time(before_change):
...     print(before_change.astimezone(UK))
...     print(datetime.now(UTC).astimezone(UK))
...
2023-10-29 01:30:00+01:00
2023-10-29 01:30:00+01:00
>>> after_change = datetime(2023, 10, 29, 1, 30, tzinfo=UTC)
>>> with freeze_time(after_change):
...     print(after_change.astimezone(UK))
...     print(datetime.now(UTC).astimezone(UK))
...
2023-10-29 01:30:00+00:00
2023-10-29 01:30:00+01:00

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.

2 participants