Skip to content

Commit a257599

Browse files
authored
♻️ Default to using system zoneinfo if available (#303)
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
1 parent 78ac0a3 commit a257599

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

pydantic_extra_types/timezone_name.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@ def _warn_about_pytz_usage() -> None:
4444

4545
def get_timezones() -> set[str]:
4646
"""Determine the timezone provider and return available timezones."""
47-
if _is_available('zoneinfo') and _is_available('tzdata'): # pragma: no cover
48-
return _tz_provider_from_zone_info()
47+
if _is_available('zoneinfo'): # pragma: no cover
48+
timezones = _tz_provider_from_zone_info()
49+
if len(timezones) == 0: # pragma: no cover
50+
raise ImportError('No timezone provider found. Please install tzdata with "pip install tzdata"')
51+
return timezones
4952
elif _is_available('pytz'): # pragma: no cover
5053
return _tz_provider_from_pytz()
5154
else: # pragma: no cover

0 commit comments

Comments
 (0)