diff --git a/src/icalendar/tests/test_pytz_zoneinfo_integration.py b/src/icalendar/tests/test_pytz_zoneinfo_integration.py new file mode 100644 index 0000000..c797c03 --- /dev/null +++ b/src/icalendar/tests/test_pytz_zoneinfo_integration.py @@ -0,0 +1,15 @@ +"""This tests the switch to different timezone implementations. + +These are mostly located in icalendar.timezone. +""" +import pytz +from icalendar.timezone.zoneinfo import zoneinfo, ZONEINFO +from icalendar.timezone.pytz import PYTZ +import pytest + + +@pytest.mark.parametrize("tz_name", pytz.all_timezones + list(zoneinfo.available_timezones())) +@pytest.mark.parametrize("tzp_", [PYTZ(), ZONEINFO()]) +def test_timezone_names_are_known(tz_name, tzp_): + """Make sure that all timezones are understood.""" + assert tzp_.knows_timezone_id(tz_name), f"{tzp_.__class__.__name__} should know {tz_name}" diff --git a/src/icalendar/timezone/zoneinfo.py b/src/icalendar/timezone/zoneinfo.py index b683e2b..ab3dde3 100644 --- a/src/icalendar/timezone/zoneinfo.py +++ b/src/icalendar/timezone/zoneinfo.py @@ -11,6 +11,7 @@ class ZONEINFO: """Provide icalendar with timezones from zoneinfo.""" utc = zoneinfo.ZoneInfo("UTC") + _available_timezones = zoneinfo.available_timezones() def localize(self, dt: datetime, tz: zoneinfo.ZoneInfo) -> datetime: """Localize a datetime to a timezone.""" @@ -27,6 +28,9 @@ class ZONEINFO: except ValueError: pass + def knows_timezone_id(self, id: str) -> bool: + """Whether the timezone is already cached by the implementation.""" + return id in self._available_timezones __all__ = ["ZONEINFO"]