@@ -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 \u6210 31\u5E74 4\u6708 29\u65E5 " , // Heisei 31 April 29
382+ "\u5E73 \u6210 31\u5E74 4\u6708 30\u65E5 " , // Heisei 31 April 30
383+ "\u4EE4 \u548C 1\u5E74 5\u6708 1\u65E5 " , // Reiwa 1 May 1
384+ "\u4EE4 \u548C 1\u5E74 5\u6708 2\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
0 commit comments