Skip to content

Commit 3f11dd9

Browse files
authored
fix: available_timezones is reporting an invalid IANA zone name
1 parent c056a08 commit 3f11dd9

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

Doc/library/zoneinfo.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ Functions
349349

350350
This function only includes canonical zone names and does not include
351351
"special" zones such as those under the ``posix/`` and ``right/``
352-
directories, or the ``posixrules`` zone.
352+
directories, the ``posixrules`` or the ``localtime`` zone.
353353

354354
.. caution::
355355

Lib/test/test_zoneinfo/test_zoneinfo.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,6 +1941,21 @@ def test_exclude_posixrules(self):
19411941
actual = self.module.available_timezones()
19421942
self.assertEqual(actual, expected)
19431943

1944+
def test_exclude_localtime(self):
1945+
expected = {
1946+
"America/New_York",
1947+
"Europe/London",
1948+
}
1949+
1950+
tree = list(expected) + ["localtime"]
1951+
1952+
with tempfile.TemporaryDirectory() as td:
1953+
for key in tree:
1954+
self.touch_zone(key, td)
1955+
1956+
with self.tzpath_context([td]):
1957+
actual = self.module.available_timezones()
1958+
self.assertEqual(actual, expected)
19441959

19451960
class CTestModule(TestModule):
19461961
module = c_zoneinfo

Lib/zoneinfo/_tzpath.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ def valid_key(fpath):
170170
# posixrules is a special symlink-only time zone where it exists, it
171171
# should not be included in the output
172172
valid_zones.remove("posixrules")
173+
if "localtime" in valid_zones:
174+
# localtime is a special symlink-only time zone where it exists, it
175+
# should not be included in the output
176+
valid_zones.remove("localtime")
173177

174178
return valid_zones
175179

0 commit comments

Comments
 (0)