Merge "Fix missing zone strings in some cases"

This commit is contained in:
Neil Fuller
2020-04-29 12:18:53 +00:00
committed by Gerrit Code Review

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;
}
}
}