From: Frank Tang Date: Thu, 22 Sep 2022 03:05:55 +0000 (-0700) Subject: ICU-22159 Merge inDaylightTime to Calendar X-Git-Tag: cldr/2022-12-02~16 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=294b26eb7aa2385a5232bb151320fa06e5266add;p=icu ICU-22159 Merge inDaylightTime to Calendar All the subclass implementation of inDaylightTime are the same so just move to a base class implementation. --- diff --git a/icu4c/source/i18n/calendar.cpp b/icu4c/source/i18n/calendar.cpp index 7b8b929990f..ffd84761bec 100644 --- a/icu4c/source/i18n/calendar.cpp +++ b/icu4c/source/i18n/calendar.cpp @@ -2869,7 +2869,20 @@ Calendar::getActualMinimum(UCalendarDateFields field, UErrorCode& status) const // ------------------------------------- +UBool +Calendar::inDaylightTime(UErrorCode& status) const +{ + if (U_FAILURE(status) || !getTimeZone().useDaylightTime()) { + return false; + } + // Force an update of the state of the Calendar. + ((Calendar*)this)->complete(status); // cast away const + + return (UBool)(U_SUCCESS(status) ? (internalGet(UCAL_DST_OFFSET) != 0) : false); +} + +// ------------------------------------- /** * Ensure that each field is within its valid range by calling {@link diff --git a/icu4c/source/i18n/cecal.cpp b/icu4c/source/i18n/cecal.cpp index 60e3d4b2657..2621056c497 100644 --- a/icu4c/source/i18n/cecal.cpp +++ b/icu4c/source/i18n/cecal.cpp @@ -86,19 +86,6 @@ CECalendar::handleGetLimit(UCalendarDateFields field, ELimitType limitType) cons return LIMITS[field][limitType]; } -UBool -CECalendar::inDaylightTime(UErrorCode& status) const -{ - if (U_FAILURE(status) || !getTimeZone().useDaylightTime()) { - return false; - } - - // Force an update of the state of the Calendar. - ((CECalendar*)this)->complete(status); // cast away const - - return (UBool)(U_SUCCESS(status) ? (internalGet(UCAL_DST_OFFSET) != 0) : false); -} - UBool CECalendar::haveDefaultCentury() const { diff --git a/icu4c/source/i18n/cecal.h b/icu4c/source/i18n/cecal.h index 9ac71f6ba38..711e2aa2526 100644 --- a/icu4c/source/i18n/cecal.h +++ b/icu4c/source/i18n/cecal.h @@ -76,17 +76,6 @@ protected: */ virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const override; - /** - * (Overrides Calendar) Return true if the current date for this Calendar is in - * Daylight Savings Time. Recognizes DST_OFFSET, if it is set. - * - * @param status Fill-in parameter which receives the status of this operation. - * @return True if the current date for this Calendar is in Daylight Savings Time, - * false, otherwise. - * @internal - */ - virtual UBool inDaylightTime(UErrorCode&) const override; - /** * Returns true because Coptic/Ethiopic Calendar does have a default century * @internal diff --git a/icu4c/source/i18n/chnsecal.cpp b/icu4c/source/i18n/chnsecal.cpp index e48c90eb5af..b2b6258820b 100644 --- a/icu4c/source/i18n/chnsecal.cpp +++ b/icu4c/source/i18n/chnsecal.cpp @@ -826,19 +826,6 @@ void ChineseCalendar::offsetMonth(int32_t newMoon, int32_t dom, int32_t delta) { } -UBool -ChineseCalendar::inDaylightTime(UErrorCode& status) const -{ - // copied from GregorianCalendar - if (U_FAILURE(status) || !getTimeZone().useDaylightTime()) - return false; - - // Force an update of the state of the Calendar. - ((ChineseCalendar*)this)->complete(status); // cast away const - - return (UBool)(U_SUCCESS(status) ? (internalGet(UCAL_DST_OFFSET) != 0) : false); -} - // default century static UDate gSystemDefaultCenturyStart = DBL_MIN; diff --git a/icu4c/source/i18n/chnsecal.h b/icu4c/source/i18n/chnsecal.h index 488fe169d99..016e9422e43 100644 --- a/icu4c/source/i18n/chnsecal.h +++ b/icu4c/source/i18n/chnsecal.h @@ -229,18 +229,6 @@ class U_I18N_API ChineseCalendar : public Calendar { protected: - /** - * (Overrides Calendar) Return true if the current date for this Calendar is in - * Daylight Savings Time. Recognizes DST_OFFSET, if it is set. - * - * @param status Fill-in parameter which receives the status of this operation. - * @return True if the current date for this Calendar is in Daylight Savings Time, - * false, otherwise. - * @internal - */ - virtual UBool inDaylightTime(UErrorCode& status) const override; - - /** * Returns true because the Islamic Calendar does have a default century * @internal diff --git a/icu4c/source/i18n/gregocal.cpp b/icu4c/source/i18n/gregocal.cpp index 63a6c2d4529..882d25b4a2a 100644 --- a/icu4c/source/i18n/gregocal.cpp +++ b/icu4c/source/i18n/gregocal.cpp @@ -1235,20 +1235,6 @@ int32_t GregorianCalendar::handleGetExtendedYearFromWeekFields(int32_t yearWoy, } -// ------------------------------------- - -UBool -GregorianCalendar::inDaylightTime(UErrorCode& status) const -{ - if (U_FAILURE(status) || !getTimeZone().useDaylightTime()) - return false; - - // Force an update of the state of the Calendar. - ((GregorianCalendar*)this)->complete(status); // cast away const - - return (UBool)(U_SUCCESS(status) ? (internalGet(UCAL_DST_OFFSET) != 0) : false); -} - // ------------------------------------- /** diff --git a/icu4c/source/i18n/hebrwcal.cpp b/icu4c/source/i18n/hebrwcal.cpp index 7e8da3eb2fb..07aea83f643 100644 --- a/icu4c/source/i18n/hebrwcal.cpp +++ b/icu4c/source/i18n/hebrwcal.cpp @@ -666,19 +666,6 @@ int32_t HebrewCalendar::handleComputeMonthStart(int32_t eyear, int32_t month, UB return (int) (day + 347997); } -UBool -HebrewCalendar::inDaylightTime(UErrorCode& status) const -{ - // copied from GregorianCalendar - if (U_FAILURE(status) || !getTimeZone().useDaylightTime()) - return false; - - // Force an update of the state of the Calendar. - ((HebrewCalendar*)this)->complete(status); // cast away const - - return (UBool)(U_SUCCESS(status) ? (internalGet(UCAL_DST_OFFSET) != 0) : false); -} - /** * The system maintains a static default century start date and Year. They are * initialized the first time they are used. Once the system default century date diff --git a/icu4c/source/i18n/hebrwcal.h b/icu4c/source/i18n/hebrwcal.h index d75651d47a4..34ce8c24c68 100644 --- a/icu4c/source/i18n/hebrwcal.h +++ b/icu4c/source/i18n/hebrwcal.h @@ -366,18 +366,6 @@ public: virtual void validateField(UCalendarDateFields field, UErrorCode &status) override; protected: - - /** - * (Overrides Calendar) Return true if the current date for this Calendar is in - * Daylight Savings Time. Recognizes DST_OFFSET, if it is set. - * - * @param status Fill-in parameter which receives the status of this operation. - * @return True if the current date for this Calendar is in Daylight Savings Time, - * false, otherwise. - * @internal - */ - virtual UBool inDaylightTime(UErrorCode& status) const override; - /** * Returns true because the Hebrew Calendar does have a default century * @internal diff --git a/icu4c/source/i18n/indiancal.cpp b/icu4c/source/i18n/indiancal.cpp index 24919e394f6..80d38ca9d42 100644 --- a/icu4c/source/i18n/indiancal.cpp +++ b/icu4c/source/i18n/indiancal.cpp @@ -297,21 +297,6 @@ void IndianCalendar::handleComputeFields(int32_t julianDay, UErrorCode& /* stat internalSet(UCAL_DAY_OF_YEAR, yday + 1); // yday is 0-based } -UBool -IndianCalendar::inDaylightTime(UErrorCode& status) const -{ - // copied from GregorianCalendar - if (U_FAILURE(status) || !getTimeZone().useDaylightTime()) { - return false; - } - - // Force an update of the state of the Calendar. - ((IndianCalendar*)this)->complete(status); // cast away const - - return (UBool)(U_SUCCESS(status) ? (internalGet(UCAL_DST_OFFSET) != 0) : false); -} - - /** * The system maintains a static default century start date and Year. They are * initialized the first time they are used. Once the system default century date diff --git a/icu4c/source/i18n/indiancal.h b/icu4c/source/i18n/indiancal.h index bfbea003295..e1c2f99295e 100644 --- a/icu4c/source/i18n/indiancal.h +++ b/icu4c/source/i18n/indiancal.h @@ -289,19 +289,6 @@ private: // Default century. protected: - - /** - * (Overrides Calendar) Return true if the current date for this Calendar is in - * Daylight Savings Time. Recognizes DST_OFFSET, if it is set. - * - * @param status Fill-in parameter which receives the status of this operation. - * @return True if the current date for this Calendar is in Daylight Savings Time, - * false, otherwise. - * @internal - */ - virtual UBool inDaylightTime(UErrorCode& status) const override; - - /** * Returns true because the Indian Calendar does have a default century * @internal diff --git a/icu4c/source/i18n/islamcal.cpp b/icu4c/source/i18n/islamcal.cpp index 916b4da2b64..5b920f46a70 100644 --- a/icu4c/source/i18n/islamcal.cpp +++ b/icu4c/source/i18n/islamcal.cpp @@ -692,19 +692,6 @@ void IslamicCalendar::handleComputeFields(int32_t julianDay, UErrorCode &status) internalSet(UCAL_DAY_OF_YEAR, dayOfYear); } -UBool -IslamicCalendar::inDaylightTime(UErrorCode& status) const -{ - // copied from GregorianCalendar - if (U_FAILURE(status) || !getTimeZone().useDaylightTime()) - return false; - - // Force an update of the state of the Calendar. - ((IslamicCalendar*)this)->complete(status); // cast away const - - return (UBool)(U_SUCCESS(status) ? (internalGet(UCAL_DST_OFFSET) != 0) : false); -} - /** * The system maintains a static default century start date and Year. They are * initialized the first time they are used. Once the system default century date diff --git a/icu4c/source/i18n/islamcal.h b/icu4c/source/i18n/islamcal.h index 7d9941d4709..9e84353e4b0 100644 --- a/icu4c/source/i18n/islamcal.h +++ b/icu4c/source/i18n/islamcal.h @@ -381,19 +381,6 @@ class U_I18N_API IslamicCalendar : public Calendar { // Default century. protected: - - /** - * (Overrides Calendar) Return true if the current date for this Calendar is in - * Daylight Savings Time. Recognizes DST_OFFSET, if it is set. - * - * @param status Fill-in parameter which receives the status of this operation. - * @return True if the current date for this Calendar is in Daylight Savings Time, - * false, otherwise. - * @internal - */ - virtual UBool inDaylightTime(UErrorCode& status) const override; - - /** * Returns true because the Islamic Calendar does have a default century * @internal diff --git a/icu4c/source/i18n/persncal.cpp b/icu4c/source/i18n/persncal.cpp index 9db47c98912..bdbe296d232 100644 --- a/icu4c/source/i18n/persncal.cpp +++ b/icu4c/source/i18n/persncal.cpp @@ -233,19 +233,6 @@ void PersianCalendar::handleComputeFields(int32_t julianDay, UErrorCode &/*statu internalSet(UCAL_DAY_OF_YEAR, dayOfYear); } -UBool -PersianCalendar::inDaylightTime(UErrorCode& status) const -{ - // copied from GregorianCalendar - if (U_FAILURE(status) || !getTimeZone().useDaylightTime()) - return false; - - // Force an update of the state of the Calendar. - ((PersianCalendar*)this)->complete(status); // cast away const - - return (UBool)(U_SUCCESS(status) ? (internalGet(UCAL_DST_OFFSET) != 0) : false); -} - // default century static UDate gSystemDefaultCenturyStart = DBL_MIN; diff --git a/icu4c/source/i18n/persncal.h b/icu4c/source/i18n/persncal.h index d0f2ee5ec20..5111e01e5a1 100644 --- a/icu4c/source/i18n/persncal.h +++ b/icu4c/source/i18n/persncal.h @@ -282,18 +282,6 @@ class PersianCalendar : public Calendar { PersianCalendar(); // default constructor not implemented protected: - - /** - * (Overrides Calendar) Return true if the current date for this Calendar is in - * Daylight Savings Time. Recognizes DST_OFFSET, if it is set. - * - * @param status Fill-in parameter which receives the status of this operation. - * @return True if the current date for this Calendar is in Daylight Savings Time, - * false, otherwise. - * @internal - */ - virtual UBool inDaylightTime(UErrorCode& status) const override; - /** * Returns true because the Persian Calendar does have a default century * @internal diff --git a/icu4c/source/i18n/unicode/calendar.h b/icu4c/source/i18n/unicode/calendar.h index 3c0e5c3e3e0..f7cca52106e 100644 --- a/icu4c/source/i18n/unicode/calendar.h +++ b/icu4c/source/i18n/unicode/calendar.h @@ -870,7 +870,7 @@ public: * false, otherwise. * @stable ICU 2.0 */ - virtual UBool inDaylightTime(UErrorCode& status) const = 0; + virtual UBool inDaylightTime(UErrorCode& status) const; /** * Specifies whether or not date/time interpretation is to be lenient. With lenient diff --git a/icu4c/source/i18n/unicode/gregocal.h b/icu4c/source/i18n/unicode/gregocal.h index d97b33b7aca..abd0debec68 100644 --- a/icu4c/source/i18n/unicode/gregocal.h +++ b/icu4c/source/i18n/unicode/gregocal.h @@ -423,17 +423,6 @@ public: */ virtual int32_t getActualMaximum(UCalendarDateFields field, UErrorCode& status) const override; - /** - * (Overrides Calendar) Return true if the current date for this Calendar is in - * Daylight Savings Time. Recognizes DST_OFFSET, if it is set. - * - * @param status Fill-in parameter which receives the status of this operation. - * @return True if the current date for this Calendar is in Daylight Savings Time, - * false, otherwise. - * @stable ICU 2.0 - */ - virtual UBool inDaylightTime(UErrorCode& status) const override; - public: /**