summaryrefslogtreecommitdiff
path: root/babel
diff options
context:
space:
mode:
authorAarni Koskela <akx@iki.fi>2016-07-15 14:13:09 +0300
committerAarni Koskela <akx@iki.fi>2016-07-15 14:13:09 +0300
commitbece010dd32fbb5f4bbcd6a667800bdab662ddf6 (patch)
tree5b5a526b4e7fd2fc37fc2531e2140931ccc17294 /babel
parent5c37e6afe6d1978a9672b707ba28a5fd932cf222 (diff)
downloadbabel-bece010dd32fbb5f4bbcd6a667800bdab662ddf6.tar.gz
Properly fall back to `long` metazone names when short forms are no-inherit
Thanks to @stringtheory for the bug report! Fixes #428
Diffstat (limited to 'babel')
-rw-r--r--babel/dates.py19
1 files changed, 17 insertions, 2 deletions
diff --git a/babel/dates.py b/babel/dates.py
index 523e456..c84ca48 100644
--- a/babel/dates.py
+++ b/babel/dates.py
@@ -30,6 +30,16 @@ from babel.util import UTC, LOCALTZ
from babel._compat import string_types, integer_types, number_types
+# "If a given short metazone form is known NOT to be understood in a given
+# locale and the parent locale has this value such that it would normally
+# be inherited, the inheritance of this value can be explicitly disabled by
+# use of the 'no inheritance marker' as the value, which is 3 simultaneous [sic]
+# empty set characters ( U+2205 )."
+# - http://www.unicode.org/reports/tr35/tr35-dates.html#Metazone_Names
+
+NO_INHERITANCE_MARKER = u'\u2205\u2205\u2205'
+
+
LC_TIME = default_locale('LC_TIME')
# Aliases for use in scopes where the modules are shadowed by local variables
@@ -642,8 +652,13 @@ def get_timezone_name(dt_or_tzinfo=None, width='long', uncommon=False,
if metazone:
metazone_info = locale.meta_zones.get(metazone, {})
if width in metazone_info:
- if zone_variant in metazone_info[width]:
- return metazone_info[width][zone_variant]
+ name = metazone_info[width].get(zone_variant)
+ if width == 'short' and name == NO_INHERITANCE_MARKER:
+ # 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:
+ return name
# If we have a concrete datetime, we assume that the result can't be
# independent of daylight savings time, so we return the GMT offset