From 0e333d74bf1bd12a98b49107cca7314c4e6a3b23 Mon Sep 17 00:00:00 2001 From: Jelle van der Waa Date: Mon, 31 Mar 2025 11:29:01 +0200 Subject: [PATCH] Default to using system zoneinfo if available The zoneinfo module by default uses the systems timezone information and if not found falls back to tzdata. This change makes `get_timezone()` behave the same allowing for tzdata to fully become an optional dependency for Linux distributions which already include time zone data. Closes: #291 --- pydantic_extra_types/timezone_name.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pydantic_extra_types/timezone_name.py b/pydantic_extra_types/timezone_name.py index 773a612..0280387 100644 --- a/pydantic_extra_types/timezone_name.py +++ b/pydantic_extra_types/timezone_name.py @@ -44,8 +44,11 @@ def _warn_about_pytz_usage() -> None: def get_timezones() -> set[str]: """Determine the timezone provider and return available timezones.""" - if _is_available('zoneinfo') and _is_available('tzdata'): # pragma: no cover - return _tz_provider_from_zone_info() + if _is_available('zoneinfo'): # pragma: no cover + timezones = _tz_provider_from_zone_info() + if len(timezones) == 0: # pragma: no cover + raise ImportError('No timezone provider found. Please install tzdata with "pip install tzdata"') + return timezones elif _is_available('pytz'): # pragma: no cover return _tz_provider_from_pytz() else: # pragma: no cover