kopia lustrzana https://github.com/collective/icalendar
Test that timezone names are understood
rodzic
e4debef7a8
commit
50c583c655
|
@ -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}"
|
|
@ -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"]
|
||||
|
|
Ładowanie…
Reference in New Issue