]> granicus.if.org Git - icu/commitdiff
ICU-21939 Fix bogus "conflicting fields" error in DateIntervalFormat.
authorRich Gillam <62772518+richgillam@users.noreply.github.com>
Fri, 15 Jul 2022 00:40:18 +0000 (17:40 -0700)
committerRich Gillam <62772518+richgillam@users.noreply.github.com>
Mon, 18 Jul 2022 22:16:40 +0000 (15:16 -0700)
icu4c/source/test/intltest/dtifmtts.cpp
icu4c/source/test/intltest/dtifmtts.h
icu4j/main/classes/core/src/com/ibm/icu/text/DateTimePatternGenerator.java
icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/DateIntervalFormatTest.java

index 82322019b2a3aa8454408019657688eb408b110b..e563212441b65cf48e9d9527df34c1a375d58b42 100644 (file)
@@ -65,6 +65,7 @@ void DateIntervalFormatTest::runIndexedTest( int32_t index, UBool exec, const ch
     TESTCASE_AUTO(testTicket21222GregorianEraDiff);
     TESTCASE_AUTO(testTicket21222ROCEraDiff);
     TESTCASE_AUTO(testTicket21222JapaneseEraDiff);
+    TESTCASE_AUTO(testTicket21939);
     TESTCASE_AUTO_END;
 }
 
@@ -2372,4 +2373,16 @@ void DateIntervalFormatTest::testTicket21222JapaneseEraDiff() {
     verifyCategoryAndField(formatted, expectedCategory, expectedField, status);
 }
 
+void DateIntervalFormatTest::testTicket21939() {
+    IcuTestErrorCode err(*this, "testTicket21939");
+    LocalPointer<DateIntervalFormat> dif(DateIntervalFormat::createInstance(u"rMdhm", Locale::forLanguageTag("en-u-ca-chinese", err), err));
+    
+    if (assertSuccess("Error creating DateIntervalFormat", err)) {
+        const DateFormat* df = dif->getDateFormat();
+        const SimpleDateFormat* sdf = dynamic_cast<const SimpleDateFormat*>(df);
+        UnicodeString pattern;
+        assertEquals("Wrong pattern", u"M/d/r, h:mm\u202Fa", sdf->toPattern(pattern));
+    }
+}
+
 #endif /* #if !UCONFIG_NO_FORMATTING */
index 428b209a0958b8c78a800d83f577e2e0313ad556..bced7292ed09bd5c804b2f5eeab61b25165b11d3 100644 (file)
@@ -88,6 +88,8 @@ public:
     void testTicket21222GregorianEraDiff();
     void testTicket21222ROCEraDiff();
     void testTicket21222JapaneseEraDiff();
+    
+    void testTicket21939();
 
 private:
     /**
index 3792850a8b2dc442ce9187de65a661a33b2ff04b..c649964488d3ebdd3ee582f1082eec291eaa94b2 100644 (file)
@@ -2804,8 +2804,8 @@ public class DateTimePatternGenerator implements Freezable<DateTimePatternGenera
                     char ch1 = original.getFieldChar(field);
                     char ch2 = value.charAt(0);
                     if ( allowDuplicateFields ||
-                            (ch1 == 'r' && ch2 == 'U') ||
-                            (ch1 == 'U' && ch2 == 'r') ) {
+                            (ch1 == 'r' && (ch2 == 'U' || ch2 == 'y')) ||
+                            ((ch1 == 'U' || ch1 == 'y') && ch2 == 'r') ) {
                         continue;
                     }
                     throw new IllegalArgumentException("Conflicting fields:\t"
index 086f0a589c4457454ac188128b6ceb7f983be6b6..aa6961065724f9c583e066478b0183c6ab079501 100644 (file)
@@ -2481,4 +2481,14 @@ public class DateIntervalFormatTest extends TestFmwk {
                      formatted.toString());
         verifyFields(formatted, expectedFields);
     }
+    
+    @Test
+    public void testTicket21939() {
+        // the test here is just to check that this particular skeleton doesn't
+        // lead to an IllegalArgumentException
+        DateIntervalFormat dif = DateIntervalFormat.getInstance("rMdhm", ULocale.forLanguageTag("en-u-ca-chinese"));
+        DateFormat df = dif.getDateFormat();
+        SimpleDateFormat sdf = (SimpleDateFormat)df;
+        assertEquals("Wrong date format", "M/d/r, h:mm\u202Fa", sdf.toPattern());
+    }
 }