From 2242ff73b83e6dfaa97b6e8e55bf4301b41b89d5 Mon Sep 17 00:00:00 2001 From: Neil Fuller Date: Wed, 5 Apr 2017 13:58:26 +0100 Subject: [PATCH] Canonicalize tz IDs when finding exemplar location Canonicalize time zone IDs when looking up exemplar location. ICU's canonical IDs are not guaranteed the same as IANA's. Various data files (e.g. timezones.xml, tzdata, time_zones_by_country.xml) are using IANA IDs. ICU's IDs are often the same, but because they are guaranteed not to change and IANAs are not there is some drift. This fixes an issue with the settings picker for ICU IDs: America/Buenos_Aires Asia/Rangoon Asia/Katmandu Asia/Calcutta Which are IANA's: America/Argentina/Buenos_Aires Asia/Yangon Asia/Kathmandu Asia/Kolkata introduced by commit b4d003da66. It could also influence some display names for automatically-selected time zones outside of this list. The issues was particularly noticeable in locales that use non-ASCII scripts; ICU performs a fallback if the ID isn't canonical and would transform and return the last part of the ID (e.g. Buenos Aires, Yangon, Kathmandu, Kolkata). Bug: 36469833 Test: Manual testing in Japanese Change-Id: I2febdbee58e474d251d0a33f2c8335664a74581f (cherry picked from commit f92ad8a0190add07779ed454a0908dd3df83f4bd) --- .../src/com/android/settingslib/datetime/ZoneGetter.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/SettingsLib/src/com/android/settingslib/datetime/ZoneGetter.java b/packages/SettingsLib/src/com/android/settingslib/datetime/ZoneGetter.java index 4bfca9b61d6b..474de9074062 100644 --- a/packages/SettingsLib/src/com/android/settingslib/datetime/ZoneGetter.java +++ b/packages/SettingsLib/src/com/android/settingslib/datetime/ZoneGetter.java @@ -211,7 +211,16 @@ public class ZoneGetter { if (preferLongName) { displayName = getZoneLongName(timeZoneNames, tz, now); } else { - displayName = timeZoneNames.getExemplarLocationName(tz.getID()); + // Canonicalize the zone ID for ICU. It will only return valid strings for zone IDs + // that match ICUs zone IDs (which are similar but not guaranteed the same as those + // in timezones.xml). timezones.xml and related files uses the IANA IDs. ICU IDs are + // stable and IANA IDs have changed over time so they have drifted. + // See http://bugs.icu-project.org/trac/ticket/13070 / http://b/36469833. + String canonicalZoneId = android.icu.util.TimeZone.getCanonicalID(tz.getID()); + if (canonicalZoneId == null) { + canonicalZoneId = tz.getID(); + } + displayName = timeZoneNames.getExemplarLocationName(canonicalZoneId); if (displayName == null || displayName.isEmpty()) { // getZoneExemplarLocation can return null. Fall back to the long name. displayName = getZoneLongName(timeZoneNames, tz, now); @@ -325,4 +334,4 @@ public class ZoneGetter { } } } -} \ No newline at end of file +} -- 2.11.0