From 5de4f5947872855cd63fdb5f5fa3aad106e3bd38 Mon Sep 17 00:00:00 2001 From: Rich Gillam Date: Fri, 17 Nov 2023 19:05:18 -0800 Subject: [PATCH] ICU-22575 Change AvailableFormatsSink to allow locales to inherit availableFormats items from the root locale. --- icu4c/source/i18n/dtptngen.cpp | 4 ++-- icu4c/source/test/cintltst/udatpg_test.c | 2 +- icu4c/source/test/intltest/dtifmtts.cpp | 4 ++-- icu4c/source/test/intltest/dtptngts.cpp | 8 +++++--- .../java/com/ibm/icu/text/DateTimePatternGenerator.java | 2 +- .../ibm/icu/dev/test/format/DateIntervalFormatTest.java | 4 ++-- .../ibm/icu/dev/test/format/DateTimeGeneratorTest.java | 9 ++++++--- 7 files changed, 19 insertions(+), 14 deletions(-) diff --git a/icu4c/source/i18n/dtptngen.cpp b/icu4c/source/i18n/dtptngen.cpp index 2947672013e7..aa23b7cd4a61 100644 --- a/icu4c/source/i18n/dtptngen.cpp +++ b/icu4c/source/i18n/dtptngen.cpp @@ -1023,7 +1023,7 @@ struct DateTimePatternGenerator::AvailableFormatsSink : public ResourceSink { AvailableFormatsSink(DateTimePatternGenerator& _dtpg) : dtpg(_dtpg) {} virtual ~AvailableFormatsSink(); - virtual void put(const char *key, ResourceValue &value, UBool isRoot, + virtual void put(const char *key, ResourceValue &value, UBool /*isRoot*/, UErrorCode &errorCode) override { const UnicodeString formatKey(key, -1, US_INV); if (!dtpg.isAvailableFormatSet(formatKey) ) { @@ -1032,7 +1032,7 @@ struct DateTimePatternGenerator::AvailableFormatsSink : public ResourceSink { // derived from std patterns, but not a previous availableFormats entry: const UnicodeString& formatValue = value.getUnicodeString(errorCode); conflictingPattern.remove(); - dtpg.addPatternWithSkeleton(formatValue, &formatKey, !isRoot, conflictingPattern, errorCode); + dtpg.addPatternWithSkeleton(formatValue, &formatKey, true, conflictingPattern, errorCode); } } }; diff --git a/icu4c/source/test/cintltst/udatpg_test.c b/icu4c/source/test/cintltst/udatpg_test.c index f67c6572858c..a28ab2b9d793 100644 --- a/icu4c/source/test/cintltst/udatpg_test.c +++ b/icu4c/source/test/cintltst/udatpg_test.c @@ -653,7 +653,7 @@ static void TestDateTimePatterns(void) { { "ha", { u"EEEE d MMMM, y 'da' HH:mm", u"d MMMM, y 'da' HH:mm", u"d MMM, y, HH:mm", - u"d/M/y, HH:mm" } }, + u"y-MM-dd, HH:mm" } }, { NULL, { NULL, NULL, NULL, NULL } } // terminator }; diff --git a/icu4c/source/test/intltest/dtifmtts.cpp b/icu4c/source/test/intltest/dtifmtts.cpp index 087366f027ba..9989d6ff5d29 100644 --- a/icu4c/source/test/intltest/dtifmtts.cpp +++ b/icu4c/source/test/intltest/dtifmtts.cpp @@ -1048,7 +1048,7 @@ void DateIntervalFormatTest::testFormat() { "th", "BE 2550 10 10 10:10:10", "BE 2550 11 10 10:10:10", "d", "10/10 \\u2013 10/11", - "th", "BE 2550 10 10 10:10:10", "BE 2550 11 10 10:10:10", "y", "2550", + "th", "BE 2550 10 10 10:10:10", "BE 2550 11 10 10:10:10", "y", "\\u0E1E.\\u0E28. 2550", "th", "BE 2550 10 10 10:10:10", "BE 2550 11 10 10:10:10", "MMM", "\\u0E15.\\u0E04.\\u2013\\u0E1E.\\u0E22.", @@ -2144,7 +2144,7 @@ void DateIntervalFormatTest::testTicket20707() { {u"12\u202FAM", u"00", u"00", u"12\u202FAM", u"12\u202FAM", u"0 (hour: 12)", u"12\u202FAM"}, {u"12\u202FAM", u"00", u"00", u"12\u202FAM", u"12\u202FAM", u"0 (hour: 12)", u"12\u202FAM"}, // Hour-cycle: K - {u"0 am", u"0", u"0", u"0 am", u"0 am", u"0 (\u0918\u0902\u091F\u093E: 0)", u"\u0930\u093E\u0924 0"} + {u"0 am", u"00", u"00", u"0 am", u"0 am", u"0 (\u0918\u0902\u091F\u093E: 00)", u"\u0930\u093E\u0924 0"} }; int32_t i = 0; diff --git a/icu4c/source/test/intltest/dtptngts.cpp b/icu4c/source/test/intltest/dtptngts.cpp index f387d7520d89..f780271bdec5 100644 --- a/icu4c/source/test/intltest/dtptngts.cpp +++ b/icu4c/source/test/intltest/dtptngts.cpp @@ -1168,9 +1168,9 @@ void IntlTestDateTimePatternGeneratorAPI::testC() { {"zh-TW", "CCCCm", "BBBBhh:mm"}, {"zh-TW", "CCCCCm", "BBBBBh:mm"}, {"zh-TW", "CCCCCCm", "BBBBBhh:mm"}, - {"de", "Cm", "H:mm"}, + {"de", "Cm", "HH:mm"}, {"de", "CCm", "HH:mm"}, - {"de", "CCCm", "H:mm"}, + {"de", "CCCm", "HH:mm"}, {"de", "CCCCm", "HH:mm"}, {"en", "Cm", "h:mm\\u202Fa"}, {"en", "CCm", "hh:mm\\u202Fa"}, @@ -1602,6 +1602,8 @@ void IntlTestDateTimePatternGeneratorAPI::testBestPattern() { { "en_GB@calendar=coptic", "yMd", u"dd/MM/y GGGGG" }, { "en_GB@calendar=japanese", "yMd", u"dd/MM/y GGGGG" }, { "en_GB@calendar=buddhist", "yMd", u"dd/MM/y GGGGG" }, + // ICU-22757: Not inheriting availableFormats patterns from root + { "sv_SE", "yMd", u"y-MM-dd" }, // ICU-20992: Bad patterns for missing fields { "ckb_IR", "mmSSS", u"mm:ss\u066bSSS" }, { "ckb_IR", "BSSS", u"SSS \u251c'Dayperiod': B\u2524" }, @@ -1657,7 +1659,7 @@ void IntlTestDateTimePatternGeneratorAPI::testDateTimePatterns() { { "ha", { UnicodeString(u"EEEE d MMMM, y 'da' HH:mm"), UnicodeString(u"d MMMM, y 'da' HH:mm"), UnicodeString(u"d MMM, y, HH:mm"), - UnicodeString(u"d/M/y, HH:mm") } }, + UnicodeString(u"y-MM-dd, HH:mm") } }, { nullptr, { UnicodeString(""), UnicodeString(""), // terminator UnicodeString(""), UnicodeString("") } }, }; 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 3b2b7040c90f..d66b478b0ed3 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 @@ -268,7 +268,7 @@ public void put(UResource.Key key, UResource.Value value, boolean isRoot) { // Add pattern with its associated skeleton. Override any duplicate derived from std patterns, // but not a previous availableFormats entry: String formatValue = value.toString(); - addPatternWithSkeleton(formatValue, formatKey, !isRoot, returnInfo); + addPatternWithSkeleton(formatValue, formatKey, true, returnInfo); } } } diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/format/DateIntervalFormatTest.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/format/DateIntervalFormatTest.java index a7ca4221ff9b..24e7f96851aa 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/format/DateIntervalFormatTest.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/format/DateIntervalFormatTest.java @@ -692,7 +692,7 @@ public void TestFormat() { "th", "BE 2550 10 10 10:10:10", "BE 2550 11 10 10:10:10", "d", "10/10 \\u2013 10/11", - "th", "BE 2550 10 10 10:10:10", "BE 2550 11 10 10:10:10", "y", "2550", + "th", "BE 2550 10 10 10:10:10", "BE 2550 11 10 10:10:10", "y", "\\u0e1e.\\u0e28. 2550", "th", "BE 2550 10 10 10:10:10", "BE 2550 11 10 10:10:10", "MMM", "\u0E15.\u0E04.\u2013\u0E1E.\u0E22.", @@ -2265,7 +2265,7 @@ public void testTicket20707() { {"0\u202FAM", "00", "00", "0\u202FAM", "0\u202FAM", "0 (hour: 00)", "0\u202FAM"}, {"12\u202FAM", "00", "00", "12\u202FAM", "12\u202FAM", "0 (hour: 12)", "12\u202FAM"}, {"12\u202FAM", "00", "00", "12\u202FAM", "12\u202FAM", "0 (hour: 12)", "12\u202FAM"}, - {"0 am", "0", "0", "0 am", "0 am", "0 (\u0918\u0902\u091F\u093E: 0)", "\u0930\u093E\u0924 0"} + {"0 am", "00", "00", "0 am", "0 am", "0 (\u0918\u0902\u091F\u093E: 00)", "\u0930\u093E\u0924 0"} }; int i = 0; diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/format/DateTimeGeneratorTest.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/format/DateTimeGeneratorTest.java index 9e43bd53f4cd..1b74f10cdef1 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/format/DateTimeGeneratorTest.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/format/DateTimeGeneratorTest.java @@ -65,9 +65,9 @@ public void TestC() { {"zh-TW", "CCCCm", "BBBBhh:mm"}, {"zh-TW", "CCCCCm", "BBBBBh:mm"}, {"zh-TW", "CCCCCCm", "BBBBBhh:mm"}, - {"de", "Cm", "H:mm"}, + {"de", "Cm", "HH:mm"}, {"de", "CCm", "HH:mm"}, - {"de", "CCCm", "H:mm"}, + {"de", "CCCm", "HH:mm"}, {"de", "CCCCm", "HH:mm"}, {"en", "Cm", "h:mm\u202Fa"}, {"en", "CCm", "hh:mm\u202Fa"}, @@ -1832,6 +1832,9 @@ public void testBestPattern() { // ICU-21873: Missing aliased values "en_001@calendar=islamic", "Ehm", "EEE h:mm\u202Fa", + + // ICU-22575: AvailableFormats not inheriting from root + "sv_SE", "yMd", "y-MM-dd", }; for (int i = 0; i < testCases.length; i += 3) { @@ -1921,7 +1924,7 @@ public void testDateTimePatterns() { "EEEE d MMMM, y 'da' HH:mm", "d MMMM, y 'da' HH:mm", "d MMM, y, HH:mm", - "d/M/y, HH:mm" } ), + "y-MM-dd, HH:mm" } ), }; String[] enDTPatterns = {