Skip to content

Commit bde9eee

Browse files
committed
ICU-20536 Japanese era Reiwa support in ICU4J 53
1 parent ee8c0a2 commit bde9eee

File tree

5 files changed

+40
-14
lines changed

5 files changed

+40
-14
lines changed

icu4j/main/classes/core/src/com/ibm/icu/util/JapaneseCalendar.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,7 @@ protected void handleComputeFields(int julianDay) {
560560
1912, 7, 30, // Taisho
561561
1926, 12, 25, // Showa
562562
1989, 1, 8, // Heisei
563+
2019, 5, 1, // Reiwa
563564
};
564565

565566
//-------------------------------------------------------------------------
@@ -576,25 +577,25 @@ protected void handleComputeFields(int julianDay) {
576577
* Constant for the era starting on Sept. 8, 1868 AD.
577578
* @stable ICU 2.8
578579
*/
579-
static public final int MEIJI = CURRENT_ERA - 3;
580+
static public final int MEIJI = CURRENT_ERA - 4;
580581

581582
/**
582583
* Constant for the era starting on July 30, 1912 AD.
583584
* @stable ICU 2.8
584585
*/
585-
static public final int TAISHO = CURRENT_ERA - 2;
586+
static public final int TAISHO = CURRENT_ERA - 3;
586587

587588
/**
588589
* Constant for the era starting on Dec. 25, 1926 AD.
589590
* @stable ICU 2.8
590591
*/
591-
static public final int SHOWA = CURRENT_ERA - 1;
592+
static public final int SHOWA = CURRENT_ERA - 2;
592593

593594
/**
594595
* Constant for the era starting on Jan. 7, 1989 AD.
595596
* @stable ICU 2.8
596597
*/
597-
static public final int HEISEI = CURRENT_ERA;
598+
static public final int HEISEI = CURRENT_ERA - 1;
598599

599600
/**
600601
* Override GregorianCalendar. We should really handle YEAR_WOY and

icu4j/main/shared/data/icudata.jar

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:7e28ec897adf45879e984e846f7434f35156c24851e6e570709dc14d88bdd89a
3-
size 10158705
2+
oid sha256:9cb378e2459f851b64b900b49afbc32302813c596ab65f841f3f93d58be58f7e
3+
size 10158846
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
version https://git-lfs.github.com/spec/v1
2-
oid sha256:132762b7f41c03ded7d8d115d461e72a34806bc0bff62cfde3111acbfda8159b
3-
size 719353
2+
oid sha256:9eb5e370346e1f4c36d1e20d89e7cb228aa30c2372d4051ad143653e79cade40
3+
size 719320

icu4j/main/tests/core/src/com/ibm/icu/dev/test/calendar/JapaneseTest.java

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,9 @@ public void Test3860()
148148
Calendar cal = new JapaneseCalendar(loc);
149149
DateFormat enjformat = cal.getDateTimeFormat(0,0,new ULocale("en_JP@calendar=japanese"));
150150
DateFormat format = cal.getDateTimeFormat(0,0,loc);
151-
((SimpleDateFormat)format).applyPattern("y.M.d"); // Note: just 'y' doesn't work here.
151+
((SimpleDateFormat)format).applyPattern("y/M/d"); // Note: just 'y' doesn't work here.
152152
ParsePosition pos = new ParsePosition(0);
153-
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
153+
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
154154
String inEn = enjformat.format(aDate);
155155

156156
cal.clear();
@@ -159,15 +159,15 @@ public void Test3860()
159159
int gotEra = cal.get(Calendar.ERA);
160160

161161
int expectYear = 1;
162-
int expectEra = JapaneseCalendar.CURRENT_ERA;
162+
int expectEra = JapaneseCalendar.CURRENT_ERA; // Reiwa
163163

164164
if((gotYear != expectYear) || (gotEra != expectEra)) {
165165
errln("Expected year " + expectYear + ", era " + expectEra +", but got year " + gotYear + " and era " + gotEra + ", == " + inEn);
166166
} else {
167167
logln("Got year " + gotYear + " and era " + gotEra + ", == " + inEn);
168168
}
169169

170-
// Test parse with missing era (should default to current era, heisei)
170+
// Test parse with missing era (should default to current era)
171171
// Test parse with incomplete information
172172
logln("Testing parse w/ just year...");
173173
Calendar cal2 = new JapaneseCalendar(loc);
@@ -191,7 +191,7 @@ public void Test3860()
191191
gotYear = cal2.get(Calendar.YEAR);
192192
gotEra = cal2.get(Calendar.ERA);
193193
expectYear = 1;
194-
expectEra = JapaneseCalendar.CURRENT_ERA;
194+
expectEra = JapaneseCalendar.CURRENT_ERA; // Reiwa
195195
if((gotYear != 1) || (gotEra != expectEra)) {
196196
errln("parse "+ samplestr + " of 'y' as Japanese Calendar, expected year " + expectYear +
197197
" and era " + expectEra + ", but got year " + gotYear + " and era " + gotEra + " (Gregorian:" + str +")");
@@ -370,5 +370,30 @@ public void TestLimits() {
370370
doLimitsTest(jcal, null, cal.getTime());
371371
doTheoreticalLimitsTest(jcal, true);
372372
}
373+
374+
public void TestHeiseiToReiwa() {
375+
Calendar cal = Calendar.getInstance();
376+
cal.set(2019, Calendar.APRIL, 29);
377+
378+
DateFormat jfmt = DateFormat.getDateInstance(DateFormat.LONG, new ULocale("ja@calendar=japanese"));
379+
380+
final String[] EXPECTED_FORMAT = {
381+
"\u5E73\u621031\u5E744\u670829\u65E5", // Heisei 31 April 29
382+
"\u5E73\u621031\u5E744\u670830\u65E5", // Heisei 31 April 30
383+
"\u4EE4\u548C1\u5E745\u67081\u65E5", // Reiwa 1 May 1
384+
"\u4EE4\u548C1\u5E745\u67082\u65E5", // Reiwa 1 May 2
385+
};
386+
387+
for (int i = 0; i < EXPECTED_FORMAT.length; i++) {
388+
Date d = cal.getTime();
389+
String dateStr = jfmt.format(d);
390+
if (!EXPECTED_FORMAT[i].equals(dateStr)) {
391+
errln("Formatting year:" + cal.get(Calendar.YEAR) + " month:" + (cal.get(Calendar.MONTH) + 1)
392+
+ " day:" + cal.get(Calendar.DATE) + " - expected: " + EXPECTED_FORMAT[i]
393+
+ " / actual: " + dateStr);
394+
}
395+
cal.add(Calendar.DATE, 1);
396+
}
397+
}
373398
}
374399

icu4j/main/tests/core/src/com/ibm/icu/dev/test/util/DebugUtilitiesData.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/** Copyright (C) 2007-2014, International Business Machines Corporation and Others. All Rights Reserved. **/
1+
/** Copyright (C) 2007-2019, International Business Machines Corporation and Others. All Rights Reserved. **/
22

33
/* NOTE: this file is AUTOMATICALLY GENERATED by gentest.
44
* See: {ICU4C}/source/data/icu4j-readme.txt for more information.

0 commit comments

Comments
 (0)