ICU-8953 Fixed the getCanonicalID with the Olson link.
X-SVN-Rev: 30987
This commit is contained in:
parent
c267b157f0
commit
884a12613a
@ -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.
|
||||
|
@ -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];
|
||||
|
Loading…
Reference in New Issue
Block a user