You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] ZoneInfo does not support datetime.Time and utcoffset can't be retrieved #117598
deftest():
fromzoneinfoimportZoneInfofromdatetimeimporttimet=time(12, 4, 5, 123456, tzinfo=ZoneInfo("Europe/Prague"), fold=1)
ift.tzinfo.utcoffset(None) isNone:
# if prevuous does not work this should but fails with# AttributeError: 'datetime.time' object has no attribute 'toordinal't.tzinfo.utcoffset(t)
i propose checking if instance is time and then skip to ordinal like so
t.tzinfo.utcoffset(t)utcoffset expects a datetime, so that it can figure out whether or not "Europe/Prague" is on daylight savings time, at the datetime in question.
I don't think it's a bug. It's Python requiring you to explicitly specify from which date you wish the daylight savings time to be used, for a time zone's UTC offset (which may vary on different days of the year).
Activity
JamesParrott commentedon Apr 7, 2024
I can recreate this on Windows, but below, aren't you asking zoneinfo a question that has an ambiguous answer?
t.tzinfo.utcoffset(t)
utcoffsetexpects a datetime, so that it can figure out whether or not "Europe/Prague" is on daylight savings time, at the datetime in question.07pepa commentedon Apr 7, 2024
actualy this works with pytz so maybe its pytz bug ?
JamesParrott commentedon Apr 7, 2024
I don't think it's a bug. It's Python requiring you to explicitly specify from which date you wish the daylight savings time to be used, for a time zone's UTC offset (which may vary on different days of the year).
07pepa commentedon Apr 7, 2024
That seems logical gona file bug on pytz
JamesParrott commentedon Apr 7, 2024
This is outside of CPython's scope now.
But, @07pepa I don't think it's a bug in pytz either. pytz has just chosen to always return self._utcoffset from timezone.utcoffset:
https://github.com/stub42/pytz/blob/fb43f957c5149e750c3be3cfc72b22ad94db4886/src/pytz/tzinfo.py#L422