commit 03bce8a97e74fba96fa316f460c23e087ea192a0
parent cb03592107ea8ccf52ece21f3bc14f5ebf0dd492
Author: André Bargull <andre.bargull@gmail.com>
Date: Tue, 25 Nov 2025 15:19:41 +0000
Bug 2000225 - Part 18: Change extended-year for ICU4XChineseBasedCalendar to related ISO year. r=platform-i18n-reviewers,dminor
ICU 78 changed the extended year of Chinese/Dangi calendars to the related
Gregorian year. Apply the same changes for `ICU4XChineseBasedCalendar` for
consistency.
This also makes it easier to update ICU4X (bug 1997048).
Differential Revision: https://phabricator.services.mozilla.com/D273827
Diffstat:
4 files changed, 12 insertions(+), 35 deletions(-)
diff --git a/intl/components/src/calendar/ICU4XChineseBasedCalendar.cpp b/intl/components/src/calendar/ICU4XChineseBasedCalendar.cpp
@@ -61,18 +61,6 @@ bool ICU4XChineseBasedCalendar::inTemporalLeapYear(UErrorCode& status) const {
return days > (monthsInNonLeapYear * maxDaysInMonth);
}
-int32_t ICU4XChineseBasedCalendar::getRelatedYear(UErrorCode& status) const {
- int32_t year = get(UCAL_EXTENDED_YEAR, status);
- if (U_FAILURE(status)) {
- return 0;
- }
- return year + relatedYearDifference();
-}
-
-void ICU4XChineseBasedCalendar::setRelatedYear(int32_t year) {
- set(UCAL_EXTENDED_YEAR, year - relatedYearDifference());
-}
-
void ICU4XChineseBasedCalendar::handleComputeFields(int32_t julianDay,
UErrorCode& status) {
int32_t gyear = getGregorianYear();
@@ -96,7 +84,8 @@ void ICU4XChineseBasedCalendar::handleComputeFields(int32_t julianDay,
MOZ_ASSERT(date);
MonthCode monthCode = monthCodeFrom(date.get());
- int32_t extendedYear = icu4x::capi::icu4x_Date_extended_year_mv1(date.get());
+ int32_t extendedYear =
+ icu4x::capi::icu4x_Date_era_year_or_related_iso_mv1(date.get());
int32_t month = icu4x::capi::icu4x_Date_ordinal_month_mv1(date.get());
int32_t dayOfMonth = icu4x::capi::icu4x_Date_day_of_month_mv1(date.get());
int32_t dayOfYear = icu4x::capi::icu4x_Date_day_of_year_mv1(date.get());
@@ -105,11 +94,18 @@ void ICU4XChineseBasedCalendar::handleComputeFields(int32_t julianDay,
MOZ_ASSERT(1 <= dayOfMonth && dayOfMonth <= 30);
MOZ_ASSERT(1 <= dayOfYear && dayOfYear <= (13 * 30));
+ // Difference between the Chinese calendar era (the extended year 1) and the
+ // start year used for cycle computations. This is the sixtieth year of reign
+ // of Huáng Dì. Other sources use the first year of reign, which means using
+ // -2697 instead. Both numbers result in the same year of cycle, but the
+ // latter number gives a different cycle number. To align with the ICU4C
+ // Chinese calendar implementation, we use -2637 here.
+ constexpr int32_t chineseCalendarYearDiff = -2637;
+
// Compute the cycle and year of cycle relative to the Chinese calendar, even
// when this is the Dangi calendar.
- int32_t chineseExtendedYear =
- extendedYear + relatedYearDifference() - chineseRelatedYearDiff;
- int32_t cycle_year = chineseExtendedYear - 1;
+ int32_t chineseCalendarYear = extendedYear - chineseCalendarYearDiff;
+ int32_t cycle_year = chineseCalendarYear - 1;
int32_t cycle = FloorDiv(cycle_year, 60);
int32_t yearOfCycle = cycle_year - (cycle * 60);
diff --git a/intl/components/src/calendar/ICU4XChineseBasedCalendar.h b/intl/components/src/calendar/ICU4XChineseBasedCalendar.h
@@ -35,17 +35,8 @@ class ICU4XChineseBasedCalendar : public ICU4XCalendar {
bool requiresFallbackForExtendedYear(int32_t year) const override;
bool requiresFallbackForGregorianYear(int32_t year) const override;
- /**
- * Difference to the related Gregorian year.
- */
- virtual int32_t relatedYearDifference() const = 0;
-
- static constexpr int32_t chineseRelatedYearDiff = -2637;
-
public:
bool inTemporalLeapYear(UErrorCode& status) const override;
- int32_t getRelatedYear(UErrorCode& status) const override;
- void setRelatedYear(int32_t year) override;
protected:
void handleComputeFields(int32_t julianDay, UErrorCode& status) override;
diff --git a/intl/components/src/calendar/ICU4XChineseCalendar.h b/intl/components/src/calendar/ICU4XChineseCalendar.h
@@ -36,10 +36,6 @@ class ICU4XChineseCalendar : public ICU4XChineseBasedCalendar {
protected:
std::string_view eraName(int32_t extendedYear) const override;
- int32_t relatedYearDifference() const override {
- return chineseRelatedYearDiff;
- }
-
public:
UClassID getDynamicClassID() const override;
static UClassID U_EXPORT2 getStaticClassID();
diff --git a/intl/components/src/calendar/ICU4XDangiCalendar.h b/intl/components/src/calendar/ICU4XDangiCalendar.h
@@ -36,12 +36,6 @@ class ICU4XDangiCalendar : public ICU4XChineseBasedCalendar {
protected:
std::string_view eraName(int32_t extendedYear) const override;
- static constexpr int32_t dangiRelatedYearDiff = -2333;
-
- int32_t relatedYearDifference() const override {
- return dangiRelatedYearDiff;
- }
-
public:
UClassID getDynamicClassID() const override;
static UClassID U_EXPORT2 getStaticClassID();