diff --git a/icu4c/source/test/cintltst/crelativedateformattest.c b/icu4c/source/test/cintltst/crelativedateformattest.c index 6f94fe45f62a..1dafd4f10b5b 100644 --- a/icu4c/source/test/cintltst/crelativedateformattest.c +++ b/icu4c/source/test/cintltst/crelativedateformattest.c @@ -343,6 +343,8 @@ static const RelDateTimeFormatTestItem fmtTestItems[] = { ak_decDef_long_stdAlon_sec, ak_attrDef_long_stdAlon_sec}, { "en_IN", -1, UDAT_STYLE_SHORT, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, UDAT_REL_UNIT_WEDNESDAY, enIN_decDef_short_midSent_weds, enIN_attrDef_short_midSent_weds}, + { "en@calendar=iso8601", -1, UDAT_STYLE_LONG, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, UDAT_REL_UNIT_SECOND, + en_decDef_long_midSent_sec, en_attrDef_long_midSent_sec }, { NULL, 0, (UDateRelativeDateTimeFormatterStyle)0, (UDisplayContext)0, (URelativeDateTimeUnit)0, NULL, NULL } /* terminator */ }; diff --git a/icu4c/source/test/cintltst/udatpg_test.c b/icu4c/source/test/cintltst/udatpg_test.c index 5475c195426b..b9278085b205 100644 --- a/icu4c/source/test/cintltst/udatpg_test.c +++ b/icu4c/source/test/cintltst/udatpg_test.c @@ -30,6 +30,7 @@ #if !UCONFIG_NO_FORMATTING #include +#include // for sprintf() #include "unicode/udat.h" #include "unicode/udatpg.h" @@ -51,7 +52,9 @@ static void TestGetDefaultHourCycleOnEmptyInstance(void); static void TestEras(void); static void TestDateTimePatterns(void); static void TestRegionOverride(void); +static void TestISO8601(void); + void addDateTimePatternGeneratorTest(TestNode** root) { TESTCASE(TestOpenClose); TESTCASE(TestUsage); @@ -63,6 +66,7 @@ void addDateTimePatternGeneratorTest(TestNode** root) { TESTCASE(TestEras); TESTCASE(TestDateTimePatterns); TESTCASE(TestRegionOverride); + TESTCASE(TestISO8601); } /* @@ -836,4 +840,46 @@ static void TestRegionOverride(void) { udatpg_close(dtpg); } } + +static void TestISO8601(void) { + typedef struct TestCase { + const char* locale; + const UChar* skeleton; + const UChar* expectedPattern; + } TestCase; + + const TestCase testCases[] = { + { "en_GB@calendar=iso8601;rg=uszzzz", u"EEEEyMMMMdjmm", u"y MMMM d, EEEE 'at' h:mm a" }, + { "en_GB@calendar=iso8601;rg=uszzzz", u"EEEEyMMMMdHmm", u"y MMMM d, EEEE 'at' HH:mm" }, + { "en_GB@calendar=iso8601;rg=uszzzz", u"Edjmm", u"d, EEE, h:mm a" }, + { "en_GB@calendar=iso8601;rg=uszzzz", u"EdHmm", u"d, EEE, HH:mm" }, + + { "en_US@calendar=iso8601", u"EEEEyMMMMdjmm", u"y MMMM d, EEEE 'at' h:mm a" }, + { "en_US@calendar=iso8601", u"EEEEyMMMMdHmm", u"y MMMM d, EEEE 'at' HH:mm" }, + { "en_US@calendar=iso8601", u"Edjmm", u"d, EEE, h:mm a" }, + { "en_US@calendar=iso8601", u"EdHmm", u"d, EEE, HH:mm" }, + + { "en_US", u"EEEEyMMMMdjmm", u"EEEE, MMMM d, y 'at' h:mm a" }, + { "en_US", u"EEEEyMMMMdHmm", u"EEEE, MMMM d, y 'at' HH:mm" }, + { "en_US", u"Edjmm", u"d EEE, h:mm a" }, + { "en_US", u"EdHmm", u"d EEE, HH:mm" }, + }; + + for (int32_t i = 0; i < UPRV_LENGTHOF(testCases); i++) { + UErrorCode err = U_ZERO_ERROR; + UDateTimePatternGenerator* dtpg = udatpg_open(testCases[i].locale, &err); + + if (assertSuccess("Error creating dtpg", &err)) { + UChar actualPattern[200]; + + udatpg_getBestPatternWithOptions(dtpg, testCases[i].skeleton, -1, 0, actualPattern, UPRV_LENGTHOF(actualPattern), &err); + if (assertSuccess("Error getting best pattern", &err)) { + char errorMessage[200]; + snprintf(errorMessage, UPRV_LENGTHOF(errorMessage), "Wrong pattern for %s and %s", testCases[i].locale, austrdup(testCases[i].skeleton)); + assertUEquals(errorMessage, testCases[i].expectedPattern, actualPattern); + } + } + udatpg_close(dtpg); + } +} #endif 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 2210cfb4fe6b..44c884dae558 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 @@ -175,12 +175,6 @@ private void addICUPatterns(PatternInfo returnInfo, ULocale uLocale) { // first load with the ICU patterns ICUResourceBundle rb = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, uLocale); String calendarTypeToUse = getCalendarTypeToUse(uLocale); - // TODO: this is a HACK to work around ICU-22668/CLDR-17892! Remove once they're fixed! - // (Without this hack, DateTimeGeneratorTest.testISO8601() fails. The corresponding test - // on the C++ side still _passes_, so I have NOT added this hack on the C++ side. --rtg 8/21/24) - if (calendarTypeToUse.equals("iso8601")) { - calendarTypeToUse = "gregorian"; - } // TODO: See ICU-22867 ICUResourceBundle dateTimePatterns = rb.getWithFallback("calendar/" + calendarTypeToUse + "/DateTimePatterns"); if (dateTimePatterns.getType() != UResourceBundle.ARRAY || dateTimePatterns.getSize() < 8) { 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 dd51e3e7e8d4..e52dd2e53f08 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 @@ -2066,4 +2066,38 @@ public void testRegionOverride() { assertEquals("Wrong pattern", expectedPattern, actualPattern); } } + + @Test + public void testISO8601More() { + final String[][] testCases = { + { "en_GB@calendar=iso8601;rg=uszzzz", "EEEEyMMMMdjmm", "y MMMM d, EEEE 'at' h:mm a" }, + { "en_GB@calendar=iso8601;rg=uszzzz", "EEEEyMMMMdHmm", "y MMMM d, EEEE 'at' HH:mm" }, + { "en_GB@calendar=iso8601;rg=uszzzz", "Edjmm", "d, EEE, h:mm a" }, + { "en_GB@calendar=iso8601;rg=uszzzz", "EdHmm", "d, EEE, HH:mm" }, + + { "en_US@calendar=iso8601", "EEEEyMMMMdjmm", "y MMMM d, EEEE 'at' h:mm a" }, + { "en_US@calendar=iso8601", "EEEEyMMMMdHmm", "y MMMM d, EEEE 'at' HH:mm" }, + { "en_US@calendar=iso8601", "Edjmm", "d, EEE, h:mm a" }, + { "en_US@calendar=iso8601", "EdHmm", "d, EEE, HH:mm" }, + + { "en_US", "EEEEyMMMMdjmm", "EEEE, MMMM d, y 'at' h:mm a" }, + { "en_US", "EEEEyMMMMdHmm", "EEEE, MMMM d, y 'at' HH:mm" }, + { "en_US", "Edjmm", "d EEE, h:mm a" }, + { "en_US", "EdHmm", "d EEE, HH:mm" }, + }; + + for (String[] testCase : testCases) { + String localeID = testCase[0]; + String skeleton = testCase[1]; + String expectedPattern = testCase[2]; + + DateTimePatternGenerator dtpg = DateTimePatternGenerator.getInstance(new ULocale(localeID)); + + String actualPattern = dtpg.getBestPattern(skeleton); + assertEquals("Wrong pattern for " + localeID + " and " + skeleton, expectedPattern, actualPattern); +// if (!expectedPattern.equals(actualPattern)) { +// System.out.println("Wrong pattern for " + localeID + " and " + skeleton + ": expected \"" + expectedPattern + "\", got \'" + actualPattern + "\""); +// } + } + } } diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/format/RelativeDateTimeFormatterTest.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/format/RelativeDateTimeFormatterTest.java index ad868ef1087d..ab22ee99134b 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/format/RelativeDateTimeFormatterTest.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/format/RelativeDateTimeFormatterTest.java @@ -1194,6 +1194,9 @@ public TestRelativeDateTimeUnitItem(String locID, int decP, RelativeDateTimeForm RelativeDateTimeUnit.FRIDAY, enIN_decDef_short_midSent_friday), new TestRelativeDateTimeUnitItem("en_IN", -1, Style.SHORT, DisplayContext.CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, RelativeDateTimeUnit.SATURDAY, enIN_decDef_short_midSent_saturday), + + new TestRelativeDateTimeUnitItem("en@calendar=iso8601", -1, Style.LONG, DisplayContext.CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, + RelativeDateTimeUnit.SECOND, en_decDef_long_midSent_sec), }; for (TestRelativeDateTimeUnitItem item: items) { ULocale uloc = new ULocale(item.localeID);