ICU-20536 Japanese era Reiwa support in ICU4J 55

This commit is contained in:
yumaoka 2019-04-05 14:57:59 -04:00 committed by Yoshito Umaoka
parent f826dc8f93
commit 548155b72a
5 changed files with 39 additions and 13 deletions

View file

@ -560,6 +560,7 @@ public class JapaneseCalendar extends GregorianCalendar {
1912, 7, 30, // Taisho
1926, 12, 25, // Showa
1989, 1, 8, // Heisei
2019, 5, 1, // Reiwa
};
//-------------------------------------------------------------------------
@ -576,25 +577,25 @@ public class JapaneseCalendar extends GregorianCalendar {
* Constant for the era starting on Sept. 8, 1868 AD.
* @stable ICU 2.8
*/
static public final int MEIJI = CURRENT_ERA - 3;
static public final int MEIJI = CURRENT_ERA - 4;
/**
* Constant for the era starting on July 30, 1912 AD.
* @stable ICU 2.8
*/
static public final int TAISHO = CURRENT_ERA - 2;
static public final int TAISHO = CURRENT_ERA - 3;
/**
* Constant for the era starting on Dec. 25, 1926 AD.
* @stable ICU 2.8
*/
static public final int SHOWA = CURRENT_ERA - 1;
static public final int SHOWA = CURRENT_ERA - 2;
/**
* Constant for the era starting on Jan. 7, 1989 AD.
* @stable ICU 2.8
*/
static public final int HEISEI = CURRENT_ERA;
static public final int HEISEI = CURRENT_ERA - 1;
/**
* Override GregorianCalendar. We should really handle YEAR_WOY and

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:3d908f3e3c78898225932228d32ecf77de3454c3a27a081474faf5a8e7d22f7e
size 11844585
oid sha256:c72c4140b7675989a62286b573cc139e1228f83a799934d38c293eb8ef568563
size 11844833

View file

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:4682b21253c779a47c5fb00f3e38b9d3f2d832b3ae1afe71112e2355aa95d971
size 812503
oid sha256:a5cd9099835f41a0b8a72a6f789ed8862ad81c84cc697a2c1bd3623747d7c97f
size 812478

View file

@ -148,9 +148,9 @@ public class JapaneseTest extends CalendarTest {
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();
@ -159,7 +159,7 @@ public class JapaneseTest extends CalendarTest {
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);
@ -167,7 +167,7 @@ public class JapaneseTest extends CalendarTest {
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);
@ -370,5 +370,30 @@ public class JapaneseTest extends CalendarTest {
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);
}
}
}

View file

@ -1,4 +1,4 @@
/** Copyright (C) 2007-2015, International Business Machines Corporation and Others. All Rights Reserved. **/
/** Copyright (C) 2007-2019, International Business Machines Corporation and Others. All Rights Reserved. **/
/* NOTE: this file is AUTOMATICALLY GENERATED by gentest.
* See: {ICU4C}/source/data/icu4j-readme.txt for more information.