Skip to content

Commit 0f27e10

Browse files
ntindleblurb-it[bot]pganssle
authored
gh-137976: Explicitly exclude localtime from available_timezones (#138012)
* fix: available_timezones is reporting an invalid IANA zone name * 📜🤖 Added by blurb_it. * correct rst format for backticks --------- Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com> Co-authored-by: Paul Ganssle <[email protected]>
1 parent d641c41 commit 0f27e10

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-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
@@ -1951,6 +1951,21 @@ def test_exclude_posixrules(self):
19511951
actual = self.module.available_timezones()
19521952
self.assertEqual(actual, expected)
19531953

1954+
def test_exclude_localtime(self):
1955+
expected = {
1956+
"America/New_York",
1957+
"Europe/London",
1958+
}
1959+
1960+
tree = list(expected) + ["localtime"]
1961+
1962+
with tempfile.TemporaryDirectory() as td:
1963+
for key in tree:
1964+
self.touch_zone(key, td)
1965+
1966+
with self.tzpath_context([td]):
1967+
actual = self.module.available_timezones()
1968+
self.assertEqual(actual, expected)
19541969

19551970
class CTestModule(TestModule):
19561971
module = c_zoneinfo

Lib/zoneinfo/_tzpath.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ def valid_key(fpath):
177177
# posixrules is a special symlink-only time zone where it exists, it
178178
# should not be included in the output
179179
valid_zones.remove("posixrules")
180+
if "localtime" in valid_zones:
181+
# localtime is a special symlink-only time zone where it exists, it
182+
# should not be included in the output
183+
valid_zones.remove("localtime")
180184

181185
return valid_zones
182186

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Removed ``localtime`` from the list of reported system timezones.

0 commit comments

Comments
 (0)