-
Notifications
You must be signed in to change notification settings - Fork 288
Open
Description
Experiencing something similar to what's mentioned in #472:
import datetime
now = datetime.datetime.now(datetime.timezone.utc)
now.astimezone().tzinfoOutputs: datetime.timezone(datetime.timedelta(seconds=7200), 'CEST')
But:
import freezegun
with freezegun.freeze_time("2025-04-01T00:00"):
frozen_now = datetime.datetime.now(datetime.timezone.utc)
frozen_now.astimezone().tzinfoOutputs: tzlocal()
I would expect the behaviour to be equal here.
Edit: The reason we stumbled across this was attempting to do now.astimezone().tzinfo.tzname(None). When using freezegun this fails with the following traceback:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File ".venv/lib/python3.12/site-packages/dateutil/tz/tz.py", line 238, in tzname
return self._tznames[self._isdst(dt)]
^^^^^^^^^^^^^^^
File ".venv/lib/python3.12/site-packages/dateutil/tz/tz.py", line 291, in _isdst
dstval = self._naive_is_dst(dt)
^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.12/site-packages/dateutil/tz/tz.py", line 259, in _naive_is_dst
timestamp = _datetime_to_timestamp(dt)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.12/site-packages/dateutil/tz/tz.py", line 1814, in _datetime_to_timestamp
return (dt.replace(tzinfo=None) - EPOCH).total_seconds()
^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'replace'
jedie and jenshnielsen
Metadata
Metadata
Assignees
Labels
No labels