Fix missing zone strings in some cases
ICU's TimeZoneNames requires a "canonical" zone ID, otherwise it will return no data. Usually the ID being used is the same as the canonical ID so there's no problem. TZDB version 2020a switched the ID of one of Greenland's zones from America/Godthab to America/Nuuk, and ICU/CLDR hold their translation data against America/Godthab in the current version of ICU on Android. Bug: 155167041 Test: Manual - viewed settings on a device with the tzdb 2020a update Change-Id: Ia89c777a832f8b41c8d56d3327a9b7370ba44b52
This commit is contained in:
@@ -149,22 +149,31 @@ public class TimeZoneInfo {
|
|||||||
* @return TimeZoneInfo containing time zone names, exemplar locations and GMT offset
|
* @return TimeZoneInfo containing time zone names, exemplar locations and GMT offset
|
||||||
*/
|
*/
|
||||||
public TimeZoneInfo format(TimeZone timeZone) {
|
public TimeZoneInfo format(TimeZone timeZone) {
|
||||||
final String id = timeZone.getID();
|
String canonicalZoneId = getCanonicalZoneId(timeZone);
|
||||||
final TimeZoneNames timeZoneNames = mTimeZoneFormat.getTimeZoneNames();
|
final TimeZoneNames timeZoneNames = mTimeZoneFormat.getTimeZoneNames();
|
||||||
final java.util.TimeZone javaTimeZone = java.util.TimeZone.getTimeZone(id);
|
final java.util.TimeZone javaTimeZone = java.util.TimeZone.getTimeZone(canonicalZoneId);
|
||||||
final CharSequence gmtOffset = ZoneGetter.getGmtOffsetText(mTimeZoneFormat, mLocale,
|
final CharSequence gmtOffset = ZoneGetter.getGmtOffsetText(mTimeZoneFormat, mLocale,
|
||||||
javaTimeZone, mNow);
|
javaTimeZone, mNow);
|
||||||
return new TimeZoneInfo.Builder(timeZone)
|
return new TimeZoneInfo.Builder(timeZone)
|
||||||
.setGenericName(timeZoneNames.getDisplayName(id,
|
.setGenericName(timeZoneNames.getDisplayName(canonicalZoneId,
|
||||||
TimeZoneNames.NameType.LONG_GENERIC, mNow.getTime()))
|
TimeZoneNames.NameType.LONG_GENERIC, mNow.getTime()))
|
||||||
.setStandardName(timeZoneNames.getDisplayName(id,
|
.setStandardName(timeZoneNames.getDisplayName(canonicalZoneId,
|
||||||
TimeZoneNames.NameType.LONG_STANDARD, mNow.getTime()))
|
TimeZoneNames.NameType.LONG_STANDARD, mNow.getTime()))
|
||||||
.setDaylightName(timeZoneNames.getDisplayName(id,
|
.setDaylightName(timeZoneNames.getDisplayName(canonicalZoneId,
|
||||||
TimeZoneNames.NameType.LONG_DAYLIGHT, mNow.getTime()))
|
TimeZoneNames.NameType.LONG_DAYLIGHT, mNow.getTime()))
|
||||||
.setExemplarLocation(timeZoneNames.getExemplarLocationName(id))
|
.setExemplarLocation(timeZoneNames.getExemplarLocationName(canonicalZoneId))
|
||||||
.setGmtOffset(gmtOffset)
|
.setGmtOffset(gmtOffset)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String getCanonicalZoneId(TimeZone timeZone) {
|
||||||
|
final String id = timeZone.getID();
|
||||||
|
final String canonicalId = TimeZone.getCanonicalID(id);
|
||||||
|
if (canonicalId != null) {
|
||||||
|
return canonicalId;
|
||||||
|
}
|
||||||
|
return id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user