/*
*******************************************************************************
- * Copyright (C) 2011, International Business Machines Corporation and *
+ * Copyright (C) 2011-2013, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
import com.ibm.icu.text.TimeZoneNames.NameType;
import com.ibm.icu.util.BasicTimeZone;
import com.ibm.icu.util.Freezable;
+import com.ibm.icu.util.Output;
import com.ibm.icu.util.TimeZone;
import com.ibm.icu.util.TimeZone.SystemTimeZoneType;
import com.ibm.icu.util.TimeZoneTransition;
*/
public class TimeZoneGenericNames implements Serializable, Freezable<TimeZoneGenericNames> {
+ // Note: This class implements Serializable, but we no longer serialize instance of
+ // TimeZoneGenericNames in ICU 49. ICU 4.8 com.ibm.icu.text.TimeZoneFormat used to
+ // serialize TimeZoneGenericNames field. TimeZoneFormat no longer read TimeZoneGenericNames
+ // field, we have to keep TimeZoneGenericNames Serializable. Otherwise it fails to read
+ // (unused) TimeZoneGenericNames serialized data.
+
private static final long serialVersionUID = 2729910342063468417L;
/**
* Format pattern enum used for composing location and partial location names
*/
public enum Pattern {
- // The format pattern such as "{0} Time", where {0} is the country.
+ // The format pattern such as "{0} Time", where {0} is the country or city.
REGION_FORMAT("regionFormat", "({0})"),
+ // Note: FALLBACK_REGION_FORMAT is no longer used since ICU 50/CLDR 22.1
// The format pattern such as "{1} Time ({0})", where {1} is the country and {0} is a city.
- FALLBACK_REGION_FORMAT("fallbackRegionFormat", "{1} ({0})"),
+ //FALLBACK_REGION_FORMAT("fallbackRegionFormat", "{1} ({0})"),
// The format pattern such as "{1} ({0})", where {1} is the metazone, and {0} is the country or city.
FALLBACK_FORMAT("fallbackFormat", "{1} ({0})");
return name;
}
- String countryCode = ZoneMeta.getCanonicalCountry(canonicalTzID);
+ Output<Boolean> isPrimary = new Output<Boolean>();
+ String countryCode = ZoneMeta.getCanonicalCountry(canonicalTzID, isPrimary);
if (countryCode != null) {
- String country = getLocaleDisplayNames().regionDisplayName(countryCode);
- if (ZoneMeta.getSingleCountry(canonicalTzID) != null) {
- // If the zone is only one zone in the country, do not add city
+ if (isPrimary.value) {
+ // If this is only the single zone in the country, use the country name
+ String country = getLocaleDisplayNames().regionDisplayName(countryCode);
name = formatPattern(Pattern.REGION_FORMAT, country);
} else {
+ // If there are multiple zones including this in the country,
+ // use the exemplar city name
+
// getExemplarLocationName should return non-empty String
// if the time zone is associated with a location
String city = _tznames.getExemplarLocationName(canonicalTzID);
- name = formatPattern(Pattern.FALLBACK_REGION_FORMAT, city, country);
+ name = formatPattern(Pattern.REGION_FORMAT, city);
}
}
}
if (useStandard) {
NameType stdNameType = (nameType == NameType.LONG_GENERIC) ?
- NameType.LONG_STANDARD : NameType.SHORT_STANDARD_COMMONLY_USED;
+ NameType.LONG_STANDARD : NameType.SHORT_STANDARD;
String stdName = _tznames.getDisplayName(tzID, stdNameType, date);
if (stdName != null) {
name = stdName;
// golden zone at the given date.
String goldenID = _tznames.getReferenceZoneID(mzID, getTargetRegion());
if (goldenID != null && !goldenID.equals(tzID)) {
- TimeZone goldenZone = TimeZone.getTimeZone(goldenID);
+ TimeZone goldenZone = TimeZone.getFrozenTimeZone(goldenID);
int[] offsets1 = {0, 0};
// Check offset in the golden zone with wall time.
// and the location name. When the match is a long standard name,
// then we need to check if the name is same with the location name.
// This is probably a data error or a design bug.
- if (bestMatch.nameType != GenericNameType.LONG || bestMatch.timeType != TimeType.STANDARD) {
+// if (bestMatch.nameType != GenericNameType.LONG || bestMatch.timeType != TimeType.STANDARD) {
+// return bestMatch;
+// }
+
+ // TODO The deprecation of commonlyUsed flag introduced the name
+ // conflict not only for long standard names, but short standard names too.
+ // These short names (found in zh_Hant) should be gone once we clean
+ // up CLDR time zone display name data. Once the short name conflict
+ // problem (with location name) is resolved, we should change the condition
+ // below back to the original one above. -Yoshito (2011-09-14)
+ if (bestMatch.timeType != TimeType.STANDARD) {
return bestMatch;
}
}
case LONG_GENERIC:
nameType = GenericNameType.LONG;
break;
- case SHORT_STANDARD_COMMONLY_USED:
+ case SHORT_STANDARD:
nameType = GenericNameType.SHORT;
timeType = TimeType.STANDARD;
break;
case SHORT_GENERIC:
nameType = GenericNameType.SHORT;
break;
+ default:
+ throw new IllegalArgumentException("Unexpected MatchInfo name type - " + matchInfo.nameType());
}
- assert(nameType != null);
String tzID = matchInfo.tzID();
if (tzID == null) {
}
if (types.contains(GenericNameType.SHORT)) {
nameTypes.add(NameType.SHORT_GENERIC);
- nameTypes.add(NameType.SHORT_STANDARD_COMMONLY_USED);
+ nameTypes.add(NameType.SHORT_STANDARD);
}
if (!nameTypes.isEmpty()) {