]> granicus.if.org Git - icu/commitdiff
ICU-8953 Fixed the getCanonicalID with the Olson link.
authorYoshito Umaoka <y.umaoka@gmail.com>
Tue, 29 Nov 2011 17:45:37 +0000 (17:45 +0000)
committerYoshito Umaoka <y.umaoka@gmail.com>
Tue, 29 Nov 2011 17:45:37 +0000 (17:45 +0000)
X-SVN-Rev: 30987

icu4j/main/classes/core/src/com/ibm/icu/impl/ZoneMeta.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/timezone/TimeZoneTest.java

index f1b5f3a91347dbcf415ebbfd364ece8278c781c7..48dbad65a1296dae204270e3c8b57c11263648fc 100644 (file)
@@ -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.
index 776790e0f394feac7984f891e27ff3e8925753a3..01ca6e38ab731f30e5eb926de8df86c22be8e5ea 100644 (file)
@@ -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];