Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions icu4c/source/test/intltest/caltest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ void CalendarTest::runIndexedTest( int32_t index, UBool exec, const char* &name,
TESTCASE_AUTO(TestAddOverflow);

TESTCASE_AUTO(Test22750Roll);
TESTCASE_AUTO(Test23101ExtendedYear);

TESTCASE_AUTO(TestChineseCalendarComputeMonthStart);
TESTCASE_AUTO(Test22962MonthAddOneOverflow);
Expand Down Expand Up @@ -6148,6 +6149,42 @@ void CalendarTest::Test22750Roll() {
}
}

void CalendarTest::Test23101ExtendedYear() {
IcuTestErrorCode status(*this, "Test23101ExtendedYear");

static const struct TestCase {
const char* calendarName;
const char16_t* expectedExtendedYear20250101;
const char16_t* expectedExtendedYear20250701;
} testCases[] = {
{ "gregory", u"2025", u"2025" },
{ "chinese", u"4661", u"4662" },
{ "dangi", u"4357", u"4358" },
{ "japanese", u"2025", u"2025" },
{ "ethiopic", u"2017", u"2017" },
{ "ethiopic-amete-alem", u"2017", u"2017" },
};

const UDate date20250101 = (UDate) 1735689600000;
const UDate date20250701 = (UDate) 1751328000000;

for (const TestCase& testCase : testCases) {
Locale locale;
locale.setKeywordValue("calendar", testCase.calendarName, status);
if (status.errIfFailureAndReset()) { return; }
LocalPointer<Calendar> cal(Calendar::createInstance(
*TimeZone::getGMT(), locale, status));
SimpleDateFormat formatter(u"u", Locale::getRoot(), status);
if (status.errIfFailureAndReset()) { return; }
formatter.setCalendar(*cal);
UnicodeString actual20250101, actual20250701;
formatter.format(date20250101, actual20250101);
formatter.format(date20250701, actual20250701);
assertEquals("2025-01-01", testCase.expectedExtendedYear20250101, actual20250101);
assertEquals("2025-07-01", testCase.expectedExtendedYear20250701, actual20250701);
}
}

#endif /* #if !UCONFIG_NO_FORMATTING */

//eof
2 changes: 2 additions & 0 deletions icu4c/source/test/intltest/caltest.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ class CalendarTest: public CalendarTimeZoneTest {

void Test22750Roll();

void Test23101ExtendedYear();

void RunTestOnCalendars(void(TestFunc)(Calendar*, UCalendarDateFields));

void verifyFirstDayOfWeek(const char* locale, UCalendarDaysOfWeek expected);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ protected void handleComputeFields(int julianDay) {
MonthInfo info = computeMonthInfo(days, gyear);

// Extended year and cycle year is based on the epoch year
int extended_year = gyear - epochYear;
int extended_year = gyear - 1;
int cycle_year = gyear - CHINESE_EPOCH_YEAR;
if (info.month < 10 ||
gmonth >= JULY) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2746,5 +2746,39 @@ public void TestMaxActualLimitsWithoutGet23006() {
30, actualMaximumBeforeCallingGet);

}

@Test
public void Test23101ExtendedYear() {
String[][] testCases = {
{ "gregory", "2025", "2025", "2025" },
{ "chinese", "2024", "2025", "2025" },
{ "dangi", "2024", "2025", "2025" },
{ "japanese", "2025", "2025", "2025" },
{ "ethiopic", "2017", "2017", "2018" },
{ "ethiopic-amete-alem", "2017", "2017", "2018" },
};

long date20250101 = 1735689600000l;
long date20250701 = 1751328000000l;
long date20251231 = 1767139200000l;

for (String[] testCase : testCases) {
String calendarName = testCase[0];
String expectedExtendedYear20250101 = testCase[1];
String expectedExtendedYear20250701 = testCase[2];
String expectedExtendedYear20251231 = testCase[3];

ULocale locale = ULocale.forLanguageTag("und-u-ca-" + calendarName);
Calendar cal = Calendar.getInstance(TimeZone.GMT_ZONE, locale);
SimpleDateFormat formatter = new SimpleDateFormat("u", ULocale.ROOT);
formatter.setCalendar(cal);
String actual20250101 = formatter.format(date20250101);
String actual20250701 = formatter.format(date20250701);
String actual20251231 = formatter.format(date20251231);
assertEquals("2025-01-01 in " + calendarName, expectedExtendedYear20250101, actual20250101);
assertEquals("2025-07-01 in " + calendarName, expectedExtendedYear20250701, actual20250701);
assertEquals("2025-12-31 in " + calendarName, expectedExtendedYear20251231, actual20251231);
}
}
}
//eof
Loading