Merge "Fix missing zone strings in some cases" am: 738df11447

Change-Id: I66ba5583cdd3632c6e6efb47fb1c0a0ea3b137cb
This commit is contained in:
Neil Fuller
2020-04-29 12:30:24 +00:00
committed by Automerger Merge Worker

View File

@@ -149,22 +149,31 @@ public class TimeZoneInfo {
* @return TimeZoneInfo containing time zone names, exemplar locations and GMT offset
*/
public TimeZoneInfo format(TimeZone timeZone) {
final String id = timeZone.getID();
String canonicalZoneId = getCanonicalZoneId(timeZone);
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,
javaTimeZone, mNow);
return new TimeZoneInfo.Builder(timeZone)
.setGenericName(timeZoneNames.getDisplayName(id,
.setGenericName(timeZoneNames.getDisplayName(canonicalZoneId,
TimeZoneNames.NameType.LONG_GENERIC, mNow.getTime()))
.setStandardName(timeZoneNames.getDisplayName(id,
.setStandardName(timeZoneNames.getDisplayName(canonicalZoneId,
TimeZoneNames.NameType.LONG_STANDARD, mNow.getTime()))
.setDaylightName(timeZoneNames.getDisplayName(id,
.setDaylightName(timeZoneNames.getDisplayName(canonicalZoneId,
TimeZoneNames.NameType.LONG_DAYLIGHT, mNow.getTime()))
.setExemplarLocation(timeZoneNames.getExemplarLocationName(id))
.setExemplarLocation(timeZoneNames.getExemplarLocationName(canonicalZoneId))
.setGmtOffset(gmtOffset)
.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;
}
}
}