Skip to content

Commit 398b9cb

Browse files
committed
CLDR-17851 update ExampleGenerator and tests
- use new supplemental data info
1 parent 3038d14 commit 398b9cb

File tree

2 files changed

+43
-16
lines changed

2 files changed

+43
-16
lines changed

tools/cldr-code/src/main/java/org/unicode/cldr/test/ExampleGenerator.java

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3104,10 +3104,10 @@ private void handleDateRangePattern(String value, List<String> examples) {
31043104
private void handleEras(XPathParts parts, String value, List<String> examples) {
31053105
String calendarId = parts.getAttributeValue(3, "type");
31063106
String type = parts.getAttributeValue(-1, "type");
3107-
String id =
3108-
(calendarId.startsWith("islamic"))
3109-
? "islamic"
3110-
: calendarId; // islamic variations map to same sample
3107+
String id = calendarId;
3108+
if (id.equals("generic") || id.equals("iso8601")) {
3109+
id = "gregorian"; // use Gregorian eras, 'generic' is not in the data
3110+
}
31113111
final SupplementalCalendarData.CalendarData calendarData =
31123112
supplementalDataInfo.getCalendarData().get(id);
31133113

@@ -3123,21 +3123,48 @@ private void handleEras(XPathParts parts, String value, List<String> examples) {
31233123
GregorianCalendar startCal = forDateString(eraData.getStart());
31243124
GregorianCalendar endCal = forDateString(eraData.getEnd());
31253125

3126-
if (startCal == null && endCal == null) return; // no data
3126+
final SupplementalCalendarData.EraData prevEra = calendarData.get(typeIndex - 1);
3127+
final SupplementalCalendarData.EraData nextEra = calendarData.get(typeIndex + 1);
3128+
3129+
if (startCal == null && prevEra != null && prevEra.getEnd() != null) {
3130+
startCal = forDateString(prevEra.getEnd());
3131+
// shift forward so we are in the next era
3132+
startCal.setTimeInMillis(startCal.getTimeInMillis() + (DateConstants.MILLIS_PER_DAY));
3133+
}
3134+
if (endCal == null && nextEra != null && nextEra.getStart() != null) {
3135+
endCal = forDateString(nextEra.getStart());
3136+
// shift backward so we are in the prev era
3137+
endCal.setTimeInMillis(endCal.getTimeInMillis() - (DateConstants.MILLIS_PER_DAY));
3138+
}
3139+
3140+
GregorianCalendar sampleDate = null;
31273141

31283142
if (startCal != null && endCal != null) {
3129-
// go 2 days before end
3130-
endCal.roll(Calendar.JULIAN_DAY, -2);
3131-
if (endCal.before(startCal)) {
3132-
endCal = startCal;
3143+
// roll back a day to not hit the edge
3144+
sampleDate = endCal;
3145+
sampleDate.setTimeInMillis(
3146+
sampleDate.getTimeInMillis() - (DateConstants.MILLIS_PER_DAY));
3147+
} else if (startCal == null && endCal != null) {
3148+
// roll back a day to not hit the edge
3149+
sampleDate = endCal;
3150+
sampleDate.setTimeInMillis(
3151+
sampleDate.getTimeInMillis() - (DateConstants.MILLIS_PER_DAY));
3152+
} else if (startCal != null && endCal == null) {
3153+
sampleDate = forDateString("2002-07-15"); // CLDR repo root commit
3154+
if (sampleDate.before(startCal)) {
3155+
sampleDate = startCal;
3156+
sampleDate.setTimeInMillis(
3157+
sampleDate.getTimeInMillis() + (DateConstants.MILLIS_PER_DAY));
31333158
}
3134-
} else if (startCal == null) {
3135-
endCal.roll(Calendar.JULIAN_DAY, -2);
3136-
} else if (endCal == null) {
3137-
endCal = forDateString("2002-07-15"); // CLDR repo root commit
3159+
} else {
3160+
// System.err.println("No good date for " + eraData);
3161+
// TODO: should be an error in TestSupplementalDataInfo
3162+
sampleDate = null;
31383163
}
31393164

3140-
final Date sample = endCal.getTime();
3165+
if (sampleDate == null) return; // could not find the time
3166+
3167+
final Date sample = sampleDate.getTime();
31413168

31423169
String skeleton = "Gy";
31433170
String checkPath =

tools/cldr-code/src/test/java/org/unicode/cldr/unittest/TestExampleGenerator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,7 +1734,7 @@ public void TestEraFormats() {
17341734
ExampleGenerator exampleGeneratorZh = getExampleGenerator("zh");
17351735
checkValue(
17361736
"japanese type=235 abbreviated",
1737-
"〖平成1年〗",
1737+
"〖平成31年〗",
17381738
exampleGeneratorJa,
17391739
"//ldml/dates/calendars/calendar[@type=\"japanese\"]/eras/eraAbbr/era[@type=\"235\"]");
17401740
checkValue(
@@ -1749,7 +1749,7 @@ public void TestEraFormats() {
17491749
"//ldml/dates/calendars/calendar[@type=\"gregorian\"]/eras/eraNames/era[@type=\"0\"][@alt=\"variant\"]");
17501750
checkValue(
17511751
"roc type=1 abbreviated",
1752-
"〖民国1年〗",
1752+
"〖民国91年〗",
17531753
exampleGeneratorZh,
17541754
"//ldml/dates/calendars/calendar[@type=\"roc\"]/eras/eraAbbr/era[@type=\"1\"]");
17551755
}

0 commit comments

Comments
 (0)