Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLDR-10347 show one example for each day period, excluding midnight #3949

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2597,7 +2597,6 @@ private String handleDateFormatItem(String xpath, String value, boolean showCont
String numbersOverride = parts.findAttributeValue("pattern", "numbers");
SimpleDateFormat sdf =
icuServiceBuilder.getDateFormat(calendar, value, numbersOverride);
sdf.setTimeZone(ZONE_SAMPLE);
String defaultNumberingSystem =
cldrFile.getWinningValue("//ldml/numbers/defaultNumberingSystem");
String timeSeparator =
Expand All @@ -2609,6 +2608,7 @@ private String handleDateFormatItem(String xpath, String value, boolean showCont
dfs.setTimeSeparatorString(timeSeparator);
sdf.setDateFormatSymbols(dfs);
if (id == null || id.indexOf('B') < 0) {
sdf.setTimeZone(ZONE_SAMPLE);
// Standard date/time format, or availableFormat without dayPeriod
if (value.contains("MMM") || value.contains("LLL")) {
// alpha month, do not need context examples
Expand All @@ -2626,9 +2626,19 @@ private String handleDateFormatItem(String xpath, String value, boolean showCont
}
} else {
List<String> examples = new ArrayList<>();
examples.add(sdf.format(DATE_SAMPLE3));
examples.add(sdf.format(DATE_SAMPLE));
examples.add(sdf.format(DATE_SAMPLE4));
haytenf marked this conversation as resolved.
Show resolved Hide resolved
DayPeriodInfo dayPeriodInfo = supplementalDataInfo.getDayPeriods(DayPeriodInfo.Type.format, cldrFile.getLocaleID());
Set<DayPeriod> dayPeriods = new LinkedHashSet<DayPeriod>(dayPeriodInfo.getPeriods());
for (DayPeriod dayPeriod : dayPeriods) {
if (dayPeriod.equals(DayPeriod.midnight)) { // suppress midnight, see ICU-12278 bug
haytenf marked this conversation as resolved.
Show resolved Hide resolved
continue;
}
R3<Integer, Integer, Boolean> info = dayPeriodInfo.getFirstDayPeriodInfo(dayPeriod);
if (info != null) {
int time = ((info.get0() + info.get1()) / 2); // time midpoint
haytenf marked this conversation as resolved.
Show resolved Hide resolved
String formatted = sdf.format(time);
examples.add(formatted);
}
}
return formatExampleList(examples.toArray(new String[0]));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,56 @@ private void checkDayPeriod(
checkPathValue(exampleGenerator, path, cldrFile.getStringValue(path), expected);
}

public void TestAllDayPeriods() {
// excludes midnight, see ICU-12278
String[][] tests = {
haytenf marked this conversation as resolved.
Show resolved Hide resolved
{
"en",
"//ldml/dates/calendars/calendar"
+ "[@type=\"gregorian\"]/dateTimeFormats/"
+ "availableFormats/dateFormatItem"
+ "[@id=\"Bhm\"]",
"en day periods pattern \"Bhm\"",
"〖3:00 at night〗〖9:00 in the morning〗〖12:00 noon〗〖3:00 in the afternoon〗〖7:30 in the evening〗"
},
{
"it",
"//ldml/dates/calendars/calendar"
+ "[@type=\"gregorian\"]/dateTimeFormats/"
+ "availableFormats/dateFormatItem"
+ "[@id=\"Bhm\"]",
"it day periods pattern \"Bhm\"",
"〖3:00 di notte〗〖9:00 di mattina〗〖12:00 mezzogiorno〗〖3:00 di pomeriggio〗〖9:00 di sera〗"
},
{
"de",
"//ldml/dates/calendars/calendar"
+ "[@type=\"gregorian\"]/dateTimeFormats/"
+ "availableFormats/dateFormatItem"
+ "[@id=\"Bhm\"]",
"de day periods pattern \"Bhm\"",
"〖2:30 nachts〗〖7:30 morgens〗〖11:00 vorm.〗〖12:30 mittags〗〖3:30 nachm.〗〖9:00 abends〗"
},
{
"zh",
"//ldml/dates/calendars/calendar"
+ "[@type=\"gregorian\"]/dateTimeFormats/"
+ "availableFormats/dateFormatItem"
+ "[@id=\"Bhm\"]",
"zh day periods pattern \"Bhm\"",
"〖凌晨2:30〗〖早上6:30〗〖上午10:00〗〖中午12:30〗〖下午4:00〗〖晚上9:30〗"
},
};
for (String[] test : tests) {
final String locale = test[0];
final String path = test[1];
final String message = test[2];
final String expected = test[3];
ExampleGenerator exampleGenerator = getExampleGenerator(locale);
checkValue(message, expected, exampleGenerator, path);
}
}

/**
* Test that getExampleHtml returns same output for same input regardless of order in which it
* is called with different inputs.
Expand Down
Loading