Skip to content

Commit

Permalink
ICU-22464 Fix Java DateFormatSymbols to copy abbreviated day period n…
Browse files Browse the repository at this point in the history
…ames to the other sizes when appropriate.
  • Loading branch information
richgillam committed Sep 20, 2023
1 parent 87d606c commit 2ca7c49
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
Expand Up @@ -5275,7 +5275,6 @@ public void TestDayPeriodWithLocales() {
assertEquals("hh:mm:ss bbbb | 12:00:00 | de", "12:00:00 PM", sdf.format(k120000));

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

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

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

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

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

// #13215: for locales with keywords, check hang in DayPeriodRules.getInstance(ULocale),
// which is called in SimpleDateFormat.format for patterns that include 'B'.
Expand Down
Expand Up @@ -2004,12 +2004,12 @@ protected void initializeData(ULocale desiredLocale, ICUResourceBundle b, String
standaloneShortQuarters = arrays.get("quarters/stand-alone/abbreviated");
standaloneNarrowQuarters = arrays.get("quarters/stand-alone/narrow");

abbreviatedDayPeriods = loadDayPeriodStrings(maps.get("dayPeriod/format/abbreviated"));
wideDayPeriods = loadDayPeriodStrings(maps.get("dayPeriod/format/wide"));
narrowDayPeriods = loadDayPeriodStrings(maps.get("dayPeriod/format/narrow"));
standaloneAbbreviatedDayPeriods = loadDayPeriodStrings(maps.get("dayPeriod/stand-alone/abbreviated"));
standaloneWideDayPeriods = loadDayPeriodStrings(maps.get("dayPeriod/stand-alone/wide"));
standaloneNarrowDayPeriods = loadDayPeriodStrings(maps.get("dayPeriod/stand-alone/narrow"));
abbreviatedDayPeriods = loadDayPeriodStrings(maps.get("dayPeriod/format/abbreviated"), null);
wideDayPeriods = loadDayPeriodStrings(maps.get("dayPeriod/format/wide"), abbreviatedDayPeriods);
narrowDayPeriods = loadDayPeriodStrings(maps.get("dayPeriod/format/narrow"), abbreviatedDayPeriods);
standaloneAbbreviatedDayPeriods = loadDayPeriodStrings(maps.get("dayPeriod/stand-alone/abbreviated"), abbreviatedDayPeriods);
standaloneWideDayPeriods = loadDayPeriodStrings(maps.get("dayPeriod/stand-alone/wide"), standaloneAbbreviatedDayPeriods);
standaloneNarrowDayPeriods = loadDayPeriodStrings(maps.get("dayPeriod/stand-alone/narrow"), standaloneAbbreviatedDayPeriods);

for (int i = 0; i < DT_MONTH_PATTERN_COUNT; i++) {
String monthPatternPath = LEAP_MONTH_PATTERNS_PATHS[i];
Expand Down Expand Up @@ -2129,15 +2129,24 @@ private static final boolean arrayOfArrayEquals(Object[][] aa1, Object[][]aa2) {
/**
* Loads localized names for day periods in the requested format.
* @param resourceMap Contains the dayPeriod resource to load
*/
private String[] loadDayPeriodStrings(Map<String, String> resourceMap) {
String strings[] = new String[DAY_PERIOD_KEYS.length];
if (resourceMap != null) {
for (int i = 0; i < DAY_PERIOD_KEYS.length; ++i) {
strings[i] = resourceMap.get(DAY_PERIOD_KEYS[i]); // Null if string doesn't exist.
* @param copyFrom If non-null, any values in the result that would otherwise be null are copied
* from this array
*/
private String[] loadDayPeriodStrings(Map<String, String> resourceMap, String[] copyFrom) {
if (resourceMap == null && copyFrom != null) {
return copyFrom;
} else {
String strings[] = new String[DAY_PERIOD_KEYS.length];
if (resourceMap != null) {
for (int i = 0; i < DAY_PERIOD_KEYS.length; ++i) {
strings[i] = resourceMap.get(DAY_PERIOD_KEYS[i]); // Null if string doesn't exist.
if (strings[i] == null && copyFrom != null) {
strings[i] = copyFrom[i];
}
}
}
return strings;
}
return strings;
}

/*
Expand Down

0 comments on commit 2ca7c49

Please sign in to comment.