diff --git a/icu4c/source/i18n/calendar.cpp b/icu4c/source/i18n/calendar.cpp index 0a02c33f0d85..7595f094e529 100644 --- a/icu4c/source/i18n/calendar.cpp +++ b/icu4c/source/i18n/calendar.cpp @@ -696,16 +696,13 @@ static const char gGregorian[] = "gregorian"; Calendar::Calendar(UErrorCode& success) : UObject(), -fIsTimeSet(false), -fAreFieldsSet(false), -fAreAllFieldsSet(false), -fAreFieldsVirtuallySet(false), -fNextStamp(kMinimumUserStamp), -fTime(0), -fLenient(true), -fZone(nullptr), -fRepeatedWallTime(UCAL_WALLTIME_LAST), -fSkippedWallTime(UCAL_WALLTIME_LAST) + fIsTimeSet(false), + fAreFieldsSet(false), + fAreAllFieldsSet(false), + fAreFieldsVirtuallySet(false), + fLenient(true), + fRepeatedWallTime(UCAL_WALLTIME_LAST), + fSkippedWallTime(UCAL_WALLTIME_LAST) { validLocale[0] = 0; actualLocale[0] = 0; @@ -724,16 +721,13 @@ fSkippedWallTime(UCAL_WALLTIME_LAST) Calendar::Calendar(TimeZone* zone, const Locale& aLocale, UErrorCode& success) : UObject(), -fIsTimeSet(false), -fAreFieldsSet(false), -fAreAllFieldsSet(false), -fAreFieldsVirtuallySet(false), -fNextStamp(kMinimumUserStamp), -fTime(0), -fLenient(true), -fZone(nullptr), -fRepeatedWallTime(UCAL_WALLTIME_LAST), -fSkippedWallTime(UCAL_WALLTIME_LAST) + fIsTimeSet(false), + fAreFieldsSet(false), + fAreAllFieldsSet(false), + fAreFieldsVirtuallySet(false), + fLenient(true), + fRepeatedWallTime(UCAL_WALLTIME_LAST), + fSkippedWallTime(UCAL_WALLTIME_LAST) { validLocale[0] = 0; actualLocale[0] = 0; @@ -759,16 +753,13 @@ fSkippedWallTime(UCAL_WALLTIME_LAST) Calendar::Calendar(const TimeZone& zone, const Locale& aLocale, UErrorCode& success) : UObject(), -fIsTimeSet(false), -fAreFieldsSet(false), -fAreAllFieldsSet(false), -fAreFieldsVirtuallySet(false), -fNextStamp(kMinimumUserStamp), -fTime(0), -fLenient(true), -fZone(nullptr), -fRepeatedWallTime(UCAL_WALLTIME_LAST), -fSkippedWallTime(UCAL_WALLTIME_LAST) + fIsTimeSet(false), + fAreFieldsSet(false), + fAreAllFieldsSet(false), + fAreFieldsVirtuallySet(false), + fLenient(true), + fRepeatedWallTime(UCAL_WALLTIME_LAST), + fSkippedWallTime(UCAL_WALLTIME_LAST) { validLocale[0] = 0; actualLocale[0] = 0; @@ -795,7 +786,6 @@ Calendar::~Calendar() Calendar::Calendar(const Calendar &source) : UObject(source) { - fZone = nullptr; *this = source; } @@ -4229,7 +4219,7 @@ Calendar::recalculateStamp() { int32_t currentValue; int32_t j, i; - fNextStamp = 1; + fNextStamp = kInternallySet; for (j = 0; j < UCAL_FIELD_COUNT; j++) { currentValue = STAMP_MAX; diff --git a/icu4c/source/i18n/unicode/calendar.h b/icu4c/source/i18n/unicode/calendar.h index 8a07c37b8925..5f688ab881fa 100644 --- a/icu4c/source/i18n/unicode/calendar.h +++ b/icu4c/source/i18n/unicode/calendar.h @@ -1881,38 +1881,6 @@ class U_I18N_API Calendar : public UObject { */ int32_t getActualHelper(UCalendarDateFields field, int32_t startValue, int32_t endValue, UErrorCode &status) const; - -private: - /** - * The flag which indicates if the current time is set in the calendar. - */ - UBool fIsTimeSet; - - /** - * True if the fields are in sync with the currently set time of this Calendar. - * If false, then the next attempt to get the value of a field will - * force a recomputation of all fields from the current value of the time - * field. - *

- * This should really be named areFieldsInSync, but the old name is retained - * for backward compatibility. - */ - UBool fAreFieldsSet; - - /** - * True if all of the fields have been set. This is initially false, and set to - * true by computeFields(). - */ - UBool fAreAllFieldsSet; - - /** - * True if all fields have been virtually set, but have not yet been - * computed. This occurs only in setTimeInMillis(). A calendar set - * to this state will compute all fields from the time if it becomes - * necessary, but otherwise will delay such computation. - */ - UBool fAreFieldsVirtuallySet; - protected: /** * Get the current time without recomputing. @@ -2169,7 +2137,7 @@ class U_I18N_API Calendar : public UObject { /** * The next available value for fStamp[] */ - int8_t fNextStamp;// = MINIMUM_USER_STAMP; + int8_t fNextStamp = kMinimumUserStamp; /** * Recalculates the time stamp array (fStamp). @@ -2180,30 +2148,60 @@ class U_I18N_API Calendar : public UObject { /** * The current time set for the calendar. */ - UDate fTime; + UDate fTime = 0; /** - * @see #setLenient + * Time zone affects the time calculation done by Calendar. Calendar subclasses use + * the time zone data to produce the local time. Always set; never nullptr. */ - UBool fLenient; + TimeZone* fZone = nullptr; /** - * Time zone affects the time calculation done by Calendar. Calendar subclasses use - * the time zone data to produce the local time. Always set; never nullptr. + * The flag which indicates if the current time is set in the calendar. + */ + bool fIsTimeSet:1; + + /** + * True if the fields are in sync with the currently set time of this Calendar. + * If false, then the next attempt to get the value of a field will + * force a recomputation of all fields from the current value of the time + * field. + *

+ * This should really be named areFieldsInSync, but the old name is retained + * for backward compatibility. + */ + bool fAreFieldsSet:1; + + /** + * True if all of the fields have been set. This is initially false, and set to + * true by computeFields(). + */ + bool fAreAllFieldsSet:1; + + /** + * True if all fields have been virtually set, but have not yet been + * computed. This occurs only in setTimeInMillis(). A calendar set + * to this state will compute all fields from the time if it becomes + * necessary, but otherwise will delay such computation. + */ + bool fAreFieldsVirtuallySet:1; + + /** + * @see #setLenient */ - TimeZone* fZone; + bool fLenient:1; /** * Option for repeated wall time * @see #setRepeatedWallTimeOption */ - UCalendarWallTimeOption fRepeatedWallTime; + UCalendarWallTimeOption fRepeatedWallTime:2; /** * Option for skipped wall time * @see #setSkippedWallTimeOption */ - UCalendarWallTimeOption fSkippedWallTime; + UCalendarWallTimeOption fSkippedWallTime:2; /** * Both firstDayOfWeek and minimalDaysInFirstWeek are locale-dependent. They are @@ -2213,11 +2211,11 @@ class U_I18N_API Calendar : public UObject { * out the week count for a specific date for a given locale. These must be set when * a Calendar is constructed. */ - UCalendarDaysOfWeek fFirstDayOfWeek; + UCalendarDaysOfWeek fFirstDayOfWeek:3; + UCalendarDaysOfWeek fWeekendOnset:3; + UCalendarDaysOfWeek fWeekendCease:3; uint8_t fMinimalDaysInFirstWeek; - UCalendarDaysOfWeek fWeekendOnset; int32_t fWeekendOnsetMillis; - UCalendarDaysOfWeek fWeekendCease; int32_t fWeekendCeaseMillis; /**