From: Yoshito Umaoka Date: Tue, 29 Nov 2011 17:45:37 +0000 (+0000) Subject: ICU-8953 Fixed the getCanonicalID with the Olson link. X-Git-Tag: milestone-59-0-1~4325 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=884a12613a4e80862ee12b00cf7118ed7c1a2774;p=icu ICU-8953 Fixed the getCanonicalID with the Olson link. X-SVN-Rev: 30987 --- diff --git a/icu4j/main/classes/core/src/com/ibm/icu/impl/ZoneMeta.java b/icu4j/main/classes/core/src/com/ibm/icu/impl/ZoneMeta.java index f1b5f3a9134..48dbad65a12 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/impl/ZoneMeta.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/impl/ZoneMeta.java @@ -358,31 +358,23 @@ public final class ZoneMeta { public static String getCanonicalCLDRID(String tzid) { String canonical = CANONICAL_ID_CACHE.get(tzid); if (canonical == null) { - int zoneIdx = getZoneIndex(tzid); - if (zoneIdx >= 0) { + canonical = findCLDRCanonicalID(tzid); + if (canonical == null) { + // Resolve Olson link and try it again if necessary try { - UResourceBundle top = UResourceBundle.getBundleInstance( - ICUResourceBundle.ICU_BASE_NAME, ZONEINFORESNAME, ICUResourceBundle.ICU_DATA_CLASS_LOADER); - UResourceBundle zones = top.get(kZONES); - UResourceBundle zone = zones.get(zoneIdx); - if (zone.getType() == UResourceBundle.INT) { - // resolve link - String tmp = getZoneID(zone.getInt()); - if (tmp != null) { - canonical = tmp; + int zoneIdx = getZoneIndex(tzid); + if (zoneIdx >= 0) { + UResourceBundle top = UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, + ZONEINFORESNAME, ICUResourceBundle.ICU_DATA_CLASS_LOADER); + UResourceBundle zones = top.get(kZONES); + UResourceBundle zone = zones.get(zoneIdx); + if (zone.getType() == UResourceBundle.INT) { + // It's a link - resolve link and lookup + tzid = getZoneID(zone.getInt()); + canonical = findCLDRCanonicalID(tzid); } - } else { - canonical = tzid; - } - // check canonical mapping in CLDR - UResourceBundle keyTypeData = UResourceBundle.getBundleInstance( - ICUResourceBundle.ICU_BASE_NAME, "keyTypeData", ICUResourceBundle.ICU_DATA_CLASS_LOADER); - UResourceBundle typeAlias = keyTypeData.get("typeAlias"); - UResourceBundle aliasesForKey = typeAlias.get("timezone"); - if (canonical != null) { - String cldrCanonical = aliasesForKey.getString(canonical.replace('/', ':')); - if (cldrCanonical != null) { - canonical = cldrCanonical; + if (canonical == null) { + canonical = tzid; } } } catch (MissingResourceException e) { @@ -396,6 +388,35 @@ public final class ZoneMeta { return canonical; } + private static String findCLDRCanonicalID(String tzid) { + String canonical = null; + String tzidKey = tzid.replace('/', ':'); + + try { + // First, try check if the given ID is canonical + UResourceBundle keyTypeData = UResourceBundle.getBundleInstance(ICUResourceBundle.ICU_BASE_NAME, + "keyTypeData", ICUResourceBundle.ICU_DATA_CLASS_LOADER); + UResourceBundle typeMap = keyTypeData.get("typeMap"); + UResourceBundle typeKeys = typeMap.get("timezone"); + try { + /* UResourceBundle canonicalEntry = */ typeKeys.get(tzidKey); + // The given tzid is available in the canonical list + canonical = tzid; + } catch (MissingResourceException e) { + // fall through + } + if (canonical == null) { + // Try alias map + UResourceBundle typeAlias = keyTypeData.get("typeAlias"); + UResourceBundle aliasesForKey = typeAlias.get("timezone"); + canonical = aliasesForKey.getString(tzidKey); + } + } catch (MissingResourceException e) { + // fall through + } + return canonical; + } + /** * Return the region code for this tzid. * If tzid is not a system zone ID, this method returns null. diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/timezone/TimeZoneTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/timezone/TimeZoneTest.java index 776790e0f39..01ca6e38ab7 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/timezone/TimeZoneTest.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/timezone/TimeZoneTest.java @@ -1597,6 +1597,8 @@ public class TimeZoneTest extends TestFmwk {"Etc/Unknown", "Etc/Unknown", null}, {"bogus", null, null}, {"", null, null}, + {"America/Marigot", "America/Marigot", "true"}, // Olson link, but CLDR canonical (#8953) + {"Europe/Bratislava", "Europe/Bratislava", "true"}, // Same as above {null, null, null}, }; boolean[] isSystemID = new boolean[1];