Skip to content

Commit fe0b356

Browse files
committed
Fix pendulum.tz.timezones() to use system tzdata
Fix the `pendulum.tz.available_timezones()` to use `available_timezones()` function instead of iterating over the files in `tzdata` package. This is more in line with PEP 615, as the system timezone functions will operate on system-provided tzdata when available, and use the `tzdata` package only if it's not available. Therefore, the previous code would yield a potentially different list of timezones than the system actually provides. Furthermore, Gentoo provides a dummy `tzdata` package that does not provide any data, since Python always uses system tzdata. This change is necessary to make pendulum work again on Gentoo. Fixes #769
1 parent 6705906 commit fe0b356

File tree

1 file changed

+2
-7
lines changed

1 file changed

+2
-7
lines changed

src/pendulum/tz/__init__.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from pendulum.tz.timezone import UTC
1111
from pendulum.tz.timezone import FixedTimezone
1212
from pendulum.tz.timezone import Timezone
13+
from zoneinfo import available_timezones
1314

1415

1516
if TYPE_CHECKING:
@@ -26,13 +27,7 @@
2627

2728

2829
def timezones() -> tuple[str, ...]:
29-
global _timezones
30-
31-
if _timezones is None:
32-
with cast("Path", resources.files("tzdata").joinpath("zones")).open() as f:
33-
_timezones = tuple(tz.strip() for tz in f.readlines())
34-
35-
return _timezones
30+
return available_timezones()
3631

3732

3833
def fixed_timezone(offset: int) -> FixedTimezone:

0 commit comments

Comments
 (0)