Skip to content

Commit 9adcf8b

Browse files
committed
ICU-22668 Added unit tests to verify that CLDR-17892 addresses the original problem reported here and took out an
earlier hack in the Java code to work around the original problem.
1 parent 1c2a1c5 commit 9adcf8b

File tree

5 files changed

+85
-6
lines changed

5 files changed

+85
-6
lines changed

icu4c/source/test/cintltst/crelativedateformattest.c

+2
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,8 @@ static const RelDateTimeFormatTestItem fmtTestItems[] = {
343343
ak_decDef_long_stdAlon_sec, ak_attrDef_long_stdAlon_sec},
344344
{ "en_IN", -1, UDAT_STYLE_SHORT, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, UDAT_REL_UNIT_WEDNESDAY,
345345
enIN_decDef_short_midSent_weds, enIN_attrDef_short_midSent_weds},
346+
{ "en@calendar=iso8601", -1, UDAT_STYLE_LONG, UDISPCTX_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE, UDAT_REL_UNIT_SECOND,
347+
en_decDef_long_midSent_sec, en_attrDef_long_midSent_sec },
346348
{ NULL, 0, (UDateRelativeDateTimeFormatterStyle)0, (UDisplayContext)0, (URelativeDateTimeUnit)0, NULL, NULL } /* terminator */
347349
};
348350

icu4c/source/test/cintltst/udatpg_test.c

+46
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#if !UCONFIG_NO_FORMATTING
3131

3232
#include <stdbool.h>
33+
#include <stdio.h> // for sprintf()
3334

3435
#include "unicode/udat.h"
3536
#include "unicode/udatpg.h"
@@ -51,7 +52,9 @@ static void TestGetDefaultHourCycleOnEmptyInstance(void);
5152
static void TestEras(void);
5253
static void TestDateTimePatterns(void);
5354
static void TestRegionOverride(void);
55+
static void TestISO8601(void);
5456

57+
5558
void addDateTimePatternGeneratorTest(TestNode** root) {
5659
TESTCASE(TestOpenClose);
5760
TESTCASE(TestUsage);
@@ -63,6 +66,7 @@ void addDateTimePatternGeneratorTest(TestNode** root) {
6366
TESTCASE(TestEras);
6467
TESTCASE(TestDateTimePatterns);
6568
TESTCASE(TestRegionOverride);
69+
TESTCASE(TestISO8601);
6670
}
6771

6872
/*
@@ -836,4 +840,46 @@ static void TestRegionOverride(void) {
836840
udatpg_close(dtpg);
837841
}
838842
}
843+
844+
static void TestISO8601(void) {
845+
typedef struct TestCase {
846+
const char* locale;
847+
const UChar* skeleton;
848+
const UChar* expectedPattern;
849+
} TestCase;
850+
851+
const TestCase testCases[] = {
852+
{ "en_GB@calendar=iso8601;rg=uszzzz", u"EEEEyMMMMdjmm", u"y MMMM d, EEEE 'at' h:mm a" },
853+
{ "en_GB@calendar=iso8601;rg=uszzzz", u"EEEEyMMMMdHmm", u"y MMMM d, EEEE 'at' HH:mm" },
854+
{ "en_GB@calendar=iso8601;rg=uszzzz", u"Edjmm", u"d, EEE, h:mm a" },
855+
{ "en_GB@calendar=iso8601;rg=uszzzz", u"EdHmm", u"d, EEE, HH:mm" },
856+
857+
{ "en_US@calendar=iso8601", u"EEEEyMMMMdjmm", u"y MMMM d, EEEE 'at' h:mm a" },
858+
{ "en_US@calendar=iso8601", u"EEEEyMMMMdHmm", u"y MMMM d, EEEE 'at' HH:mm" },
859+
{ "en_US@calendar=iso8601", u"Edjmm", u"d, EEE, h:mm a" },
860+
{ "en_US@calendar=iso8601", u"EdHmm", u"d, EEE, HH:mm" },
861+
862+
{ "en_US", u"EEEEyMMMMdjmm", u"EEEE, MMMM d, y 'at' h:mm a" },
863+
{ "en_US", u"EEEEyMMMMdHmm", u"EEEE, MMMM d, y 'at' HH:mm" },
864+
{ "en_US", u"Edjmm", u"d EEE, h:mm a" },
865+
{ "en_US", u"EdHmm", u"d EEE, HH:mm" },
866+
};
867+
868+
for (int32_t i = 0; i < UPRV_LENGTHOF(testCases); i++) {
869+
UErrorCode err = U_ZERO_ERROR;
870+
UDateTimePatternGenerator* dtpg = udatpg_open(testCases[i].locale, &err);
871+
872+
if (assertSuccess("Error creating dtpg", &err)) {
873+
UChar actualPattern[200];
874+
875+
udatpg_getBestPatternWithOptions(dtpg, testCases[i].skeleton, -1, 0, actualPattern, UPRV_LENGTHOF(actualPattern), &err);
876+
if (assertSuccess("Error getting best pattern", &err)) {
877+
char errorMessage[200];
878+
snprintf(errorMessage, UPRV_LENGTHOF(errorMessage), "Wrong pattern for %s and %s", testCases[i].locale, austrdup(testCases[i].skeleton));
879+
assertUEquals(errorMessage, testCases[i].expectedPattern, actualPattern);
880+
}
881+
}
882+
udatpg_close(dtpg);
883+
}
884+
}
839885
#endif

icu4j/main/core/src/main/java/com/ibm/icu/text/DateTimePatternGenerator.java

-6
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,6 @@ private void addICUPatterns(PatternInfo returnInfo, ULocale uLocale) {
175175
// first load with the ICU patterns
176176
ICUResourceBundle rb = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, uLocale);
177177
String calendarTypeToUse = getCalendarTypeToUse(uLocale);
178-
// TODO: this is a HACK to work around ICU-22668/CLDR-17892! Remove once they're fixed!
179-
// (Without this hack, DateTimeGeneratorTest.testISO8601() fails. The corresponding test
180-
// on the C++ side still _passes_, so I have NOT added this hack on the C++ side. --rtg 8/21/24)
181-
if (calendarTypeToUse.equals("iso8601")) {
182-
calendarTypeToUse = "gregorian";
183-
}
184178
// TODO: See ICU-22867
185179
ICUResourceBundle dateTimePatterns = rb.getWithFallback("calendar/" + calendarTypeToUse + "/DateTimePatterns");
186180
if (dateTimePatterns.getType() != UResourceBundle.ARRAY || dateTimePatterns.getSize() < 8) {

icu4j/main/core/src/test/java/com/ibm/icu/dev/test/format/DateTimeGeneratorTest.java

+34
Original file line numberDiff line numberDiff line change
@@ -2066,4 +2066,38 @@ public void testRegionOverride() {
20662066
assertEquals("Wrong pattern", expectedPattern, actualPattern);
20672067
}
20682068
}
2069+
2070+
@Test
2071+
public void testISO8601More() {
2072+
final String[][] testCases = {
2073+
{ "en_GB@calendar=iso8601;rg=uszzzz", "EEEEyMMMMdjmm", "y MMMM d, EEEE 'at' h:mm a" },
2074+
{ "en_GB@calendar=iso8601;rg=uszzzz", "EEEEyMMMMdHmm", "y MMMM d, EEEE 'at' HH:mm" },
2075+
{ "en_GB@calendar=iso8601;rg=uszzzz", "Edjmm", "d, EEE, h:mm a" },
2076+
{ "en_GB@calendar=iso8601;rg=uszzzz", "EdHmm", "d, EEE, HH:mm" },
2077+
2078+
{ "en_US@calendar=iso8601", "EEEEyMMMMdjmm", "y MMMM d, EEEE 'at' h:mm a" },
2079+
{ "en_US@calendar=iso8601", "EEEEyMMMMdHmm", "y MMMM d, EEEE 'at' HH:mm" },
2080+
{ "en_US@calendar=iso8601", "Edjmm", "d, EEE, h:mm a" },
2081+
{ "en_US@calendar=iso8601", "EdHmm", "d, EEE, HH:mm" },
2082+
2083+
{ "en_US", "EEEEyMMMMdjmm", "EEEE, MMMM d, y 'at' h:mm a" },
2084+
{ "en_US", "EEEEyMMMMdHmm", "EEEE, MMMM d, y 'at' HH:mm" },
2085+
{ "en_US", "Edjmm", "d EEE, h:mm a" },
2086+
{ "en_US", "EdHmm", "d EEE, HH:mm" },
2087+
};
2088+
2089+
for (String[] testCase : testCases) {
2090+
String localeID = testCase[0];
2091+
String skeleton = testCase[1];
2092+
String expectedPattern = testCase[2];
2093+
2094+
DateTimePatternGenerator dtpg = DateTimePatternGenerator.getInstance(new ULocale(localeID));
2095+
2096+
String actualPattern = dtpg.getBestPattern(skeleton);
2097+
assertEquals("Wrong pattern for " + localeID + " and " + skeleton, expectedPattern, actualPattern);
2098+
// if (!expectedPattern.equals(actualPattern)) {
2099+
// System.out.println("Wrong pattern for " + localeID + " and " + skeleton + ": expected \"" + expectedPattern + "\", got \'" + actualPattern + "\"");
2100+
// }
2101+
}
2102+
}
20692103
}

icu4j/main/core/src/test/java/com/ibm/icu/dev/test/format/RelativeDateTimeFormatterTest.java

+3
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,9 @@ public TestRelativeDateTimeUnitItem(String locID, int decP, RelativeDateTimeForm
11941194
RelativeDateTimeUnit.FRIDAY, enIN_decDef_short_midSent_friday),
11951195
new TestRelativeDateTimeUnitItem("en_IN", -1, Style.SHORT, DisplayContext.CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE,
11961196
RelativeDateTimeUnit.SATURDAY, enIN_decDef_short_midSent_saturday),
1197+
1198+
new TestRelativeDateTimeUnitItem("en@calendar=iso8601", -1, Style.LONG, DisplayContext.CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE,
1199+
RelativeDateTimeUnit.SECOND, en_decDef_long_midSent_sec),
11971200
};
11981201
for (TestRelativeDateTimeUnitItem item: items) {
11991202
ULocale uloc = new ULocale(item.localeID);

0 commit comments

Comments
 (0)