From: Aarni Koskela Date: Tue, 4 Mar 2025 12:21:38 +0000 (+0200) Subject: Improve handling of no-inheritance-marker in timezone data X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a1b0e8be7ac3c206845fa74e6f4ed667b759945c;p=thirdparty%2Fbabel.git Improve handling of no-inheritance-marker in timezone data Fixes #1192 (but uncovers another bug) --- diff --git a/babel/dates.py b/babel/dates.py index 355a9236..2ec10b5b 100644 --- a/babel/dates.py +++ b/babel/dates.py @@ -649,7 +649,9 @@ def get_timezone_name( info = locale.time_zones.get(zone, {}) # Try explicitly translated zone names first if width in info and zone_variant in info[width]: - return info[width][zone_variant] + value = info[width][zone_variant] + if value != NO_INHERITANCE_MARKER: + return value metazone = get_global('meta_zones').get(zone) if metazone: @@ -660,7 +662,7 @@ def get_timezone_name( # If the short form is marked no-inheritance, # try to fall back to the long name instead. name = metazone_info.get('long', {}).get(zone_variant) - if name: + if name and name != NO_INHERITANCE_MARKER: return name # If we have a concrete datetime, we assume that the result can't be diff --git a/tests/test_dates.py b/tests/test_dates.py index e47521e4..cd213b7f 100644 --- a/tests/test_dates.py +++ b/tests/test_dates.py @@ -1187,3 +1187,33 @@ def test_issue_1089(): def test_issue_1162(locale, format, negative, expected): delta = timedelta(seconds=10800) * (-1 if negative else +1) assert dates.format_timedelta(delta, add_direction=True, format=format, locale=locale) == expected + + +def test_issue_1192(): + # The actual returned value here is not actually strictly specified ("get_timezone_name" + # is not an operation specified as such). Issue #1192 concerned this invocation returning + # the invalid "no inheritance marker" value; _that_ should never be returned here. + # IOW, if the below "Hawaii-Aleutian Time" changes with e.g. CLDR updates, that's fine. + assert dates.get_timezone_name('Pacific/Honolulu', 'short', locale='en_GB') == "Hawaii-Aleutian Time" + + +@pytest.mark.xfail +def test_issue_1192_fmt(timezone_getter): + """ + There is an issue in how we format the fallback for z/zz in the absence of data + (esp. with the no inheritance marker present). + This test is marked xfail until that's fixed. + """ + # env TEST_TIMEZONES=Pacific/Honolulu TEST_LOCALES=en_US,en_GB TEST_TIME_FORMAT="YYYY-MM-dd H:mm z" bin/icu4c_date_format + # Defaulting TEST_TIME to 2025-03-04T13:53:00Z + # Pacific/Honolulu en_US 2025-03-04 3:53 HST + # Pacific/Honolulu en_GB 2025-03-04 3:53 GMT-10 + # env TEST_TIMEZONES=Pacific/Honolulu TEST_LOCALES=en_US,en_GB TEST_TIME_FORMAT="YYYY-MM-dd H:mm zz" bin/icu4c_date_format + # Pacific/Honolulu en_US 2025-03-04 3:53 HST + # Pacific/Honolulu en_GB 2025-03-04 3:53 GMT-10 + tz = timezone_getter("Pacific/Honolulu") + dt = _localize(tz, datetime(2025, 3, 4, 13, 53, tzinfo=UTC)) + assert dates.format_datetime(dt, "YYYY-MM-dd H:mm z", locale="en_US") == "2025-03-04 3:53 HST" + assert dates.format_datetime(dt, "YYYY-MM-dd H:mm z", locale="en_GB") == "2025-03-04 3:53 GMT-10" + assert dates.format_datetime(dt, "YYYY-MM-dd H:mm zz", locale="en_US") == "2025-03-04 3:53 HST" + assert dates.format_datetime(dt, "YYYY-MM-dd H:mm zz", locale="en_GB") == "2025-03-04 3:53 GMT-10"