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

[BUG] timezone definitions keep changing but are assumed static #776

Open
3 of 5 tasks
niccokunzmann opened this issue Feb 6, 2025 · 0 comments
Open
3 of 5 tasks

Comments

@niccokunzmann
Copy link
Member

niccokunzmann commented Feb 6, 2025

Describe the bug

icalendar.timezone.tzid.tinfo2tzids (which I added) would provide us with a timezone name for a timezone even if this timezone is not easily recognized as having one, so we can generate timezones if needed.

Now, the code assumes that timezones in the past would not change.
But they do! Even between 1970 and 2000.

To Reproduce

Here is an example of how the timezone definitions are different between each other, using EET which is +2 hours away from UTC.

>>> 60*60*2  # 2 hours offset
7200
>>> from dateutil.tz import gettz
>>> from pytz import timezone
>>> from zoneinfo import ZoneInfo
>>> import datetime
>>> d = datetime.datetime(1983, 3, 27, 3, 0)
>>> tz1 = gettz("EET")
>>> tz1.utcoffset(d)
datetime.timedelta(seconds=10800)  # wrong offset
>>> tz2 = ZoneInfo("EET")
>>> tz2.utcoffset(d)   # correct offset
datetime.timedelta(seconds=7200)
>>> tz3 = timezone("EET")
>>> tz3.utcoffset(d)  # no offset
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/nicco/icalendar/.tox/py39/lib/python3.9/site-packages/pytz/tzinfo.py", line 425, in utcoffset
    dt = self.localize(dt, is_dst)
  File "/home/nicco/icalendar/.tox/py39/lib/python3.9/site-packages/pytz/tzinfo.py", line 344, in localize
    raise NonExistentTimeError(dt)
pytz.exceptions.NonExistentTimeError: 1983-03-27 03:00:00

So, we can determine pytz and zoneinfo easily because they have a name in them. Dateutil timezones do not have this.

Expected behavior

I would like to be always able to get the correct timezone name for a timezone.
This is hard though!

Environment

  • OS: Ubuntu 24
  • Python version: 3.9
  • icalendar version: main (6.1.1)

Additional context

Ideas to go forward

  • create a bug report in dateutil
  • possible reduction of risk if this occurs again: We can assume that timezone changes happen around midnight. Thus we could reduce the tests cases to the hours around midday to reduce ambiguous timezone definitions.
@niccokunzmann niccokunzmann changed the title [BUG] timezone definitions keep changing [BUG] timezone definitions keep changing but are assumed static Feb 6, 2025
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

No branches or pull requests

1 participant