Skip to content

gh-137976: fix available_timezones to prevent reporting an invalid IANA zone name: localtime #138012

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Doc/library/zoneinfo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ Functions

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

.. caution::

Expand Down
15 changes: 15 additions & 0 deletions Lib/test/test_zoneinfo/test_zoneinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1941,6 +1941,21 @@ def test_exclude_posixrules(self):
actual = self.module.available_timezones()
self.assertEqual(actual, expected)

def test_exclude_localtime(self):
expected = {
"America/New_York",
"Europe/London",
}

tree = list(expected) + ["localtime"]

with tempfile.TemporaryDirectory() as td:
for key in tree:
self.touch_zone(key, td)

with self.tzpath_context([td]):
actual = self.module.available_timezones()
self.assertEqual(actual, expected)

class CTestModule(TestModule):
module = c_zoneinfo
Expand Down
4 changes: 4 additions & 0 deletions Lib/zoneinfo/_tzpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ def valid_key(fpath):
# posixrules is a special symlink-only time zone where it exists, it
# should not be included in the output
valid_zones.remove("posixrules")
if "localtime" in valid_zones:
# localtime is a special symlink-only time zone where it exists, it
# should not be included in the output
valid_zones.remove("localtime")

return valid_zones

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Removed ``localtime`` from the list of reported system timezones.
Loading