summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Chang <vichang@google.com>2021-05-04 15:18:45 +0100
committervichang <vichang@google.com>2021-05-04 16:09:24 +0000
commit0793dc321ae731829f08c2ba6bafd8905c8d0e89 (patch)
tree2592ba5e76cee10499b2b9c073e4a97843e480c7
parent4b95112d4e6042e46e5f53c38b120b39146f91f3 (diff)
downloadicu-0793dc321ae731829f08c2ba6bafd8905c8d0e89.tar.gz
Rename ExtendedTimeZoneNames.matchName method
The return type can't be changed, because ART branch is building aganist the prebuilt SDK provided by ICU. Temporaily name the method "matchNameToBeRenamed" until the prebuilt SDK is updataed Bug: 183477238 Test: m droid Change-Id: I109a0f444959a894282149ad7d7f40cffd6d5902
-rw-r--r--android_icu4j/api/intra/current.txt7
-rw-r--r--android_icu4j/libcore_bridge/src/java/com/android/icu/text/ExtendedTimeZoneNames.java80
2 files changed, 87 insertions, 0 deletions
diff --git a/android_icu4j/api/intra/current.txt b/android_icu4j/api/intra/current.txt
index d3cc4cc87..317a84368 100644
--- a/android_icu4j/api/intra/current.txt
+++ b/android_icu4j/api/intra/current.txt
@@ -74,6 +74,13 @@ package com.android.icu.text {
method @NonNull public static com.android.icu.text.ExtendedTimeZoneNames getInstance(@NonNull android.icu.util.ULocale);
method @NonNull public android.icu.text.TimeZoneNames getTimeZoneNames();
method @Nullable public com.android.icu.text.ExtendedTimeZoneNames.MatchedTimeZone matchName(@NonNull CharSequence, int, @NonNull String);
+ method @Nullable public com.android.icu.text.ExtendedTimeZoneNames.Match matchNameToBeRenamed(@NonNull CharSequence, int, @NonNull String);
+ }
+
+ public static final class ExtendedTimeZoneNames.Match {
+ method public int getMatchLength();
+ method @NonNull public String getTzId();
+ method public boolean isDst();
}
public static class ExtendedTimeZoneNames.MatchedTimeZone {
diff --git a/android_icu4j/libcore_bridge/src/java/com/android/icu/text/ExtendedTimeZoneNames.java b/android_icu4j/libcore_bridge/src/java/com/android/icu/text/ExtendedTimeZoneNames.java
index 57c7367bc..37c60635f 100644
--- a/android_icu4j/libcore_bridge/src/java/com/android/icu/text/ExtendedTimeZoneNames.java
+++ b/android_icu4j/libcore_bridge/src/java/com/android/icu/text/ExtendedTimeZoneNames.java
@@ -54,7 +54,55 @@ public class ExtendedTimeZoneNames {
private final ULocale locale;
private final TimeZoneNames timeZoneNames;
+/**
+ * A class representing the return result of {@link #matchName(CharSequence, int, String)}
+ *
+ * @hide
+ */
+ @IntraCoreApi
+ public static final class Match {
+
+ private final int matchLength;
+ private final @NonNull String tzId;
+ private final boolean isDst;
+ private Match(int matchLength, @NonNull String tzId, boolean isDst) {
+ this.matchLength = matchLength;
+ this.tzId = tzId;
+ this.isDst = isDst;
+ }
+
+ /**
+ * Returns the number of chars in the matched name.
+ *
+ * @hide
+ */
+ @IntraCoreApi
+ public int getMatchLength() {
+ return matchLength;
+ }
+
+ /**
+ * Returns the time zone id associated with the matched name.
+ *
+ * @hide
+ */
+ @IntraCoreApi
+ public @NonNull String getTzId() {
+ return tzId;
+ }
+
+ /**
+ * Returns true if the matched name is a display name for daylight saving time. For example,
+ * returns true for "Pacific Daylight Time", but false for "Pacific Standard Time".
+ *
+ * @hide
+ */
+ @IntraCoreApi
+ public boolean isDst() {
+ return isDst;
+ }
+ }
/**
* A class representing the return result of {@link #matchName(CharSequence, int, String)}
*
@@ -131,6 +179,38 @@ public class ExtendedTimeZoneNames {
}
/**
+ * Returns {@link Match} if a time zone name in ICU can be matched against the input
+ * CharSequence {@code s}.
+ * The best match is found by the following principles:
+ * <ul>
+ * <li>Length of the matched name. Longest name matched to the given {@code s} has the
+ * highest priority.</li>
+ * <li>The current time zone and meta zones possible in the current country have higher
+ * priority than other zones.</li>
+ * <li>If only meta zones are matched, the country/region in the locale is used to select
+ * a reference time zone. For example, if the name is "Pacific Standard Time" and the country
+ * is US, America/Los_Angeles is returned.</li>
+ * </ul>
+ *
+ * @param text input string to be matched against time zone names in ICU
+ * @param start the begin index in the CharSequence {@code s}
+ * @param currentTzId the time zone ID prioritized to be matched if multiple time zone IDs can
+ * be matched and this is one of the matched IDs.
+ * @return null if no match is found
+ *
+ * @hide
+ */
+ @IntraCoreApi
+ public @Nullable Match matchNameToBeRenamed(@NonNull CharSequence text, int start,
+ @NonNull String currentTzId) {
+ MatchedTimeZone matchedTimeZone = matchName(text, start, currentTzId);
+ if (matchedTimeZone == null) {
+ return null;
+ }
+ return new Match(matchedTimeZone.matchLength, matchedTimeZone.tzId, matchedTimeZone.isDst);
+ }
+
+ /**
* Returns {@link MatchedTimeZone} if a time zone name in ICU can be matched against the input
* CharSequence {@code s}.
* The best match is found by the following principles: