DO NOT MERGE Cherry-pick: ICU-20536 Japanese era Reiwa support in ICU4J 58
Partial cherry-pick https://github.com/unicode-org/icu/commit/913b5e8f5dbbe8ddca19c221f9867c00a9d84b94
- Exclude non-test files
Update android_icu4j by running tools/srcgen/generate_android_icu4j.sh
Bug: 138560701
Test: CtsIcuTestCases
Test: CtsLibcoreTestCases
Test: CtsLibcoreOjTestCases
Change-Id: If5d3468e5dbd2b90435f0b23528cbe3d3b4c42a8
diff --git a/android_icu4j/src/main/tests/android/icu/dev/data/testdata/format.res b/android_icu4j/src/main/tests/android/icu/dev/data/testdata/format.res
index 61e45b8..b6e62c2 100644
--- a/android_icu4j/src/main/tests/android/icu/dev/data/testdata/format.res
+++ b/android_icu4j/src/main/tests/android/icu/dev/data/testdata/format.res
Binary files differ
diff --git a/android_icu4j/src/main/tests/android/icu/dev/data/testdata/structLocale.res b/android_icu4j/src/main/tests/android/icu/dev/data/testdata/structLocale.res
index 38f0092..ce139dd 100644
--- a/android_icu4j/src/main/tests/android/icu/dev/data/testdata/structLocale.res
+++ b/android_icu4j/src/main/tests/android/icu/dev/data/testdata/structLocale.res
Binary files differ
diff --git a/android_icu4j/src/main/tests/android/icu/dev/test/calendar/JapaneseTest.java b/android_icu4j/src/main/tests/android/icu/dev/test/calendar/JapaneseTest.java
index eab03a0..a33c5e0 100644
--- a/android_icu4j/src/main/tests/android/icu/dev/test/calendar/JapaneseTest.java
+++ b/android_icu4j/src/main/tests/android/icu/dev/test/calendar/JapaneseTest.java
@@ -154,9 +154,9 @@
Calendar cal = new JapaneseCalendar(loc);
DateFormat enjformat = cal.getDateTimeFormat(0,0,new ULocale("en_JP@calendar=japanese"));
DateFormat format = cal.getDateTimeFormat(0,0,loc);
- ((SimpleDateFormat)format).applyPattern("y.M.d"); // Note: just 'y' doesn't work here.
+ ((SimpleDateFormat)format).applyPattern("y/M/d"); // Note: just 'y' doesn't work here.
ParsePosition pos = new ParsePosition(0);
- Date aDate = format.parse("1.1.9", pos); // after the start of heisei accession. Jan 1, 1H wouldn't work because it is actually showa 64
+ Date aDate = format.parse("1/5/9", pos); // after the start of Reiwa accession. Jan 1, R1 wouldn't work because it is actually Heisei 31
String inEn = enjformat.format(aDate);
cal.clear();
@@ -165,7 +165,7 @@
int gotEra = cal.get(Calendar.ERA);
int expectYear = 1;
- int expectEra = JapaneseCalendar.CURRENT_ERA;
+ int expectEra = JapaneseCalendar.CURRENT_ERA; // Reiwa
if((gotYear != expectYear) || (gotEra != expectEra)) {
errln("Expected year " + expectYear + ", era " + expectEra +", but got year " + gotYear + " and era " + gotEra + ", == " + inEn);
@@ -173,7 +173,7 @@
logln("Got year " + gotYear + " and era " + gotEra + ", == " + inEn);
}
- // Test parse with missing era (should default to current era, heisei)
+ // Test parse with missing era (should default to current era)
// Test parse with incomplete information
logln("Testing parse w/ just year...");
Calendar cal2 = new JapaneseCalendar(loc);
@@ -197,7 +197,7 @@
gotYear = cal2.get(Calendar.YEAR);
gotEra = cal2.get(Calendar.ERA);
expectYear = 1;
- expectEra = JapaneseCalendar.CURRENT_ERA;
+ expectEra = JapaneseCalendar.CURRENT_ERA; // Reiwa
if((gotYear != 1) || (gotEra != expectEra)) {
errln("parse "+ samplestr + " of 'y' as Japanese Calendar, expected year " + expectYear +
" and era " + expectEra + ", but got year " + gotYear + " and era " + gotEra + " (Gregorian:" + str +")");
@@ -379,5 +379,30 @@
doLimitsTest(jcal, null, cal.getTime());
doTheoreticalLimitsTest(jcal, true);
}
+
+ public void TestHeiseiToReiwa() {
+ Calendar cal = Calendar.getInstance();
+ cal.set(2019, Calendar.APRIL, 29);
+
+ DateFormat jfmt = DateFormat.getDateInstance(DateFormat.LONG, new ULocale("ja@calendar=japanese"));
+
+ final String[] EXPECTED_FORMAT = {
+ "\u5E73\u621031\u5E744\u670829\u65E5", // Heisei 31 April 29
+ "\u5E73\u621031\u5E744\u670830\u65E5", // Heisei 31 April 30
+ "\u4EE4\u548C1\u5E745\u67081\u65E5", // Reiwa 1 May 1
+ "\u4EE4\u548C1\u5E745\u67082\u65E5", // Reiwa 1 May 2
+ };
+
+ for (int i = 0; i < EXPECTED_FORMAT.length; i++) {
+ Date d = cal.getTime();
+ String dateStr = jfmt.format(d);
+ if (!EXPECTED_FORMAT[i].equals(dateStr)) {
+ errln("Formatting year:" + cal.get(Calendar.YEAR) + " month:" + (cal.get(Calendar.MONTH) + 1)
+ + " day:" + cal.get(Calendar.DATE) + " - expected: " + EXPECTED_FORMAT[i]
+ + " / actual: " + dateStr);
+ }
+ cal.add(Calendar.DATE, 1);
+ }
+ }
}
diff --git a/icu4j/main/shared/data/testdata.jar b/icu4j/main/shared/data/testdata.jar
index 4d74c9f..0147195 100755
--- a/icu4j/main/shared/data/testdata.jar
+++ b/icu4j/main/shared/data/testdata.jar
Binary files differ
diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/calendar/JapaneseTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/calendar/JapaneseTest.java
index 34f9595..6a79bf5 100644
--- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/calendar/JapaneseTest.java
+++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/calendar/JapaneseTest.java
@@ -151,9 +151,9 @@
Calendar cal = new JapaneseCalendar(loc);
DateFormat enjformat = cal.getDateTimeFormat(0,0,new ULocale("en_JP@calendar=japanese"));
DateFormat format = cal.getDateTimeFormat(0,0,loc);
- ((SimpleDateFormat)format).applyPattern("y.M.d"); // Note: just 'y' doesn't work here.
+ ((SimpleDateFormat)format).applyPattern("y/M/d"); // Note: just 'y' doesn't work here.
ParsePosition pos = new ParsePosition(0);
- Date aDate = format.parse("1.1.9", pos); // after the start of heisei accession. Jan 1, 1H wouldn't work because it is actually showa 64
+ Date aDate = format.parse("1/5/9", pos); // after the start of Reiwa accession. Jan 1, R1 wouldn't work because it is actually Heisei 31
String inEn = enjformat.format(aDate);
cal.clear();
@@ -162,7 +162,7 @@
int gotEra = cal.get(Calendar.ERA);
int expectYear = 1;
- int expectEra = JapaneseCalendar.CURRENT_ERA;
+ int expectEra = JapaneseCalendar.CURRENT_ERA; // Reiwa
if((gotYear != expectYear) || (gotEra != expectEra)) {
errln("Expected year " + expectYear + ", era " + expectEra +", but got year " + gotYear + " and era " + gotEra + ", == " + inEn);
@@ -170,7 +170,7 @@
logln("Got year " + gotYear + " and era " + gotEra + ", == " + inEn);
}
- // Test parse with missing era (should default to current era, heisei)
+ // Test parse with missing era (should default to current era)
// Test parse with incomplete information
logln("Testing parse w/ just year...");
Calendar cal2 = new JapaneseCalendar(loc);
@@ -194,7 +194,7 @@
gotYear = cal2.get(Calendar.YEAR);
gotEra = cal2.get(Calendar.ERA);
expectYear = 1;
- expectEra = JapaneseCalendar.CURRENT_ERA;
+ expectEra = JapaneseCalendar.CURRENT_ERA; // Reiwa
if((gotYear != 1) || (gotEra != expectEra)) {
errln("parse "+ samplestr + " of 'y' as Japanese Calendar, expected year " + expectYear +
" and era " + expectEra + ", but got year " + gotYear + " and era " + gotEra + " (Gregorian:" + str +")");
@@ -376,5 +376,30 @@
doLimitsTest(jcal, null, cal.getTime());
doTheoreticalLimitsTest(jcal, true);
}
+
+ public void TestHeiseiToReiwa() {
+ Calendar cal = Calendar.getInstance();
+ cal.set(2019, Calendar.APRIL, 29);
+
+ DateFormat jfmt = DateFormat.getDateInstance(DateFormat.LONG, new ULocale("ja@calendar=japanese"));
+
+ final String[] EXPECTED_FORMAT = {
+ "\u5E73\u621031\u5E744\u670829\u65E5", // Heisei 31 April 29
+ "\u5E73\u621031\u5E744\u670830\u65E5", // Heisei 31 April 30
+ "\u4EE4\u548C1\u5E745\u67081\u65E5", // Reiwa 1 May 1
+ "\u4EE4\u548C1\u5E745\u67082\u65E5", // Reiwa 1 May 2
+ };
+
+ for (int i = 0; i < EXPECTED_FORMAT.length; i++) {
+ Date d = cal.getTime();
+ String dateStr = jfmt.format(d);
+ if (!EXPECTED_FORMAT[i].equals(dateStr)) {
+ errln("Formatting year:" + cal.get(Calendar.YEAR) + " month:" + (cal.get(Calendar.MONTH) + 1)
+ + " day:" + cal.get(Calendar.DATE) + " - expected: " + EXPECTED_FORMAT[i]
+ + " / actual: " + dateStr);
+ }
+ cal.add(Calendar.DATE, 1);
+ }
+ }
}