Skip to content

Commit 79f8249

Browse files
committed
ICU-20536 Japanese era Reiwa support in ICU4J 52
1 parent e6db21d commit 79f8249

File tree

5 files changed

+39
-13
lines changed

5 files changed

+39
-13
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:3b2727b9cec70230b0eba1cc0af7a1ea31d9e7562e0885a2192f96aa1ce40804
3-
size 10942996
2+
oid sha256:178438dae9a672db7339fdfed07f0c693b91c77605ca9f027907a53cd7de9296
3+
size 10993637
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:897e6fa37ac41c3ff835d475803fe01369e8ebc39d12211e2f662fc5abea0d01
3-
size 726436
2+
oid sha256:6282cbe83b50464de8508852153458d4716bb2c39a26c2f42c0aa510b6e45a81
3+
size 726431

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

Lines changed: 29 additions & 4 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 heisei accession. Jan 1, 1R wouldn't work because it is actually showa 64
154154
String inEn = enjformat.format(aDate);
155155

156156
cal.clear();
@@ -159,7 +159,7 @@ 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);
@@ -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-2013, 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)