From d60148df867f389338e603711ae96ecfd15f7944 Mon Sep 17 00:00:00 2001 From: Frank Tang Date: Fri, 13 Dec 2024 10:22:53 -0800 Subject: [PATCH] ICU-22991 Remove protected direct access to fStamp --- icu4c/source/i18n/chnsecal.cpp | 4 +++- icu4c/source/i18n/gregocal.cpp | 8 ++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/icu4c/source/i18n/chnsecal.cpp b/icu4c/source/i18n/chnsecal.cpp index 050994fcbaf6..fb8e5191c524 100644 --- a/icu4c/source/i18n/chnsecal.cpp +++ b/icu4c/source/i18n/chnsecal.cpp @@ -219,7 +219,9 @@ int32_t ChineseCalendar::handleGetExtendedYear(UErrorCode& status) { } int32_t year; - if (newestStamp(UCAL_ERA, UCAL_YEAR, kUnset) <= fStamp[UCAL_EXTENDED_YEAR]) { + // if UCAL_EXTENDED_YEAR is not older than UCAL_ERA nor UCAL_YEAR + if (newerField(UCAL_EXTENDED_YEAR, newerField(UCAL_ERA, UCAL_YEAR)) == + UCAL_EXTENDED_YEAR) { year = internalGet(UCAL_EXTENDED_YEAR, 1); // Default to year 1 } else { // adjust to the instance specific epoch diff --git a/icu4c/source/i18n/gregocal.cpp b/icu4c/source/i18n/gregocal.cpp index 23366c7ab7a3..0c09faf3f2ff 100644 --- a/icu4c/source/i18n/gregocal.cpp +++ b/icu4c/source/i18n/gregocal.cpp @@ -1186,14 +1186,10 @@ int32_t GregorianCalendar::handleGetExtendedYear(UErrorCode& status) { int32_t year = kEpochYear; // year field to use - int32_t yearField = UCAL_EXTENDED_YEAR; - // There are three separate fields which could be used to // derive the proper year. Use the one most recently set. - if (fStamp[yearField] < fStamp[UCAL_YEAR]) - yearField = UCAL_YEAR; - if (fStamp[yearField] < fStamp[UCAL_YEAR_WOY]) - yearField = UCAL_YEAR_WOY; + UCalendarDateFields yearField = newerField( + newerField(UCAL_EXTENDED_YEAR, UCAL_YEAR), UCAL_YEAR_WOY); // based on the "best" year field, get the year switch(yearField) {