Skip to content
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
23 changes: 16 additions & 7 deletions scripts/import_cldr.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,22 @@ def parse_global(srcdir, sup):
for key_elem in bcp47_timezone.findall('.//keyword/key'):
if key_elem.attrib['name'] == 'tz':
for elem in key_elem.findall('type'):
if 'deprecated' not in elem.attrib:
aliases = str(elem.attrib['alias']).split()
tzid = aliases.pop(0)
territory = _zone_territory_map.get(tzid, '001')
territory_zones.setdefault(territory, []).append(tzid)
zone_territories[tzid] = territory
for alias in aliases:
if 'deprecated' in elem.attrib:
continue
aliases = str(elem.attrib['alias']).split()
iana = elem.attrib.get('iana')
tzid = iana or aliases[0] # Use the IANA ID if available, otherwise the first alias
territory = '001'
# The windowsZones map might use an alias to refer to a timezone,
# so can't just do a simple dict lookup.
for cand in (tzid, *aliases):
if cand in _zone_territory_map:
territory = _zone_territory_map[cand]
break
territory_zones.setdefault(territory, []).append(tzid)
zone_territories[tzid] = territory
for alias in aliases:
if alias != tzid:
zone_aliases[alias] = tzid
break

Expand Down
16 changes: 12 additions & 4 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,18 @@ def test_ignore_invalid_locales_in_lc_ctype(monkeypatch):
default_locale('LC_CTYPE')


def test_get_global():
assert core.get_global('zone_aliases')['GMT'] == 'Etc/GMT'
assert core.get_global('zone_aliases')['UTC'] == 'Etc/UTC'
assert core.get_global('zone_territories')['Europe/Berlin'] == 'DE'
def test_zone_aliases_and_territories():
aliases = core.get_global('zone_aliases')
territories = core.get_global('zone_territories')
assert aliases['GMT'] == 'Etc/GMT'
assert aliases['UTC'] == 'Etc/UTC'
assert territories['Europe/Berlin'] == 'DE'
# Check that the canonical (IANA) names are used in `territories`,
# but that aliases are still available.
assert territories['Africa/Asmara'] == 'ER'
assert aliases['Africa/Asmera'] == 'Africa/Asmara'
assert territories['Europe/Kyiv'] == 'UA'
assert aliases['Europe/Kiev'] == 'Europe/Kyiv'


def test_hash():
Expand Down
Loading