From cf294f071f911fc751b1af5fff7a0410a7ab2a70 Mon Sep 17 00:00:00 2001 From: Helena Aytenfisu Date: Thu, 8 Aug 2024 11:35:49 -0400 Subject: [PATCH 1/3] CLDR-10347 Show one example for each day period, excludes midnight --- .../unicode/cldr/test/ExampleGenerator.java | 18 +++++-- .../cldr/unittest/TestExampleGenerator.java | 50 +++++++++++++++++++ 2 files changed, 64 insertions(+), 4 deletions(-) diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/test/ExampleGenerator.java b/tools/cldr-code/src/main/java/org/unicode/cldr/test/ExampleGenerator.java index 913e4884462..1979c86a0e4 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/test/ExampleGenerator.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/test/ExampleGenerator.java @@ -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 = @@ -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 @@ -2626,9 +2626,19 @@ private String handleDateFormatItem(String xpath, String value, boolean showCont } } else { List examples = new ArrayList<>(); - examples.add(sdf.format(DATE_SAMPLE3)); - examples.add(sdf.format(DATE_SAMPLE)); - examples.add(sdf.format(DATE_SAMPLE4)); + DayPeriodInfo dayPeriodInfo = supplementalDataInfo.getDayPeriods(DayPeriodInfo.Type.format, cldrFile.getLocaleID()); + Set dayPeriods = new LinkedHashSet(dayPeriodInfo.getPeriods()); + for (DayPeriod dayPeriod : dayPeriods) { + if (dayPeriod.equals(DayPeriod.midnight)) { // suppress midnight, see ICU-12278 bug + continue; + } + R3 info = dayPeriodInfo.getFirstDayPeriodInfo(dayPeriod); + if (info != null) { + int time = ((info.get0() + info.get1()) / 2); // time midpoint + String formatted = sdf.format(time); + examples.add(formatted); + } + } return formatExampleList(examples.toArray(new String[0])); } } diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestExampleGenerator.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestExampleGenerator.java index a239a63f518..8947173477d 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestExampleGenerator.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestExampleGenerator.java @@ -1123,6 +1123,56 @@ private void checkDayPeriod( checkPathValue(exampleGenerator, path, cldrFile.getStringValue(path), expected); } + public void TestAllDayPeriods() { + // excludes midnight, see ICU-12278 + String[][] tests = { + { + "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. From 8cc6f65f0fedfd16d3f34ca42c83f657eebafb0c Mon Sep 17 00:00:00 2001 From: Helena Aytenfisu Date: Fri, 9 Aug 2024 13:24:50 -0400 Subject: [PATCH 2/3] CLDR-10347 Updated using style feedback --- .../unicode/cldr/test/ExampleGenerator.java | 7 +- .../cldr/unittest/TestExampleGenerator.java | 82 ++++++++----------- 2 files changed, 36 insertions(+), 53 deletions(-) diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/test/ExampleGenerator.java b/tools/cldr-code/src/main/java/org/unicode/cldr/test/ExampleGenerator.java index 1979c86a0e4..f487d932972 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/test/ExampleGenerator.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/test/ExampleGenerator.java @@ -168,7 +168,6 @@ public class ExampleGenerator { private static final Date DATE_SAMPLE2; private static final Date DATE_SAMPLE3; - private static final Date DATE_SAMPLE4; static { Calendar calendar = Calendar.getInstance(ZONE_SAMPLE, ULocale.ENGLISH); @@ -180,8 +179,6 @@ public class ExampleGenerator { calendar.set(1999, 8, 5, 7, 0, 0); // 1999-09-05 07:00:00 DATE_SAMPLE3 = calendar.getTime(); - calendar.set(1999, 8, 5, 23, 0, 0); // 1999-09-05 23:00:00 - DATE_SAMPLE4 = calendar.getTime(); } static final List CURRENCY_SAMPLES = @@ -2634,8 +2631,8 @@ private String handleDateFormatItem(String xpath, String value, boolean showCont } R3 info = dayPeriodInfo.getFirstDayPeriodInfo(dayPeriod); if (info != null) { - int time = ((info.get0() + info.get1()) / 2); // time midpoint - String formatted = sdf.format(time); + int time = ((info.get0() + info.get1()) / 2); // dayPeriod endpoints overlap, midpoint to disambiguate + String formatted = sdf.format(time); examples.add(formatted); } } diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestExampleGenerator.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestExampleGenerator.java index 8947173477d..7b457fae317 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestExampleGenerator.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestExampleGenerator.java @@ -1123,54 +1123,40 @@ private void checkDayPeriod( checkPathValue(exampleGenerator, path, cldrFile.getStringValue(path), expected); } - public void TestAllDayPeriods() { - // excludes midnight, see ICU-12278 - String[][] tests = { - { - "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); - } + public void TestAllDayPeriods() { // excludes midnight, see ICU-12278 + checkDayPeriodsForLocale( + "en", + "Bhm", + "〖3:00 at night〗〖9:00 in the morning〗〖12:00 noon〗〖3:00 in the afternoon〗〖7:30 in the evening〗"); + checkDayPeriodsForLocale( + "it", + "Bhm", + "〖3:00 di notte〗〖9:00 di mattina〗〖12:00 mezzogiorno〗〖3:00 di pomeriggio〗〖9:00 di sera〗"); + checkDayPeriodsForLocale( + "de", + "Bhm", + "〖2:30 nachts〗〖7:30 morgens〗〖11:00 vorm.〗〖12:30 mittags〗〖3:30 nachm.〗〖9:00 abends〗"); + checkDayPeriodsForLocale( + "zh", + "Bhm", + "〖凌晨2:30〗〖早上6:30〗〖上午10:00〗〖中午12:30〗〖下午4:00〗〖晚上9:30〗"); + checkDayPeriodsForLocale( + "am", + "EBhm", + "〖ሐሙስ በሌሊት 3:00〗〖ሐሙስ ጥዋት 9:00〗〖ሐሙስ ቀትር 12:00〗〖ሐሙስ ከሰዓት 3:00〗〖ሐሙስ በምሽት 9:00〗"); + checkDayPeriodsForLocale( + "hi", + "EBhms", + "〖गुरु रात 2:00:00〗〖गुरु सुबह 8:00:00〗〖गुरु दोपहर 2:00:00〗〖गुरु शाम 6:00:00〗"); + } + + public void checkDayPeriodsForLocale(String localeId, String pattern, String expected) { + ExampleGenerator exampleGenerator = getExampleGenerator(localeId); + String path = "//ldml/dates/calendars/calendar[@type=\"gregorian\"]" + + "/dateTimeFormats/availableFormats/dateFormatItem" + + "[@id=\"" + pattern + "\"]"; + String message = "Day periods with pattern \"" + pattern + "\""; + checkValue(message, expected, exampleGenerator, path); } /** From 2c29a6f041640992827242070a249d57bd499680 Mon Sep 17 00:00:00 2001 From: Helena Aytenfisu Date: Mon, 12 Aug 2024 16:57:29 -0400 Subject: [PATCH 3/3] CLDR-10347 Fixed formatting using spotless --- .../unicode/cldr/test/ExampleGenerator.java | 18 +++++++--- .../cldr/unittest/TestExampleGenerator.java | 36 +++++++++---------- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/tools/cldr-code/src/main/java/org/unicode/cldr/test/ExampleGenerator.java b/tools/cldr-code/src/main/java/org/unicode/cldr/test/ExampleGenerator.java index f487d932972..e3641e07fa9 100644 --- a/tools/cldr-code/src/main/java/org/unicode/cldr/test/ExampleGenerator.java +++ b/tools/cldr-code/src/main/java/org/unicode/cldr/test/ExampleGenerator.java @@ -2623,15 +2623,23 @@ private String handleDateFormatItem(String xpath, String value, boolean showCont } } else { List examples = new ArrayList<>(); - DayPeriodInfo dayPeriodInfo = supplementalDataInfo.getDayPeriods(DayPeriodInfo.Type.format, cldrFile.getLocaleID()); - Set dayPeriods = new LinkedHashSet(dayPeriodInfo.getPeriods()); + DayPeriodInfo dayPeriodInfo = + supplementalDataInfo.getDayPeriods( + DayPeriodInfo.Type.format, cldrFile.getLocaleID()); + Set dayPeriods = + new LinkedHashSet(dayPeriodInfo.getPeriods()); for (DayPeriod dayPeriod : dayPeriods) { - if (dayPeriod.equals(DayPeriod.midnight)) { // suppress midnight, see ICU-12278 bug + if (dayPeriod.equals( + DayPeriod.midnight)) { // suppress midnight, see ICU-12278 bug continue; } - R3 info = dayPeriodInfo.getFirstDayPeriodInfo(dayPeriod); + R3 info = + dayPeriodInfo.getFirstDayPeriodInfo(dayPeriod); if (info != null) { - int time = ((info.get0() + info.get1()) / 2); // dayPeriod endpoints overlap, midpoint to disambiguate + int time = + ((info.get0() + info.get1()) + / 2); // dayPeriod endpoints overlap, midpoint to + // disambiguate String formatted = sdf.format(time); examples.add(formatted); } diff --git a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestExampleGenerator.java b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestExampleGenerator.java index 7b457fae317..6eca391675e 100644 --- a/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestExampleGenerator.java +++ b/tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestExampleGenerator.java @@ -1123,38 +1123,38 @@ private void checkDayPeriod( checkPathValue(exampleGenerator, path, cldrFile.getStringValue(path), expected); } - public void TestAllDayPeriods() { // excludes midnight, see ICU-12278 + public void TestAllDayPeriods() { // excludes midnight, see ICU-12278 checkDayPeriodsForLocale( - "en", - "Bhm", + "en", + "Bhm", "〖3:00 at night〗〖9:00 in the morning〗〖12:00 noon〗〖3:00 in the afternoon〗〖7:30 in the evening〗"); checkDayPeriodsForLocale( - "it", - "Bhm", + "it", + "Bhm", "〖3:00 di notte〗〖9:00 di mattina〗〖12:00 mezzogiorno〗〖3:00 di pomeriggio〗〖9:00 di sera〗"); checkDayPeriodsForLocale( - "de", - "Bhm", + "de", + "Bhm", "〖2:30 nachts〗〖7:30 morgens〗〖11:00 vorm.〗〖12:30 mittags〗〖3:30 nachm.〗〖9:00 abends〗"); + checkDayPeriodsForLocale("zh", "Bhm", "〖凌晨2:30〗〖早上6:30〗〖上午10:00〗〖中午12:30〗〖下午4:00〗〖晚上9:30〗"); checkDayPeriodsForLocale( - "zh", - "Bhm", - "〖凌晨2:30〗〖早上6:30〗〖上午10:00〗〖中午12:30〗〖下午4:00〗〖晚上9:30〗"); - checkDayPeriodsForLocale( - "am", - "EBhm", + "am", + "EBhm", "〖ሐሙስ በሌሊት 3:00〗〖ሐሙስ ጥዋት 9:00〗〖ሐሙስ ቀትር 12:00〗〖ሐሙስ ከሰዓት 3:00〗〖ሐሙስ በምሽት 9:00〗"); checkDayPeriodsForLocale( - "hi", - "EBhms", + "hi", + "EBhms", "〖गुरु रात 2:00:00〗〖गुरु सुबह 8:00:00〗〖गुरु दोपहर 2:00:00〗〖गुरु शाम 6:00:00〗"); } public void checkDayPeriodsForLocale(String localeId, String pattern, String expected) { ExampleGenerator exampleGenerator = getExampleGenerator(localeId); - String path = "//ldml/dates/calendars/calendar[@type=\"gregorian\"]" - + "/dateTimeFormats/availableFormats/dateFormatItem" - + "[@id=\"" + pattern + "\"]"; + String path = + "//ldml/dates/calendars/calendar[@type=\"gregorian\"]" + + "/dateTimeFormats/availableFormats/dateFormatItem" + + "[@id=\"" + + pattern + + "\"]"; String message = "Day periods with pattern \"" + pattern + "\""; checkValue(message, expected, exampleGenerator, path); }