Skip to content

Commit 2ca7c49

Browse files
committed
ICU-22464 Fix Java DateFormatSymbols to copy abbreviated day period names to the other sizes when appropriate.
1 parent 87d606c commit 2ca7c49

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

icu4j/main/common_tests/src/test/java/com/ibm/icu/dev/test/format/DateFormatTest.java

-4
Original file line numberDiff line numberDiff line change
@@ -5275,7 +5275,6 @@ public void TestDayPeriodWithLocales() {
52755275
assertEquals("hh:mm:ss bbbb | 12:00:00 | de", "12:00:00 PM", sdf.format(k120000));
52765276

52775277
// Locale ee has a rule that wraps around midnight (21h - 4h).
5278-
if (!logKnownIssue("ICU-22464", "Wide time format BBBB is not formatting with night time for ee")) {
52795278
sdf = new SimpleDateFormat("", new ULocale("ee"));
52805279
sdf.setTimeZone(TimeZone.GMT_ZONE);
52815280

@@ -5284,7 +5283,6 @@ public void TestDayPeriodWithLocales() {
52845283
assertEquals("hh:mm:ss BBBB | 22:00:00 | ee", "10:00:00 zã", sdf.format(k220000));
52855284
assertEquals("hh:mm:ss BBBB | 00:00:00 | ee", "12:00:00 zã", sdf.format(k000000));
52865285
assertEquals("hh:mm:ss BBBB | 01:00:00 | ee", "01:00:00 zã", sdf.format(k010000));
5287-
}
52885286

52895287
// Locale root has rules for AM/PM only.
52905288
sdf = new SimpleDateFormat("", new ULocale("root"));
@@ -5318,7 +5316,6 @@ public void TestDayPeriodWithLocales() {
53185316
// Locale es_CO should not fall back to es and should have a
53195317
// different string for 1 in the morning.
53205318
// (es_CO: "de la mañana" vs. es: "de la madrugada")
5321-
if (!logKnownIssue("ICU-22464", "Wide time format BBBB is not formatting with night time for es and es_CO")) {
53225319
sdf = new SimpleDateFormat("", new ULocale("es_CO"));
53235320
sdf.setTimeZone(TimeZone.GMT_ZONE);
53245321

@@ -5330,7 +5327,6 @@ public void TestDayPeriodWithLocales() {
53305327

53315328
sdf.applyPattern("hh:mm:ss BBBB");
53325329
assertEquals("hh:mm:ss BBBB | 01:00:00 | es", "01:00:00 de la madrugada", sdf.format(k010000));
5333-
}
53345330

53355331
// #13215: for locales with keywords, check hang in DayPeriodRules.getInstance(ULocale),
53365332
// which is called in SimpleDateFormat.format for patterns that include 'B'.

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

+22-13
Original file line numberDiff line numberDiff line change
@@ -2004,12 +2004,12 @@ protected void initializeData(ULocale desiredLocale, ICUResourceBundle b, String
20042004
standaloneShortQuarters = arrays.get("quarters/stand-alone/abbreviated");
20052005
standaloneNarrowQuarters = arrays.get("quarters/stand-alone/narrow");
20062006

2007-
abbreviatedDayPeriods = loadDayPeriodStrings(maps.get("dayPeriod/format/abbreviated"));
2008-
wideDayPeriods = loadDayPeriodStrings(maps.get("dayPeriod/format/wide"));
2009-
narrowDayPeriods = loadDayPeriodStrings(maps.get("dayPeriod/format/narrow"));
2010-
standaloneAbbreviatedDayPeriods = loadDayPeriodStrings(maps.get("dayPeriod/stand-alone/abbreviated"));
2011-
standaloneWideDayPeriods = loadDayPeriodStrings(maps.get("dayPeriod/stand-alone/wide"));
2012-
standaloneNarrowDayPeriods = loadDayPeriodStrings(maps.get("dayPeriod/stand-alone/narrow"));
2007+
abbreviatedDayPeriods = loadDayPeriodStrings(maps.get("dayPeriod/format/abbreviated"), null);
2008+
wideDayPeriods = loadDayPeriodStrings(maps.get("dayPeriod/format/wide"), abbreviatedDayPeriods);
2009+
narrowDayPeriods = loadDayPeriodStrings(maps.get("dayPeriod/format/narrow"), abbreviatedDayPeriods);
2010+
standaloneAbbreviatedDayPeriods = loadDayPeriodStrings(maps.get("dayPeriod/stand-alone/abbreviated"), abbreviatedDayPeriods);
2011+
standaloneWideDayPeriods = loadDayPeriodStrings(maps.get("dayPeriod/stand-alone/wide"), standaloneAbbreviatedDayPeriods);
2012+
standaloneNarrowDayPeriods = loadDayPeriodStrings(maps.get("dayPeriod/stand-alone/narrow"), standaloneAbbreviatedDayPeriods);
20132013

20142014
for (int i = 0; i < DT_MONTH_PATTERN_COUNT; i++) {
20152015
String monthPatternPath = LEAP_MONTH_PATTERNS_PATHS[i];
@@ -2129,15 +2129,24 @@ private static final boolean arrayOfArrayEquals(Object[][] aa1, Object[][]aa2) {
21292129
/**
21302130
* Loads localized names for day periods in the requested format.
21312131
* @param resourceMap Contains the dayPeriod resource to load
2132-
*/
2133-
private String[] loadDayPeriodStrings(Map<String, String> resourceMap) {
2134-
String strings[] = new String[DAY_PERIOD_KEYS.length];
2135-
if (resourceMap != null) {
2136-
for (int i = 0; i < DAY_PERIOD_KEYS.length; ++i) {
2137-
strings[i] = resourceMap.get(DAY_PERIOD_KEYS[i]); // Null if string doesn't exist.
2132+
* @param copyFrom If non-null, any values in the result that would otherwise be null are copied
2133+
* from this array
2134+
*/
2135+
private String[] loadDayPeriodStrings(Map<String, String> resourceMap, String[] copyFrom) {
2136+
if (resourceMap == null && copyFrom != null) {
2137+
return copyFrom;
2138+
} else {
2139+
String strings[] = new String[DAY_PERIOD_KEYS.length];
2140+
if (resourceMap != null) {
2141+
for (int i = 0; i < DAY_PERIOD_KEYS.length; ++i) {
2142+
strings[i] = resourceMap.get(DAY_PERIOD_KEYS[i]); // Null if string doesn't exist.
2143+
if (strings[i] == null && copyFrom != null) {
2144+
strings[i] = copyFrom[i];
2145+
}
2146+
}
21382147
}
2148+
return strings;
21392149
}
2140-
return strings;
21412150
}
21422151

21432152
/*

0 commit comments

Comments
 (0)