summaryrefslogtreecommitdiff
path: root/android_icu4j/libcore_bridge/src/java/com/android/i18n/timezone/CountryZonesFinder.java
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2024-03-13 01:02:40 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2024-03-13 01:02:40 +0000
commitab7ed14d1aff7d396f9f398c3ec18c9ddfcc7dcd (patch)
tree40d7f14673987d3dfc895efe287f46fed913e183 /android_icu4j/libcore_bridge/src/java/com/android/i18n/timezone/CountryZonesFinder.java
parent2273ba3c5957b3094dcaec3a12961fd9800e3a9b (diff)
parent304410e63a5426aa480a450f7386b3e1ff240096 (diff)
downloadicu-androidx-datastore-release.tar.gz
Snap for 11565916 from 304410e63a5426aa480a450f7386b3e1ff240096 to androidx-datastore-releaseandroidx-datastore-release
Change-Id: Ie72617cf18f0becccb0d89cc431bac818a29389d
Diffstat (limited to 'android_icu4j/libcore_bridge/src/java/com/android/i18n/timezone/CountryZonesFinder.java')
-rw-r--r--android_icu4j/libcore_bridge/src/java/com/android/i18n/timezone/CountryZonesFinder.java43
1 files changed, 39 insertions, 4 deletions
diff --git a/android_icu4j/libcore_bridge/src/java/com/android/i18n/timezone/CountryZonesFinder.java b/android_icu4j/libcore_bridge/src/java/com/android/i18n/timezone/CountryZonesFinder.java
index 80a316e1f..61d9a1895 100644
--- a/android_icu4j/libcore_bridge/src/java/com/android/i18n/timezone/CountryZonesFinder.java
+++ b/android_icu4j/libcore_bridge/src/java/com/android/i18n/timezone/CountryZonesFinder.java
@@ -19,6 +19,7 @@ package com.android.i18n.timezone;
import static com.android.i18n.timezone.XmlUtils.normalizeCountryIso;
import com.android.i18n.timezone.CountryTimeZones.TimeZoneMapping;
+import libcore.util.Nullable;
import java.util.ArrayList;
import java.util.Collections;
@@ -57,10 +58,11 @@ public final class CountryZonesFinder {
/**
* Returns an immutable list of {@link CountryTimeZones} for countries that use the specified
- * time zone. An exact, case-sensitive match is performed on the zone ID. If the match but the method also
- * checks for alternative zone IDs. This method never returns null and will usually return a
- * list containing a single element. It can return an empty list if the zone ID is
- * not recognized or it is not associated with a country.
+ * time zone. An exact, case-sensitive match is performed on the zone ID. Search is done
+ * over currently used time zone IDs and also over no longer used deprecated(alternative) IDs.
+ * This method never returns null and will usually return a list containing a single element.
+ * It can return an empty list if the zone ID is not recognized or it is not associated with a
+ * country.
*/
@libcore.api.CorePlatformApi
public List<CountryTimeZones> lookupCountryTimeZonesForZoneId(String zoneId) {
@@ -104,4 +106,37 @@ public final class CountryZonesFinder {
}
return null;
}
+
+ /**
+ * Returns a canonical time zone ID for the {@code timeZoneId} specified. It is intended for use
+ * when behavioral equivalence of time zones needs to be determined.
+ *
+ * <p>When a time zone ID is returned, it is guaranteed to have the same offset / daylight
+ * savings behavior as the argument, but it might be used in a different country and could
+ * have different I18N properties like display name. The original {@code timeZoneId} will
+ * often be returned.
+ *
+ * <p>If {@code timeZoneId} is unknown or not associated with a country, {@code null} is
+ * returned. e.g. time zones such as Etc/GMT+-XX.
+ *
+ * This method behavior is based on tzlookup.xml file and works with Olson IDs attached to
+ * countries, unlike {@link android.icu.util.TimeZone} which works with wider set of arguments.
+ */
+ @libcore.api.CorePlatformApi
+ @Nullable
+ public String findCanonicalTimeZoneId(String timeZoneId) {
+ for (CountryTimeZones countryTimeZones : countryTimeZonesList) {
+
+ // notafter is ignored as timeZoneId might be deprecated a while ago
+ List<TimeZoneMapping> countryTimeZoneMappings = countryTimeZones.getTimeZoneMappings();
+ for (TimeZoneMapping timeZoneMapping : countryTimeZoneMappings) {
+ if (timeZoneMapping.getTimeZoneId().equals(timeZoneId)
+ || timeZoneMapping.getAlternativeIds().contains(timeZoneId)) {
+ return timeZoneMapping.getTimeZoneId();
+ }
+ }
+ }
+
+ return null;
+ }
}