summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Chang <vichang@google.com>2021-01-19 10:19:12 +0000
committerVictor Chang <vichang@google.com>2024-04-19 12:16:36 +0100
commit8c161094f739f5632f6f11c5651a47fc957e8cb3 (patch)
tree8447b4fc6ea20a98c7f0e04dad5d23c6b7921728
parentabd82b16c097c25d3337eec761efda24192c64ee (diff)
downloadicu-8c161094f739f5632f6f11c5651a47fc957e8cb3.tar.gz
Android patch: Allow duplicated fields in DateTimePatternGenerator
The original patch can be found at https://r.android.com/1458480 A skeleton, e.g. "jmma", is mapped into "ahmma" internally by #mapSkeletonMetacharacters, and thus the internal skeleton has duplicated fields "a". This is a regression when we moved the implementation of android.text.format.DateFormat#getBestPattern() from udatpg_getBestPattern in ICU4C to ICU4j DateTimePatternGenerator in the CL https://r.android.com/1355735. The expected pattern generated from skeleton of "jmma" is "h:mm a". Bug: 170233598 Test: n/a Change-Id: I532956cb8ec85e093d1174fc84e915bd16e7248e
-rw-r--r--icu4j/main/core/src/main/java/com/ibm/icu/text/DateTimePatternGenerator.java22
1 files changed, 20 insertions, 2 deletions
diff --git a/icu4j/main/core/src/main/java/com/ibm/icu/text/DateTimePatternGenerator.java b/icu4j/main/core/src/main/java/com/ibm/icu/text/DateTimePatternGenerator.java
index d66b478b0..f2fff195e 100644
--- a/icu4j/main/core/src/main/java/com/ibm/icu/text/DateTimePatternGenerator.java
+++ b/icu4j/main/core/src/main/java/com/ibm/icu/text/DateTimePatternGenerator.java
@@ -630,16 +630,34 @@ public class DateTimePatternGenerator implements Freezable<DateTimePatternGenera
return getBestPattern(skeleton, null, options);
}
+ // BEGIN Android-added: http://b/170233598 Allow duplicate fields
+ /**
+ * @internal
+ */
+ public String getBestPattern(String skeleton, boolean allowDuplicateFields) {
+ return getBestPattern(skeleton, null, MATCH_NO_OPTIONS, allowDuplicateFields);
+ }
+
+ private String getBestPattern(String skeleton, DateTimeMatcher skipMatcher, int options) {
+ return getBestPattern(skeleton, skipMatcher, options, false);
+ }
+ // END Android-added: http://b/170233598 Allow duplicate fields
+
/*
* getBestPattern which takes optional skip matcher
*/
- private String getBestPattern(String skeleton, DateTimeMatcher skipMatcher, int options) {
+ // Android-changed: http://b/170233598 Allow duplicate fields
+ // private String getBestPattern(String skeleton, DateTimeMatcher skipMatcher, int options) {
+ private String getBestPattern(String skeleton, DateTimeMatcher skipMatcher, int options,
+ boolean allowDuplicateFields) {
EnumSet<DTPGflags> flags = EnumSet.noneOf(DTPGflags.class);
// Replace hour metacharacters 'j', 'C', and 'J', set flags as necessary
String skeletonMapped = mapSkeletonMetacharacters(skeleton, flags);
String datePattern, timePattern;
synchronized(this) {
- current.set(skeletonMapped, fp, false);
+ // Android-changed: http://b/170233598 Allow duplicate fields
+ // current.set(skeletonMapped, fp, false);
+ current.set(skeletonMapped, fp, allowDuplicateFields);
PatternWithMatcher bestWithMatcher = getBestRaw(current, -1, _distanceInfo, skipMatcher);
if (_distanceInfo.missingFieldMask == 0 && _distanceInfo.extraFieldMask == 0) {
// we have a good item. Adjust the field types