@@ -149,6 +149,10 @@ int32_t JapaneseCalendar::getDefaultMonthInYear(int32_t eyear, UErrorCode& statu
149149
150150 int32_t month = 0 ;
151151
152+ if (era <= 1 ) {
153+ return month;
154+ }
155+
152156 // Find out if we are at the edge of an era
153157 int32_t eraStart[3 ] = { 0 ,0 ,0 };
154158 gJapaneseEraRules ->getStartDate (era, eraStart, status);
@@ -172,6 +176,10 @@ int32_t JapaneseCalendar::getDefaultDayInMonth(int32_t eyear, int32_t month, UEr
172176 int32_t era = internalGetEra ();
173177 int32_t day = 1 ;
174178
179+ if (era <= 1 ) {
180+ return day;
181+ }
182+
175183 int32_t eraStart[3 ] = { 0 ,0 ,0 };
176184 gJapaneseEraRules ->getStartDate (era, eraStart, status);
177185 if (U_FAILURE (status)) {
@@ -194,14 +202,16 @@ int32_t JapaneseCalendar::handleGetExtendedYear(UErrorCode& status)
194202 if (U_FAILURE (status)) {
195203 return 0 ;
196204 }
205+
206+ int32_t era = internalGet (UCAL_ERA , gCurrentEra );
197207 // EXTENDED_YEAR in JapaneseCalendar is a Gregorian year
198208 // The default value of EXTENDED_YEAR is 1970 (Showa 45)
199209
200- if (newerField (UCAL_EXTENDED_YEAR , UCAL_YEAR ) == UCAL_EXTENDED_YEAR &&
201- newerField (UCAL_EXTENDED_YEAR , UCAL_ERA ) == UCAL_EXTENDED_YEAR ) {
210+ if (( newerField (UCAL_EXTENDED_YEAR , UCAL_YEAR ) == UCAL_EXTENDED_YEAR &&
211+ newerField (UCAL_EXTENDED_YEAR , UCAL_ERA ) == UCAL_EXTENDED_YEAR ) || era <= 1 ) {
202212 return internalGet (UCAL_EXTENDED_YEAR , kGregorianEpoch );
203213 }
204- int32_t eraStartYear = gJapaneseEraRules ->getStartYear (internalGet ( UCAL_ERA , gCurrentEra ) , status);
214+ int32_t eraStartYear = gJapaneseEraRules ->getStartYear (era , status);
205215 if (U_FAILURE (status)) {
206216 return 0 ;
207217 }
@@ -224,13 +234,15 @@ void JapaneseCalendar::handleComputeFields(int32_t julianDay, UErrorCode& status
224234 int32_t year = internalGet (UCAL_EXTENDED_YEAR ); // Gregorian year
225235 int32_t eraCode = gJapaneseEraRules ->getEraCode (year, internalGetMonth (status) + 1 , internalGet (UCAL_DAY_OF_MONTH ), status);
226236
227- int32_t startYear = gJapaneseEraRules ->getStartYear (eraCode, status) - 1 ;
228- if (U_FAILURE (status)) {
229- return ;
230- }
231- if (uprv_add32_overflow (year, -startYear, &year)) {
232- status = U_ILLEGAL_ARGUMENT_ERROR ;
233- return ;
237+ if (year > 0 ) {
238+ int32_t startYear = gJapaneseEraRules ->getStartYear (eraCode, status) - 1 ;
239+ if (U_FAILURE (status)) {
240+ return ;
241+ }
242+ if (uprv_add32_overflow (year, -startYear, &year)) {
243+ status = U_ILLEGAL_ARGUMENT_ERROR ;
244+ return ;
245+ }
234246 }
235247 internalSet (UCAL_ERA , eraCode);
236248 internalSet (UCAL_YEAR , year);
0 commit comments