Skip to content

Commit 1da4eb8

Browse files
committed
ICU-23108 Reenable tests
1 parent 8b8c166 commit 1da4eb8

5 files changed

Lines changed: 34 additions & 30 deletions

File tree

icu4c/source/i18n/erarules.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -329,11 +329,7 @@ int32_t EraRules::getEraCode(int32_t year, int32_t month, int32_t day, UErrorCod
329329
}
330330
}
331331
// Linear search from the end, which should hit the most likely eras first.
332-
// Also this is the most efficient for any era if we have < 8 or so eras, so only less
333-
// efficient for early eras in Japanese calendar (while we still have them). Formerly
334-
// this used binary search which would only be better for those early Japanese eras,
335-
// but now that is much more difficult since there may be holes in the sorted list.
336-
// Note with this change, this no longer uses or depends on currentEra.
332+
// Also this is the most efficient for any era if we have < 8 or so eras.
337333
for (int startIdx = startDatesLength; startIdx > 0;) {
338334
if (!isSet(startDates[--startIdx])) {
339335
continue;

icu4c/source/i18n/japancal.cpp

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

icu4c/source/i18n/japancal.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,12 @@ U_NAMESPACE_BEGIN
4545
* handles this distinction correctly when computing dates. However, in lenient
4646
* mode either form of date is acceptable as input.
4747
* <p>
48-
* In modern times, eras have started on January 8, 1868 AD, Gregorian (Meiji),
49-
* July 30, 1912 (Taisho), December 25, 1926 (Showa), and January 7, 1989 (Heisei). Constants
50-
* for these eras, suitable for use in the <code>UCAL_ERA</code> field, are provided
51-
* in this class. Note that the <em>number</em> used for each era is more or
52-
* less arbitrary. Currently, the era starting in 645 AD is era #0; however this
53-
* may change in the future. Use the predefined constants rather than using actual,
54-
* absolute numbers.
48+
* In modern times, eras have started on October 23, 1868 AD, Gregorian (Meiji),
49+
* July 30, 1912 (Taisho), December 25, 1926 (Showa), January 8, 1989 (Heisei), and
50+
* May 1, 2019 (Reiwa). Constants for these eras, suitable for use in the
51+
* <code>UCAL_ERA</code> field, are provided in this class. Note that the
52+
* <em>number</em> used for each era is more or less arbitrary. Use the predefined
53+
* constants rather than using actual, absolute numbers.
5554
* <p>
5655
* Since ICU4C 63, start date of each era is imported from CLDR. CLDR era data
5756
* may contain tentative era in near future with placeholder names. By default,
@@ -204,7 +203,7 @@ class JapaneseCalendar : public GregorianCalendar {
204203
*/
205204
virtual int32_t getDefaultDayInMonth(int32_t eyear, int32_t month, UErrorCode& status) override;
206205

207-
virtual bool isEra0CountingBackward() const override { return false; }
206+
virtual bool isEra0CountingBackward() const override { return true; }
208207
};
209208

210209
U_NAMESPACE_END

icu4c/source/test/cintltst/ccaltst.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2146,8 +2146,9 @@ static const EraTestItem eraTestItems[] = {
21462146
{ "en@calendar=gregorian", true },
21472147
{ "en@calendar=roc", true },
21482148
{ "en@calendar=coptic", true },
2149+
/* calendars with non-modern era 0 that goes backwards, max era > 1 */
2150+
{ "en@calendar=japanese", true },
21492151
/* calendars with non-modern era 0 that goes forwards, max era > 1 */
2150-
{ "en@calendar=japanese", false },
21512152
{ "en@calendar=chinese", false },
21522153
/* calendars with non-modern era 0 that goes forwards, max era == 1 */
21532154
{ "en@calendar=ethiopic", false },
@@ -2167,10 +2168,6 @@ static const UChar zoneGMT[] = { 0x47,0x4D,0x54,0 };
21672168
void TestAddRollEra0AndEraBounds(void) {
21682169
const EraTestItem * eraTestItemPtr;
21692170
for (eraTestItemPtr = eraTestItems; eraTestItemPtr->locale != NULL; eraTestItemPtr++) {
2170-
if (uprv_strstr(eraTestItemPtr->locale, "calendar=japanese") != NULL &&
2171-
log_knownIssue("ICU-23108", "ICU needs to implement era inheritance")) {
2172-
continue;
2173-
}
21742171
UErrorCode status = U_ZERO_ERROR;
21752172
UCalendar *ucalTest = ucal_open(zoneGMT, -1, eraTestItemPtr->locale, UCAL_DEFAULT, &status);
21762173
if ( U_SUCCESS(status) ) {

icu4c/source/test/intltest/incaltst.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ void IntlCalendarTest::TestJapaneseFormat() {
594594
status = U_ZERO_ERROR;
595595
simpleTest(loc, expect, expectDate, status);
596596
}
597-
if (!logKnownIssue("ICU-23108", "ICU needs to implement era inheritance")) {
597+
{
598598
UnicodeString expect = u"西暦1776年7月4日木曜日";
599599
UDate expectDate = -6106032422000.0; // 1776-07-04T00:00:00Z-075258
600600
Locale loc("ja_JP@calendar=japanese");
@@ -621,7 +621,7 @@ void IntlCalendarTest::TestJapaneseFormat() {
621621
simpleTest(loc, expect, expectDate, status);
622622

623623
}
624-
if (!logKnownIssue("ICU-23108", "ICU needs to implement era inheritance")) {
624+
{
625625
UnicodeString expect = u"西暦1456年2月29日日曜日";
626626
UDate expectDate = -16214400422000.0; // 1456-03-09T00:00Z-075258
627627
Locale loc("ja_JP@calendar=japanese");

0 commit comments

Comments
 (0)