tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

calendar.h (113121B)


      1 // © 2016 and later: Unicode, Inc. and others.
      2 // License & terms of use: http://www.unicode.org/copyright.html
      3 /*
      4 ********************************************************************************
      5 *   Copyright (C) 1997-2014, International Business Machines
      6 *   Corporation and others.  All Rights Reserved.
      7 ********************************************************************************
      8 *
      9 * File CALENDAR.H
     10 *
     11 * Modification History:
     12 *
     13 *   Date        Name        Description
     14 *   04/22/97    aliu        Expanded and corrected comments and other header
     15 *                           contents.
     16 *   05/01/97    aliu        Made equals(), before(), after() arguments const.
     17 *   05/20/97    aliu        Replaced fAreFieldsSet with fAreFieldsInSync and
     18 *                           fAreAllFieldsSet.
     19 *   07/27/98    stephen     Sync up with JDK 1.2
     20 *   11/15/99    weiv        added YEAR_WOY and DOW_LOCAL
     21 *                           to EDateFields
     22 *    8/19/2002  srl         Removed Javaisms
     23 *   11/07/2003  srl         Update, clean up documentation.
     24 ********************************************************************************
     25 */
     26 
     27 #ifndef CALENDAR_H
     28 #define CALENDAR_H
     29 
     30 #include "unicode/utypes.h"
     31 
     32 #if U_SHOW_CPLUSPLUS_API
     33 
     34 /**
     35 * \file
     36 * \brief C++ API: Calendar object
     37 */
     38 #if !UCONFIG_NO_FORMATTING
     39 
     40 #include "unicode/uobject.h"
     41 #include "unicode/locid.h"
     42 #include "unicode/timezone.h"
     43 #include "unicode/ucal.h"
     44 #include "unicode/umisc.h"
     45 
     46 U_NAMESPACE_BEGIN
     47 
     48 class ICUServiceFactory;
     49 
     50 // Do not conditionalize the following with #ifndef U_HIDE_INTERNAL_API,
     51 // it is a return type for a virtual method (@internal)
     52 /**
     53 * @internal
     54 */
     55 typedef int32_t UFieldResolutionTable[12][8];
     56 
     57 class BasicTimeZone;
     58 /**
     59 * `Calendar` is an abstract base class for converting between
     60 * a `UDate` object and a set of integer fields such as
     61 * `YEAR`, `MONTH`, `DAY`, `HOUR`, and so on.
     62 * (A `UDate` object represents a specific instant in
     63 * time with millisecond precision. See UDate
     64 * for information about the `UDate` class.)
     65 *
     66 * Subclasses of `Calendar` interpret a `UDate`
     67 * according to the rules of a specific calendar system.
     68 * The most commonly used subclass of `Calendar` is
     69 * `GregorianCalendar`. Other subclasses could represent
     70 * the various types of lunar calendars in use in many parts of the world.
     71 *
     72 * **NOTE**: (ICU 2.6) The subclass interface should be considered unstable -
     73 * it WILL change.
     74 *
     75 * Like other locale-sensitive classes, `Calendar` provides a
     76 * static method, `createInstance`, for getting a generally useful
     77 * object of this type. `Calendar`'s `createInstance` method
     78 * returns the appropriate `Calendar` subclass whose
     79 * time fields have been initialized with the current date and time:
     80 *
     81 *     Calendar *rightNow = Calendar::createInstance(errCode);
     82 *
     83 * A `Calendar` object can produce all the time field values
     84 * needed to implement the date-time formatting for a particular language
     85 * and calendar style (for example, Japanese-Gregorian, Japanese-Traditional).
     86 *
     87 * When computing a `UDate` from time fields, some special circumstances
     88 * may arise: there may be insufficient information to compute the
     89 * `UDate` (such as only year and month but no day in the month),
     90 * there may be inconsistent information (such as "Tuesday, July 15, 1996"
     91 * -- July 15, 1996 is actually a Monday), or the input time might be ambiguous
     92 * because of time zone transition.
     93 *
     94 * **Insufficient information.** The calendar will use default
     95 * information to specify the missing fields. This may vary by calendar; for
     96 * the Gregorian calendar, the default for a field is the same as that of the
     97 * start of the epoch: i.e., YEAR = 1970, MONTH = JANUARY, DATE = 1, etc.
     98 *
     99 * **Inconsistent information.** If fields conflict, the calendar
    100 * will give preference to fields set more recently. For example, when
    101 * determining the day, the calendar will look for one of the following
    102 * combinations of fields.  The most recent combination, as determined by the
    103 * most recently set single field, will be used.
    104 *
    105 *     MONTH + DAY_OF_MONTH
    106 *     MONTH + WEEK_OF_MONTH + DAY_OF_WEEK
    107 *     MONTH + DAY_OF_WEEK_IN_MONTH + DAY_OF_WEEK
    108 *     DAY_OF_YEAR
    109 *     DAY_OF_WEEK + WEEK_OF_YEAR
    110 *
    111 * For the time of day:
    112 *
    113 *     HOUR_OF_DAY
    114 *     AM_PM + HOUR
    115 *
    116 * **Ambiguous Wall Clock Time.** When time offset from UTC has
    117 * changed, it produces an ambiguous time slot around the transition. For example,
    118 * many US locations observe daylight saving time. On the date switching to daylight
    119 * saving time in US, wall clock time jumps from 12:59 AM (standard) to 2:00 AM
    120 * (daylight). Therefore, wall clock time from 1:00 AM to 1:59 AM do not exist on
    121 * the date. When the input wall time fall into this missing time slot, the ICU
    122 * Calendar resolves the time using the UTC offset before the transition by default.
    123 * In this example, 1:30 AM is interpreted as 1:30 AM standard time (non-exist),
    124 * so the final result will be 2:30 AM daylight time.
    125 *
    126 * On the date switching back to standard time, wall clock time is moved back one
    127 * hour at 2:00 AM. So wall clock time from 1:00 AM to 1:59 AM occur twice. In this
    128 * case, the ICU Calendar resolves the time using the UTC offset after the transition
    129 * by default. For example, 1:30 AM on the date is resolved as 1:30 AM standard time.
    130 *
    131 * Ambiguous wall clock time resolution behaviors can be customized by Calendar APIs
    132 * {@link #setRepeatedWallTimeOption} and {@link #setSkippedWallTimeOption}.
    133 * These methods are available in ICU 49 or later versions.
    134 *
    135 * **Note:** for some non-Gregorian calendars, different
    136 * fields may be necessary for complete disambiguation. For example, a full
    137 * specification of the historical Arabic astronomical calendar requires year,
    138 * month, day-of-month *and* day-of-week in some cases.
    139 *
    140 * **Note:** There are certain possible ambiguities in
    141 * interpretation of certain singular times, which are resolved in the
    142 * following ways:
    143 *
    144 *   1. 24:00:00 "belongs" to the following day. That is,
    145 *      23:59 on Dec 31, 1969 < 24:00 on Jan 1, 1970 < 24:01:00 on Jan 1, 1970
    146 *   2. Although historically not precise, midnight also belongs to "am",
    147 *      and noon belongs to "pm", so on the same day,
    148 *      12:00 am (midnight) < 12:01 am, and 12:00 pm (noon) < 12:01 pm
    149 *
    150 * The date or time format strings are not part of the definition of a
    151 * calendar, as those must be modifiable or overridable by the user at
    152 * runtime. Use `DateFormat` to format dates.
    153 *
    154 * `Calendar` provides an API for field "rolling", where fields
    155 * can be incremented or decremented, but wrap around. For example, rolling the
    156 * month up in the date December 12, **1996** results in
    157 * January 12, **1996**.
    158 *
    159 * `Calendar` also provides a date arithmetic function for
    160 * adding the specified (signed) amount of time to a particular time field.
    161 * For example, subtracting 5 days from the date `September 12, 1996`
    162 * results in `September 7, 1996`.
    163 *
    164 * ***Supported range***
    165 *
    166 * The allowable range of `Calendar` has been narrowed. `GregorianCalendar` used
    167 * to attempt to support the range of dates with millisecond values from
    168 * `Long.MIN_VALUE` to `Long.MAX_VALUE`. The new `Calendar` protocol specifies the
    169 * maximum range of supportable dates as those having Julian day numbers
    170 * of `-0x7F000000` to `+0x7F000000`. This corresponds to years from ~5,800,000 BCE
    171 * to ~5,800,000 CE. Programmers should use the protected constants in `Calendar` to
    172 * specify an extremely early or extremely late date.
    173 *
    174 * <p>
    175 * The Japanese calendar uses a combination of era name and year number.
    176 * When an emperor of Japan abdicates and a new emperor ascends the throne,
    177 * a new era is declared and year number is reset to 1. Even if the date of
    178 * abdication is scheduled ahead of time, the new era name might not be
    179 * announced until just before the date. In such case, ICU4C may include
    180 * a start date of future era without actual era name, but not enabled
    181 * by default. ICU4C users who want to test the behavior of the future era
    182 * can enable the tentative era by:
    183 * <ul>
    184 * <li>Environment variable <code>ICU_ENABLE_TENTATIVE_ERA=true</code>.</li>
    185 * </ul>
    186 *
    187 * @stable ICU 2.0
    188 */
    189 class U_I18N_API_CLASS Calendar : public UObject {
    190 public:
    191 #ifndef U_FORCE_HIDE_DEPRECATED_API
    192    /**
    193     * Field IDs for date and time. Used to specify date/time fields. ERA is calendar
    194     * specific. Example ranges given are for illustration only; see specific Calendar
    195     * subclasses for actual ranges.
    196     * @deprecated ICU 2.6. Use C enum UCalendarDateFields defined in ucal.h
    197     */
    198    enum EDateFields {
    199 #ifndef U_HIDE_DEPRECATED_API
    200 /*
    201 * ERA may be defined on other platforms. To avoid any potential problems undefined it here.
    202 */
    203 #ifdef ERA
    204 #undef ERA
    205 #endif
    206        ERA,                  // Example: 0..1
    207        YEAR,                 // Example: 1..big number
    208        MONTH,                // Example: 0..11
    209        WEEK_OF_YEAR,         // Example: 1..53
    210        WEEK_OF_MONTH,        // Example: 1..4
    211        DATE,                 // Example: 1..31
    212        DAY_OF_YEAR,          // Example: 1..365
    213        DAY_OF_WEEK,          // Example: 1..7
    214        DAY_OF_WEEK_IN_MONTH, // Example: 1..4, may be specified as -1
    215        AM_PM,                // Example: 0..1
    216        HOUR,                 // Example: 0..11
    217        HOUR_OF_DAY,          // Example: 0..23
    218        MINUTE,               // Example: 0..59
    219        SECOND,               // Example: 0..59
    220        MILLISECOND,          // Example: 0..999
    221        ZONE_OFFSET,          // Example: -12*U_MILLIS_PER_HOUR..12*U_MILLIS_PER_HOUR
    222        DST_OFFSET,           // Example: 0 or U_MILLIS_PER_HOUR
    223        YEAR_WOY,             // 'Y' Example: 1..big number - Year of Week of Year
    224        DOW_LOCAL,            // 'e' Example: 1..7 - Day of Week / Localized
    225 
    226        EXTENDED_YEAR,
    227        JULIAN_DAY,
    228        MILLISECONDS_IN_DAY,
    229        IS_LEAP_MONTH,
    230 
    231        FIELD_COUNT = UCAL_FIELD_COUNT // See ucal.h for other fields.
    232 #endif /* U_HIDE_DEPRECATED_API */
    233    };
    234 #endif  // U_FORCE_HIDE_DEPRECATED_API
    235 
    236 #ifndef U_HIDE_DEPRECATED_API
    237    /**
    238     * Useful constant for days of week. Note: Calendar day-of-week is 1-based. Clients
    239     * who create locale resources for the field of first-day-of-week should be aware of
    240     * this. For instance, in US locale, first-day-of-week is set to 1, i.e., SUNDAY.
    241     * @deprecated ICU 2.6. Use C enum UCalendarDaysOfWeek defined in ucal.h
    242     */
    243    enum EDaysOfWeek {
    244        SUNDAY = 1,
    245        MONDAY,
    246        TUESDAY,
    247        WEDNESDAY,
    248        THURSDAY,
    249        FRIDAY,
    250        SATURDAY
    251    };
    252 
    253    /**
    254     * Useful constants for month. Note: Calendar month is 0-based.
    255     * @deprecated ICU 2.6. Use C enum UCalendarMonths defined in ucal.h
    256     */
    257    enum EMonths {
    258        JANUARY,
    259        FEBRUARY,
    260        MARCH,
    261        APRIL,
    262        MAY,
    263        JUNE,
    264        JULY,
    265        AUGUST,
    266        SEPTEMBER,
    267        OCTOBER,
    268        NOVEMBER,
    269        DECEMBER,
    270        UNDECIMBER
    271    };
    272 
    273    /**
    274     * Useful constants for hour in 12-hour clock. Used in GregorianCalendar.
    275     * @deprecated ICU 2.6. Use C enum UCalendarAMPMs defined in ucal.h
    276     */
    277    enum EAmpm {
    278        AM,
    279        PM
    280    };
    281 #endif  /* U_HIDE_DEPRECATED_API */
    282 
    283    /**
    284     * destructor
    285     * @stable ICU 2.0
    286     */
    287    U_I18N_API virtual ~Calendar();
    288 
    289    /**
    290     * Create and return a polymorphic copy of this calendar.
    291     *
    292     * @return    a polymorphic copy of this calendar.
    293     * @stable ICU 2.0
    294     */
    295    U_I18N_API virtual Calendar* clone() const = 0;
    296 
    297    /**
    298     * Creates a Calendar using the default timezone and locale. Clients are responsible
    299     * for deleting the object returned.
    300     *
    301     * @param success  Indicates the success/failure of Calendar creation. Filled in
    302     *                 with U_ZERO_ERROR if created successfully, set to a failure result
    303     *                 otherwise. U_MISSING_RESOURCE_ERROR will be returned if the resource data
    304     *                 requests a calendar type which has not been installed.
    305     * @return         A Calendar if created successfully. nullptr otherwise.
    306     * @stable ICU 2.0
    307     */
    308    U_I18N_API static Calendar* U_EXPORT2 createInstance(UErrorCode& success);
    309 
    310    /**
    311     * Creates a Calendar using the given timezone and the default locale.
    312     * The Calendar takes ownership of zoneToAdopt; the
    313     * client must not delete it.
    314     *
    315     * @param zoneToAdopt  The given timezone to be adopted.
    316     * @param success      Indicates the success/failure of Calendar creation. Filled in
    317     *                     with U_ZERO_ERROR if created successfully, set to a failure result
    318     *                     otherwise.
    319     * @return             A Calendar if created successfully. nullptr otherwise.
    320     * @stable ICU 2.0
    321     */
    322    U_I18N_API static Calendar* U_EXPORT2 createInstance(TimeZone* zoneToAdopt, UErrorCode& success);
    323 
    324    /**
    325     * Creates a Calendar using the given timezone and the default locale.  The TimeZone
    326     * is _not_ adopted; the client is still responsible for deleting it.
    327     *
    328     * @param zone  The timezone.
    329     * @param success      Indicates the success/failure of Calendar creation. Filled in
    330     *                     with U_ZERO_ERROR if created successfully, set to a failure result
    331     *                     otherwise.
    332     * @return             A Calendar if created successfully. nullptr otherwise.
    333     * @stable ICU 2.0
    334     */
    335    U_I18N_API static Calendar* U_EXPORT2 createInstance(const TimeZone& zone, UErrorCode& success);
    336 
    337    /**
    338     * Creates a Calendar using the default timezone and the given locale.
    339     *
    340     * @param aLocale  The given locale.
    341     * @param success  Indicates the success/failure of Calendar creation. Filled in
    342     *                 with U_ZERO_ERROR if created successfully, set to a failure result
    343     *                 otherwise.
    344     * @return         A Calendar if created successfully. nullptr otherwise.
    345     * @stable ICU 2.0
    346     */
    347    U_I18N_API static Calendar* U_EXPORT2 createInstance(const Locale& aLocale, UErrorCode& success);
    348 
    349    /**
    350     * Creates a Calendar using the given timezone and given locale.
    351     * The Calendar takes ownership of zoneToAdopt; the
    352     * client must not delete it.
    353     *
    354     * @param zoneToAdopt  The given timezone to be adopted.
    355     * @param aLocale      The given locale.
    356     * @param success      Indicates the success/failure of Calendar creation. Filled in
    357     *                     with U_ZERO_ERROR if created successfully, set to a failure result
    358     *                     otherwise.
    359     * @return             A Calendar if created successfully. nullptr otherwise.
    360     * @stable ICU 2.0
    361     */
    362    U_I18N_API static Calendar* U_EXPORT2 createInstance(TimeZone* zoneToAdopt,
    363                                                         const Locale& aLocale,
    364                                                         UErrorCode& success);
    365 
    366    /**
    367     * Gets a Calendar using the given timezone and given locale.  The TimeZone
    368     * is _not_ adopted; the client is still responsible for deleting it.
    369     *
    370     * @param zone         The given timezone.
    371     * @param aLocale      The given locale.
    372     * @param success      Indicates the success/failure of Calendar creation. Filled in
    373     *                     with U_ZERO_ERROR if created successfully, set to a failure result
    374     *                     otherwise.
    375     * @return             A Calendar if created successfully. nullptr otherwise.
    376     * @stable ICU 2.0
    377     */
    378    U_I18N_API static Calendar* U_EXPORT2 createInstance(const TimeZone& zone,
    379                                                         const Locale& aLocale,
    380                                                         UErrorCode& success);
    381 
    382    /**
    383     * Returns a list of the locales for which Calendars are installed.
    384     *
    385     * @param count  Number of locales returned.
    386     * @return       An array of Locale objects representing the set of locales for which
    387     *               Calendars are installed.  The system retains ownership of this list;
    388     *               the caller must NOT delete it. Does not include user-registered Calendars.
    389     * @stable ICU 2.0
    390     */
    391    U_I18N_API static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
    392 
    393    /**
    394     * Given a key and a locale, returns an array of string values in a preferred
    395     * order that would make a difference. These are all and only those values where
    396     * the open (creation) of the service with the locale formed from the input locale
    397     * plus input keyword and that value has different behavior than creation with the
    398     * input locale alone.
    399     * @param key           one of the keys supported by this service.  For now, only
    400     *                      "calendar" is supported.
    401     * @param locale        the locale
    402     * @param commonlyUsed  if set to true it will return only commonly used values
    403     *                      with the given locale in preferred order.  Otherwise,
    404     *                      it will return all the available values for the locale.
    405     * @param status        ICU Error Code
    406     * @return a string enumeration over keyword values for the given key and the locale.
    407     * @stable ICU 4.2
    408     */
    409    U_I18N_API static StringEnumeration* U_EXPORT2 getKeywordValuesForLocale(const char* key,
    410                                                                             const Locale& locale,
    411                                                                             UBool commonlyUsed,
    412                                                                             UErrorCode& status);
    413 
    414    /**
    415     * Returns the current UTC (GMT) time measured in milliseconds since 0:00:00 on 1/1/70
    416     * (derived from the system time).
    417     *
    418     * @return   The current UTC time in milliseconds.
    419     * @stable ICU 2.0
    420     */
    421    U_I18N_API static UDate U_EXPORT2 getNow();
    422 
    423    /**
    424     * Gets this Calendar's time as milliseconds. May involve recalculation of time due
    425     * to previous calls to set time field values. The time specified is non-local UTC
    426     * (GMT) time. Although this method is const, this object may actually be changed
    427     * (semantically const).
    428     *
    429     * @param status  Output param set to success/failure code on exit. If any value
    430     *                previously set in the time field is invalid or restricted by
    431     *                leniency, this will be set to an error status.
    432     * @return        The current time in UTC (GMT) time, or zero if the operation
    433     *                failed.
    434     * @stable ICU 2.0
    435     */
    436    U_I18N_API inline UDate getTime(UErrorCode& status) const { return getTimeInMillis(status); }
    437 
    438    /**
    439     * Sets this Calendar's current time with the given UDate. The time specified should
    440     * be in non-local UTC (GMT) time.
    441     *
    442     * @param date  The given UDate in UTC (GMT) time.
    443     * @param status  Output param set to success/failure code on exit. If any value
    444     *                set in the time field is invalid or restricted by
    445     *                leniency, this will be set to an error status.
    446     * @stable ICU 2.0
    447     */
    448    U_I18N_API inline void setTime(UDate date, UErrorCode& status) { setTimeInMillis(date, status); }
    449 
    450    /**
    451     * Compares the equality of two Calendar objects. Objects of different subclasses
    452     * are considered unequal. This comparison is very exacting; two Calendar objects
    453     * must be in exactly the same state to be considered equal. To compare based on the
    454     * represented time, use equals() instead.
    455     *
    456     * @param that  The Calendar object to be compared with.
    457     * @return      true if the given Calendar is the same as this Calendar; false
    458     *              otherwise.
    459     * @stable ICU 2.0
    460     */
    461    U_I18N_API virtual bool operator==(const Calendar& that) const;
    462 
    463    /**
    464     * Compares the inequality of two Calendar objects.
    465     *
    466     * @param that  The Calendar object to be compared with.
    467     * @return      true if the given Calendar is not the same as this Calendar; false
    468     *              otherwise.
    469     * @stable ICU 2.0
    470     */
    471    U_I18N_API bool operator!=(const Calendar& that) const { return !operator==(that); }
    472 
    473    /**
    474     * Returns true if the given Calendar object is equivalent to this
    475     * one.  An equivalent Calendar will behave exactly as this one
    476     * does, but it may be set to a different time.  By contrast, for
    477     * the operator==() method to return true, the other Calendar must
    478     * be set to the same time.
    479     *
    480     * @param other the Calendar to be compared with this Calendar
    481     * @stable ICU 2.4
    482     */
    483    U_I18N_API virtual UBool isEquivalentTo(const Calendar& other) const;
    484 
    485    /**
    486     * Compares the Calendar time, whereas Calendar::operator== compares the equality of
    487     * Calendar objects.
    488     *
    489     * @param when    The Calendar to be compared with this Calendar. Although this is a
    490     *                const parameter, the object may be modified physically
    491     *                (semantically const).
    492     * @param status  Output param set to success/failure code on exit. If any value
    493     *                previously set in the time field is invalid or restricted by
    494     *                leniency, this will be set to an error status.
    495     * @return        True if the current time of this Calendar is equal to the time of
    496     *                Calendar when; false otherwise.
    497     * @stable ICU 2.0
    498     */
    499    U_I18N_API UBool equals(const Calendar& when, UErrorCode& status) const;
    500 
    501    /**
    502     * Returns true if this Calendar's current time is before "when"'s current time.
    503     *
    504     * @param when    The Calendar to be compared with this Calendar. Although this is a
    505     *                const parameter, the object may be modified physically
    506     *                (semantically const).
    507     * @param status  Output param set to success/failure code on exit. If any value
    508     *                previously set in the time field is invalid or restricted by
    509     *                leniency, this will be set to an error status.
    510     * @return        True if the current time of this Calendar is before the time of
    511     *                Calendar when; false otherwise.
    512     * @stable ICU 2.0
    513     */
    514    U_I18N_API UBool before(const Calendar& when, UErrorCode& status) const;
    515 
    516    /**
    517     * Returns true if this Calendar's current time is after "when"'s current time.
    518     *
    519     * @param when    The Calendar to be compared with this Calendar. Although this is a
    520     *                const parameter, the object may be modified physically
    521     *                (semantically const).
    522     * @param status  Output param set to success/failure code on exit. If any value
    523     *                previously set in the time field is invalid or restricted by
    524     *                leniency, this will be set to an error status.
    525     * @return        True if the current time of this Calendar is after the time of
    526     *                Calendar when; false otherwise.
    527     * @stable ICU 2.0
    528     */
    529    U_I18N_API UBool after(const Calendar& when, UErrorCode& status) const;
    530 
    531 #ifndef U_FORCE_HIDE_DEPRECATED_API
    532    /**
    533     * UDate Arithmetic function. Adds the specified (signed) amount of time to the given
    534     * time field, based on the calendar's rules. For example, to subtract 5 days from
    535     * the current time of the calendar, call add(Calendar::DATE, -5). When adding on
    536     * the month or Calendar::MONTH field, other fields like date might conflict and
    537     * need to be changed. For instance, adding 1 month on the date 01/31/96 will result
    538     * in 02/29/96.
    539     * Adding a positive value always means moving forward in time, so for the Gregorian calendar,
    540     * starting with 100 BC and adding +1 to year results in 99 BC (even though this actually reduces
    541     * the numeric value of the field itself).
    542     *
    543     * @param field   Specifies which date field to modify.
    544     * @param amount  The amount of time to be added to the field, in the natural unit
    545     *                for that field (e.g., days for the day fields, hours for the hour
    546     *                field.)
    547     * @param status  Output param set to success/failure code on exit. If any value
    548     *                previously set in the time field is invalid or restricted by
    549     *                leniency, this will be set to an error status.
    550     * @deprecated ICU 2.6. use add(UCalendarDateFields field, int32_t amount, UErrorCode& status) instead.
    551     */
    552    U_I18N_API virtual void add(EDateFields field, int32_t amount, UErrorCode& status);
    553 #endif  // U_FORCE_HIDE_DEPRECATED_API
    554 
    555    /**
    556     * UDate Arithmetic function. Adds the specified (signed) amount of time to the given
    557     * time field, based on the calendar's rules. For example, to subtract 5 days from
    558     * the current time of the calendar, call add(Calendar::DATE, -5). When adding on
    559     * the month or Calendar::MONTH field, other fields like date might conflict and
    560     * need to be changed. For instance, adding 1 month on the date 01/31/96 will result
    561     * in 02/29/96.
    562     * Adding a positive value always means moving forward in time, so for the Gregorian calendar,
    563     * starting with 100 BC and adding +1 to year results in 99 BC (even though this actually reduces
    564     * the numeric value of the field itself).
    565     *
    566     * @param field   Specifies which date field to modify.
    567     * @param amount  The amount of time to be added to the field, in the natural unit
    568     *                for that field (e.g., days for the day fields, hours for the hour
    569     *                field.)
    570     * @param status  Output param set to success/failure code on exit. If any value
    571     *                previously set in the time field is invalid or restricted by
    572     *                leniency, this will be set to an error status.
    573     * @stable ICU 2.6.
    574     */
    575    U_I18N_API virtual void add(UCalendarDateFields field, int32_t amount, UErrorCode& status);
    576 
    577 #ifndef U_HIDE_DEPRECATED_API
    578    /**
    579     * Time Field Rolling function. Rolls (up/down) a single unit of time on the given
    580     * time field. For example, to roll the current date up by one day, call
    581     * roll(Calendar::DATE, true). When rolling on the year or Calendar::YEAR field, it
    582     * will roll the year value in the range between getMinimum(Calendar::YEAR) and the
    583     * value returned by getMaximum(Calendar::YEAR). When rolling on the month or
    584     * Calendar::MONTH field, other fields like date might conflict and, need to be
    585     * changed. For instance, rolling the month up on the date 01/31/96 will result in
    586     * 02/29/96. Rolling up always means rolling forward in time (unless the limit of the
    587     * field is reached, in which case it may pin or wrap), so for Gregorian calendar,
    588     * starting with 100 BC and rolling the year up results in 99 BC.
    589     * When eras have a definite beginning and end (as in the Chinese calendar, or as in
    590     * most eras in the Japanese calendar) then rolling the year past either limit of the
    591     * era will cause the year to wrap around. When eras only have a limit at one end,
    592     * then attempting to roll the year past that limit will result in pinning the year
    593     * at that limit. Note that for most calendars in which era 0 years move forward in
    594     * time (such as Buddhist, Hebrew, or Islamic), it is possible for add or roll to
    595     * result in negative years for era 0 (that is the only way to represent years before
    596     * the calendar epoch).
    597     * When rolling on the hour-in-day or Calendar::HOUR_OF_DAY field, it will roll the
    598     * hour value in the range between 0 and 23, which is zero-based.
    599     * <P>
    600     * NOTE: Do not use this method -- use roll(EDateFields, int, UErrorCode&) instead.
    601     *
    602     * @param field   The time field.
    603     * @param up      Indicates if the value of the specified time field is to be rolled
    604     *                up or rolled down. Use true if rolling up, false otherwise.
    605     * @param status  Output param set to success/failure code on exit. If any value
    606     *                previously set in the time field is invalid or restricted by
    607     *                leniency, this will be set to an error status.
    608     * @deprecated ICU 2.6. Use roll(UCalendarDateFields field, UBool up, UErrorCode& status) instead.
    609     */
    610    U_I18N_API inline void roll(EDateFields field, UBool up, UErrorCode& status);
    611 #endif  /* U_HIDE_DEPRECATED_API */
    612 
    613    /**
    614     * Time Field Rolling function. Rolls (up/down) a single unit of time on the given
    615     * time field. For example, to roll the current date up by one day, call
    616     * roll(Calendar::DATE, true). When rolling on the year or Calendar::YEAR field, it
    617     * will roll the year value in the range between getMinimum(Calendar::YEAR) and the
    618     * value returned by getMaximum(Calendar::YEAR). When rolling on the month or
    619     * Calendar::MONTH field, other fields like date might conflict and, need to be
    620     * changed. For instance, rolling the month up on the date 01/31/96 will result in
    621     * 02/29/96. Rolling up always means rolling forward in time (unless the limit of the
    622     * field is reached, in which case it may pin or wrap), so for Gregorian calendar,
    623     * starting with 100 BC and rolling the year up results in 99 BC.
    624     * When eras have a definite beginning and end (as in the Chinese calendar, or as in
    625     * most eras in the Japanese calendar) then rolling the year past either limit of the
    626     * era will cause the year to wrap around. When eras only have a limit at one end,
    627     * then attempting to roll the year past that limit will result in pinning the year
    628     * at that limit. Note that for most calendars in which era 0 years move forward in
    629     * time (such as Buddhist, Hebrew, or Islamic), it is possible for add or roll to
    630     * result in negative years for era 0 (that is the only way to represent years before
    631     * the calendar epoch).
    632     * When rolling on the hour-in-day or Calendar::HOUR_OF_DAY field, it will roll the
    633     * hour value in the range between 0 and 23, which is zero-based.
    634     * <P>
    635     * NOTE: Do not use this method -- use roll(UCalendarDateFields, int, UErrorCode&) instead.
    636     *
    637     * @param field   The time field.
    638     * @param up      Indicates if the value of the specified time field is to be rolled
    639     *                up or rolled down. Use true if rolling up, false otherwise.
    640     * @param status  Output param set to success/failure code on exit. If any value
    641     *                previously set in the time field is invalid or restricted by
    642     *                leniency, this will be set to an error status.
    643     * @stable ICU 2.6.
    644     */
    645    U_I18N_API inline void roll(UCalendarDateFields field, UBool up, UErrorCode& status);
    646 
    647 #ifndef U_FORCE_HIDE_DEPRECATED_API
    648    /**
    649     * Time Field Rolling function. Rolls by the given amount on the given
    650     * time field. For example, to roll the current date up by one day, call
    651     * roll(Calendar::DATE, +1, status). When rolling on the month or
    652     * Calendar::MONTH field, other fields like date might conflict and, need to be
    653     * changed. For instance, rolling the month up on the date 01/31/96 will result in
    654     * 02/29/96. Rolling by a positive value always means rolling forward in time (unless
    655     * the limit of the field is reached, in which case it may pin or wrap), so for
    656     * Gregorian calendar, starting with 100 BC and rolling the year by + 1 results in 99 BC.
    657     * When eras have a definite beginning and end (as in the Chinese calendar, or as in
    658     * most eras in the Japanese calendar) then rolling the year past either limit of the
    659     * era will cause the year to wrap around. When eras only have a limit at one end,
    660     * then attempting to roll the year past that limit will result in pinning the year
    661     * at that limit. Note that for most calendars in which era 0 years move forward in
    662     * time (such as Buddhist, Hebrew, or Islamic), it is possible for add or roll to
    663     * result in negative years for era 0 (that is the only way to represent years before
    664     * the calendar epoch).
    665     * When rolling on the hour-in-day or Calendar::HOUR_OF_DAY field, it will roll the
    666     * hour value in the range between 0 and 23, which is zero-based.
    667     * <P>
    668     * The only difference between roll() and add() is that roll() does not change
    669     * the value of more significant fields when it reaches the minimum or maximum
    670     * of its range, whereas add() does.
    671     *
    672     * @param field   The time field.
    673     * @param amount  Indicates amount to roll.
    674     * @param status  Output param set to success/failure code on exit. If any value
    675     *                previously set in the time field is invalid, this will be set to
    676     *                an error status.
    677     * @deprecated ICU 2.6. Use roll(UCalendarDateFields field, int32_t amount, UErrorCode& status) instead.
    678     */
    679    U_I18N_API virtual void roll(EDateFields field, int32_t amount, UErrorCode& status);
    680 #endif  // U_FORCE_HIDE_DEPRECATED_API
    681 
    682    /**
    683     * Time Field Rolling function. Rolls by the given amount on the given
    684     * time field. For example, to roll the current date up by one day, call
    685     * roll(Calendar::DATE, +1, status). When rolling on the month or
    686     * Calendar::MONTH field, other fields like date might conflict and, need to be
    687     * changed. For instance, rolling the month up on the date 01/31/96 will result in
    688     * 02/29/96. Rolling by a positive value always means rolling forward in time (unless
    689     * the limit of the field is reached, in which case it may pin or wrap), so for
    690     * Gregorian calendar, starting with 100 BC and rolling the year by + 1 results in 99 BC.
    691     * When eras have a definite beginning and end (as in the Chinese calendar, or as in
    692     * most eras in the Japanese calendar) then rolling the year past either limit of the
    693     * era will cause the year to wrap around. When eras only have a limit at one end,
    694     * then attempting to roll the year past that limit will result in pinning the year
    695     * at that limit. Note that for most calendars in which era 0 years move forward in
    696     * time (such as Buddhist, Hebrew, or Islamic), it is possible for add or roll to
    697     * result in negative years for era 0 (that is the only way to represent years before
    698     * the calendar epoch).
    699     * When rolling on the hour-in-day or Calendar::HOUR_OF_DAY field, it will roll the
    700     * hour value in the range between 0 and 23, which is zero-based.
    701     * <P>
    702     * The only difference between roll() and add() is that roll() does not change
    703     * the value of more significant fields when it reaches the minimum or maximum
    704     * of its range, whereas add() does.
    705     *
    706     * @param field   The time field.
    707     * @param amount  Indicates amount to roll.
    708     * @param status  Output param set to success/failure code on exit. If any value
    709     *                previously set in the time field is invalid, this will be set to
    710     *                an error status.
    711     * @stable ICU 2.6.
    712     */
    713    U_I18N_API virtual void roll(UCalendarDateFields field, int32_t amount, UErrorCode& status);
    714 
    715 #ifndef U_FORCE_HIDE_DEPRECATED_API
    716    /**
    717     * Return the difference between the given time and the time this
    718     * calendar object is set to.  If this calendar is set
    719     * <em>before</em> the given time, the returned value will be
    720     * positive.  If this calendar is set <em>after</em> the given
    721     * time, the returned value will be negative.  The
    722     * <code>field</code> parameter specifies the units of the return
    723     * value.  For example, if <code>fieldDifference(when,
    724     * Calendar::MONTH)</code> returns 3, then this calendar is set to
    725     * 3 months before <code>when</code>, and possibly some addition
    726     * time less than one month.
    727     *
    728     * <p>As a side effect of this call, this calendar is advanced
    729     * toward <code>when</code> by the given amount.  That is, calling
    730     * this method has the side effect of calling <code>add(field,
    731     * n)</code>, where <code>n</code> is the return value.
    732     *
    733     * <p>Usage: To use this method, call it first with the largest
    734     * field of interest, then with progressively smaller fields.  For
    735     * example:
    736     *
    737     * <pre>
    738     * int y = cal->fieldDifference(when, Calendar::YEAR, err);
    739     * int m = cal->fieldDifference(when, Calendar::MONTH, err);
    740     * int d = cal->fieldDifference(when, Calendar::DATE, err);</pre>
    741     *
    742     * computes the difference between <code>cal</code> and
    743     * <code>when</code> in years, months, and days.
    744     *
    745     * <p>Note: <code>fieldDifference()</code> is
    746     * <em>asymmetrical</em>.  That is, in the following code:
    747     *
    748     * <pre>
    749     * cal->setTime(date1, err);
    750     * int m1 = cal->fieldDifference(date2, Calendar::MONTH, err);
    751     * int d1 = cal->fieldDifference(date2, Calendar::DATE, err);
    752     * cal->setTime(date2, err);
    753     * int m2 = cal->fieldDifference(date1, Calendar::MONTH, err);
    754     * int d2 = cal->fieldDifference(date1, Calendar::DATE, err);</pre>
    755     *
    756     * one might expect that <code>m1 == -m2 && d1 == -d2</code>.
    757     * However, this is not generally the case, because of
    758     * irregularities in the underlying calendar system (e.g., the
    759     * Gregorian calendar has a varying number of days per month).
    760     *
    761     * @param when the date to compare this calendar's time to
    762     * @param field the field in which to compute the result
    763     * @param status  Output param set to success/failure code on exit. If any value
    764     *                previously set in the time field is invalid, this will be set to
    765     *                an error status.
    766     * @return the difference, either positive or negative, between
    767     * this calendar's time and <code>when</code>, in terms of
    768     * <code>field</code>.
    769     * @deprecated ICU 2.6. Use fieldDifference(UDate when, UCalendarDateFields field, UErrorCode& status).
    770     */
    771    U_I18N_API virtual int32_t fieldDifference(UDate when, EDateFields field, UErrorCode& status);
    772 #endif  // U_FORCE_HIDE_DEPRECATED_API
    773 
    774    /**
    775     * Return the difference between the given time and the time this
    776     * calendar object is set to.  If this calendar is set
    777     * <em>before</em> the given time, the returned value will be
    778     * positive.  If this calendar is set <em>after</em> the given
    779     * time, the returned value will be negative.  The
    780     * <code>field</code> parameter specifies the units of the return
    781     * value.  For example, if <code>fieldDifference(when,
    782     * Calendar::MONTH)</code> returns 3, then this calendar is set to
    783     * 3 months before <code>when</code>, and possibly some addition
    784     * time less than one month.
    785     *
    786     * <p>As a side effect of this call, this calendar is advanced
    787     * toward <code>when</code> by the given amount.  That is, calling
    788     * this method has the side effect of calling <code>add(field,
    789     * n)</code>, where <code>n</code> is the return value.
    790     *
    791     * <p>Usage: To use this method, call it first with the largest
    792     * field of interest, then with progressively smaller fields.  For
    793     * example:
    794     *
    795     * <pre>
    796     * int y = cal->fieldDifference(when, Calendar::YEAR, err);
    797     * int m = cal->fieldDifference(when, Calendar::MONTH, err);
    798     * int d = cal->fieldDifference(when, Calendar::DATE, err);</pre>
    799     *
    800     * computes the difference between <code>cal</code> and
    801     * <code>when</code> in years, months, and days.
    802     *
    803     * <p>Note: <code>fieldDifference()</code> is
    804     * <em>asymmetrical</em>.  That is, in the following code:
    805     *
    806     * <pre>
    807     * cal->setTime(date1, err);
    808     * int m1 = cal->fieldDifference(date2, Calendar::MONTH, err);
    809     * int d1 = cal->fieldDifference(date2, Calendar::DATE, err);
    810     * cal->setTime(date2, err);
    811     * int m2 = cal->fieldDifference(date1, Calendar::MONTH, err);
    812     * int d2 = cal->fieldDifference(date1, Calendar::DATE, err);</pre>
    813     *
    814     * one might expect that <code>m1 == -m2 && d1 == -d2</code>.
    815     * However, this is not generally the case, because of
    816     * irregularities in the underlying calendar system (e.g., the
    817     * Gregorian calendar has a varying number of days per month).
    818     *
    819     * @param when the date to compare this calendar's time to
    820     * @param field the field in which to compute the result
    821     * @param status  Output param set to success/failure code on exit. If any value
    822     *                previously set in the time field is invalid, this will be set to
    823     *                an error status.
    824     * @return the difference, either positive or negative, between
    825     * this calendar's time and <code>when</code>, in terms of
    826     * <code>field</code>.
    827     * @stable ICU 2.6.
    828     */
    829    U_I18N_API virtual int32_t fieldDifference(UDate when,
    830                                               UCalendarDateFields field,
    831                                               UErrorCode& status);
    832 
    833    /**
    834     * Sets the calendar's time zone to be the one passed in. The Calendar takes ownership
    835     * of the TimeZone; the caller is no longer responsible for deleting it.  If the
    836     * given time zone is nullptr, this function has no effect.
    837     *
    838     * @param value  The given time zone.
    839     * @stable ICU 2.0
    840     */
    841    U_I18N_API void adoptTimeZone(TimeZone* value);
    842 
    843    /**
    844     * Sets the calendar's time zone to be the same as the one passed in. The TimeZone
    845     * passed in is _not_ adopted; the client is still responsible for deleting it.
    846     *
    847     * @param zone  The given time zone.
    848     * @stable ICU 2.0
    849     */
    850    U_I18N_API void setTimeZone(const TimeZone& zone);
    851 
    852    /**
    853     * Returns a reference to the time zone owned by this calendar. The returned reference
    854     * is only valid until clients make another call to adoptTimeZone or setTimeZone,
    855     * or this Calendar is destroyed.
    856     *
    857     * @return   The time zone object associated with this calendar.
    858     * @stable ICU 2.0
    859     */
    860    U_I18N_API const TimeZone& getTimeZone() const;
    861 
    862    /**
    863     * Returns the time zone owned by this calendar. The caller owns the returned object
    864     * and must delete it when done.  After this call, the new time zone associated
    865     * with this Calendar is the default TimeZone as returned by TimeZone::createDefault().
    866     *
    867     * @return   The time zone object which was associated with this calendar.
    868     * @stable ICU 2.0
    869     */
    870    U_I18N_API TimeZone* orphanTimeZone();
    871 
    872    /**
    873     * Queries if the current date for this Calendar is in Daylight Savings Time.
    874     *
    875     * @param status Fill-in parameter which receives the status of this operation.
    876     * @return   True if the current date for this Calendar is in Daylight Savings Time,
    877     *           false, otherwise.
    878     * @stable ICU 2.0
    879     */
    880    U_I18N_API virtual UBool inDaylightTime(UErrorCode& status) const;
    881 
    882    /**
    883     * Specifies whether or not date/time interpretation is to be lenient. With lenient
    884     * interpretation, a date such as "February 942, 1996" will be treated as being
    885     * equivalent to the 941st day after February 1, 1996. With strict interpretation,
    886     * such dates will cause an error when computing time from the time field values
    887     * representing the dates.
    888     *
    889     * @param lenient  True specifies date/time interpretation to be lenient.
    890     *
    891     * @see            DateFormat#setLenient
    892     * @stable ICU 2.0
    893     */
    894    U_I18N_API void setLenient(UBool lenient);
    895 
    896    /**
    897     * Tells whether date/time interpretation is to be lenient.
    898     *
    899     * @return   True tells that date/time interpretation is to be lenient.
    900     * @stable ICU 2.0
    901     */
    902    U_I18N_API UBool isLenient() const;
    903 
    904    /**
    905     * Sets the behavior for handling wall time repeating multiple times
    906     * at negative time zone offset transitions. For example, 1:30 AM on
    907     * November 6, 2011 in US Eastern time (America/New_York) occurs twice;
    908     * 1:30 AM EDT, then 1:30 AM EST one hour later. When <code>UCAL_WALLTIME_FIRST</code>
    909     * is used, the wall time 1:30AM in this example will be interpreted as 1:30 AM EDT
    910     * (first occurrence). When <code>UCAL_WALLTIME_LAST</code> is used, it will be
    911     * interpreted as 1:30 AM EST (last occurrence). The default value is
    912     * <code>UCAL_WALLTIME_LAST</code>.
    913     * <p>
    914     * <b>Note:</b>When <code>UCAL_WALLTIME_NEXT_VALID</code> is not a valid
    915     * option for this. When the argument is neither <code>UCAL_WALLTIME_FIRST</code>
    916     * nor <code>UCAL_WALLTIME_LAST</code>, this method has no effect and will keep
    917     * the current setting.
    918     *
    919     * @param option the behavior for handling repeating wall time, either
    920     * <code>UCAL_WALLTIME_FIRST</code> or <code>UCAL_WALLTIME_LAST</code>.
    921     * @see #getRepeatedWallTimeOption
    922     * @stable ICU 49
    923     */
    924    U_I18N_API void setRepeatedWallTimeOption(UCalendarWallTimeOption option);
    925 
    926    /**
    927     * Gets the behavior for handling wall time repeating multiple times
    928     * at negative time zone offset transitions.
    929     *
    930     * @return the behavior for handling repeating wall time, either
    931     * <code>UCAL_WALLTIME_FIRST</code> or <code>UCAL_WALLTIME_LAST</code>.
    932     * @see #setRepeatedWallTimeOption
    933     * @stable ICU 49
    934     */
    935    U_I18N_API UCalendarWallTimeOption getRepeatedWallTimeOption() const;
    936 
    937    /**
    938     * Sets the behavior for handling skipped wall time at positive time zone offset
    939     * transitions. For example, 2:30 AM on March 13, 2011 in US Eastern time (America/New_York)
    940     * does not exist because the wall time jump from 1:59 AM EST to 3:00 AM EDT. When
    941     * <code>UCAL_WALLTIME_FIRST</code> is used, 2:30 AM is interpreted as 30 minutes before 3:00 AM
    942     * EDT, therefore, it will be resolved as 1:30 AM EST. When <code>UCAL_WALLTIME_LAST</code>
    943     * is used, 2:30 AM is interpreted as 31 minutes after 1:59 AM EST, therefore, it will be
    944     * resolved as 3:30 AM EDT. When <code>UCAL_WALLTIME_NEXT_VALID</code> is used, 2:30 AM will
    945     * be resolved as next valid wall time, that is 3:00 AM EDT. The default value is
    946     * <code>UCAL_WALLTIME_LAST</code>.
    947     * <p>
    948     * <b>Note:</b>This option is effective only when this calendar is lenient.
    949     * When the calendar is strict, such non-existing wall time will cause an error.
    950     *
    951     * @param option the behavior for handling skipped wall time at positive time zone
    952     * offset transitions, one of <code>UCAL_WALLTIME_FIRST</code>, <code>UCAL_WALLTIME_LAST</code> and
    953     * <code>UCAL_WALLTIME_NEXT_VALID</code>.
    954     * @see #getSkippedWallTimeOption
    955     *
    956     * @stable ICU 49
    957     */
    958    U_I18N_API void setSkippedWallTimeOption(UCalendarWallTimeOption option);
    959 
    960    /**
    961     * Gets the behavior for handling skipped wall time at positive time zone offset
    962     * transitions.
    963     *
    964     * @return the behavior for handling skipped wall time, one of
    965     * <code>UCAL_WALLTIME_FIRST</code>, <code>UCAL_WALLTIME_LAST</code>
    966     * and <code>UCAL_WALLTIME_NEXT_VALID</code>.
    967     * @see #setSkippedWallTimeOption
    968     * @stable ICU 49
    969     */
    970    U_I18N_API UCalendarWallTimeOption getSkippedWallTimeOption() const;
    971 
    972    /**
    973     * Sets what the first day of the week is; e.g., Sunday in US, Monday in France.
    974     *
    975     * @param value  The given first day of the week.
    976     * @stable ICU 2.6.
    977     */
    978    U_I18N_API void setFirstDayOfWeek(UCalendarDaysOfWeek value);
    979 
    980 #ifndef U_HIDE_DEPRECATED_API
    981    /**
    982     * Gets what the first day of the week is; e.g., Sunday in US, Monday in France.
    983     *
    984     * @return   The first day of the week.
    985     * @deprecated ICU 2.6 use the overload with error code
    986     */
    987    U_I18N_API EDaysOfWeek getFirstDayOfWeek() const;
    988 #endif  /* U_HIDE_DEPRECATED_API */
    989 
    990    /**
    991     * Gets what the first day of the week is; e.g., Sunday in US, Monday in France.
    992     *
    993     * @param status error code
    994     * @return   The first day of the week.
    995     * @stable ICU 2.6
    996     */
    997    U_I18N_API UCalendarDaysOfWeek getFirstDayOfWeek(UErrorCode& status) const;
    998 
    999    /**
   1000     * Sets what the minimal days required in the first week of the year are; For
   1001     * example, if the first week is defined as one that contains the first day of the
   1002     * first month of a year, call the method with value 1. If it must be a full week,
   1003     * use value 7.
   1004     *
   1005     * @param value  The given minimal days required in the first week of the year.
   1006     * @stable ICU 2.0
   1007     */
   1008    U_I18N_API void setMinimalDaysInFirstWeek(uint8_t value);
   1009 
   1010    /**
   1011     * Gets what the minimal days required in the first week of the year are; e.g., if
   1012     * the first week is defined as one that contains the first day of the first month
   1013     * of a year, getMinimalDaysInFirstWeek returns 1. If the minimal days required must
   1014     * be a full week, getMinimalDaysInFirstWeek returns 7.
   1015     *
   1016     * @return   The minimal days required in the first week of the year.
   1017     * @stable ICU 2.0
   1018     */
   1019    U_I18N_API uint8_t getMinimalDaysInFirstWeek() const;
   1020 
   1021 #ifndef U_FORCE_HIDE_DEPRECATED_API
   1022    /**
   1023     * Gets the minimum value for the given time field. e.g., for Gregorian
   1024     * DAY_OF_MONTH, 1.
   1025     *
   1026     * @param field  The given time field.
   1027     * @return       The minimum value for the given time field.
   1028     * @deprecated ICU 2.6. Use getMinimum(UCalendarDateFields field) instead.
   1029     */
   1030    U_I18N_API virtual int32_t getMinimum(EDateFields field) const;
   1031 #endif  // U_FORCE_HIDE_DEPRECATED_API
   1032 
   1033    /**
   1034     * Gets the minimum value for the given time field. e.g., for Gregorian
   1035     * DAY_OF_MONTH, 1.
   1036     *
   1037     * @param field  The given time field.
   1038     * @return       The minimum value for the given time field.
   1039     * @stable ICU 2.6.
   1040     */
   1041    U_I18N_API virtual int32_t getMinimum(UCalendarDateFields field) const;
   1042 
   1043 #ifndef U_FORCE_HIDE_DEPRECATED_API
   1044    /**
   1045     * Gets the maximum value for the given time field. e.g. for Gregorian DAY_OF_MONTH,
   1046     * 31.
   1047     *
   1048     * @param field  The given time field.
   1049     * @return       The maximum value for the given time field.
   1050     * @deprecated ICU 2.6. Use getMaximum(UCalendarDateFields field) instead.
   1051     */
   1052    U_I18N_API virtual int32_t getMaximum(EDateFields field) const;
   1053 #endif  // U_FORCE_HIDE_DEPRECATED_API
   1054 
   1055    /**
   1056     * Gets the maximum value for the given time field. e.g. for Gregorian DAY_OF_MONTH,
   1057     * 31.
   1058     *
   1059     * @param field  The given time field.
   1060     * @return       The maximum value for the given time field.
   1061     * @stable ICU 2.6.
   1062     */
   1063    U_I18N_API virtual int32_t getMaximum(UCalendarDateFields field) const;
   1064 
   1065 #ifndef U_FORCE_HIDE_DEPRECATED_API
   1066    /**
   1067     * Gets the highest minimum value for the given field if varies. Otherwise same as
   1068     * getMinimum(). For Gregorian, no difference.
   1069     *
   1070     * @param field  The given time field.
   1071     * @return       The highest minimum value for the given time field.
   1072     * @deprecated ICU 2.6. Use getGreatestMinimum(UCalendarDateFields field) instead.
   1073     */
   1074    U_I18N_API virtual int32_t getGreatestMinimum(EDateFields field) const;
   1075 #endif  // U_FORCE_HIDE_DEPRECATED_API
   1076 
   1077    /**
   1078     * Gets the highest minimum value for the given field if varies. Otherwise same as
   1079     * getMinimum(). For Gregorian, no difference.
   1080     *
   1081     * @param field  The given time field.
   1082     * @return       The highest minimum value for the given time field.
   1083     * @stable ICU 2.6.
   1084     */
   1085    U_I18N_API virtual int32_t getGreatestMinimum(UCalendarDateFields field) const;
   1086 
   1087 #ifndef U_FORCE_HIDE_DEPRECATED_API
   1088    /**
   1089     * Gets the lowest maximum value for the given field if varies. Otherwise same as
   1090     * getMaximum(). e.g., for Gregorian DAY_OF_MONTH, 28.
   1091     *
   1092     * @param field  The given time field.
   1093     * @return       The lowest maximum value for the given time field.
   1094     * @deprecated ICU 2.6. Use getLeastMaximum(UCalendarDateFields field) instead.
   1095     */
   1096    U_I18N_API virtual int32_t getLeastMaximum(EDateFields field) const;
   1097 #endif  // U_FORCE_HIDE_DEPRECATED_API
   1098 
   1099    /**
   1100     * Gets the lowest maximum value for the given field if varies. Otherwise same as
   1101     * getMaximum(). e.g., for Gregorian DAY_OF_MONTH, 28.
   1102     *
   1103     * @param field  The given time field.
   1104     * @return       The lowest maximum value for the given time field.
   1105     * @stable ICU 2.6.
   1106     */
   1107    U_I18N_API virtual int32_t getLeastMaximum(UCalendarDateFields field) const;
   1108 
   1109 #ifndef U_HIDE_DEPRECATED_API
   1110    /**
   1111     * Return the minimum value that this field could have, given the current date.
   1112     * For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum().
   1113     *
   1114     * The version of this function on Calendar uses an iterative algorithm to determine the
   1115     * actual minimum value for the field.  There is almost always a more efficient way to
   1116     * accomplish this (in most cases, you can simply return getMinimum()).  GregorianCalendar
   1117     * overrides this function with a more efficient implementation.
   1118     *
   1119     * @param field    the field to determine the minimum of
   1120     * @param status   Fill-in parameter which receives the status of this operation.
   1121     * @return         the minimum of the given field for the current date of this Calendar
   1122     * @deprecated ICU 2.6. Use getActualMinimum(UCalendarDateFields field, UErrorCode& status) instead.
   1123     */
   1124    U_I18N_API int32_t getActualMinimum(EDateFields field, UErrorCode& status) const;
   1125 #endif  /* U_HIDE_DEPRECATED_API */
   1126 
   1127    /**
   1128     * Return the minimum value that this field could have, given the current date.
   1129     * For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum().
   1130     *
   1131     * The version of this function on Calendar uses an iterative algorithm to determine the
   1132     * actual minimum value for the field.  There is almost always a more efficient way to
   1133     * accomplish this (in most cases, you can simply return getMinimum()).  GregorianCalendar
   1134     * overrides this function with a more efficient implementation.
   1135     *
   1136     * @param field    the field to determine the minimum of
   1137     * @param status   Fill-in parameter which receives the status of this operation.
   1138     * @return         the minimum of the given field for the current date of this Calendar
   1139     * @stable ICU 2.6.
   1140     */
   1141    U_I18N_API virtual int32_t getActualMinimum(UCalendarDateFields field, UErrorCode& status) const;
   1142 
   1143    /**
   1144     * Return the maximum value that this field could have, given the current date.
   1145     * For example, with the date "Feb 3, 1997" and the DAY_OF_MONTH field, the actual
   1146     * maximum would be 28; for "Feb 3, 1996" it s 29.  Similarly for a Hebrew calendar,
   1147     * for some years the actual maximum for MONTH is 12, and for others 13.
   1148     *
   1149     * The version of this function on Calendar uses an iterative algorithm to determine the
   1150     * actual maximum value for the field.  There is almost always a more efficient way to
   1151     * accomplish this (in most cases, you can simply return getMaximum()).  GregorianCalendar
   1152     * overrides this function with a more efficient implementation.
   1153     *
   1154     * @param field    the field to determine the maximum of
   1155     * @param status   Fill-in parameter which receives the status of this operation.
   1156     * @return         the maximum of the given field for the current date of this Calendar
   1157     * @stable ICU 2.6.
   1158     */
   1159    U_I18N_API virtual int32_t getActualMaximum(UCalendarDateFields field, UErrorCode& status) const;
   1160 
   1161    /**
   1162     * Gets the value for a given time field. Recalculate the current time field values
   1163     * if the time value has been changed by a call to setTime(). Return zero for unset
   1164     * fields if any fields have been explicitly set by a call to set(). To force a
   1165     * recomputation of all fields regardless of the previous state, call complete().
   1166     * This method is semantically const, but may alter the object in memory.
   1167     *
   1168     * @param field  The given time field.
   1169     * @param status Fill-in parameter which receives the status of the operation.
   1170     * @return       The value for the given time field, or zero if the field is unset,
   1171     *               and set() has been called for any other field.
   1172     * @stable ICU 2.6.
   1173     */
   1174    U_I18N_API int32_t get(UCalendarDateFields field, UErrorCode& status) const;
   1175 
   1176    /**
   1177     * Determines if the given time field has a value set. This can affect in the
   1178     * resolving of time in Calendar. Unset fields have a value of zero, by definition.
   1179     *
   1180     * @param field  The given time field.
   1181     * @return   True if the given time field has a value set; false otherwise.
   1182     * @stable ICU 2.6.
   1183     */
   1184    U_I18N_API UBool isSet(UCalendarDateFields field) const;
   1185 
   1186    /**
   1187     * Sets the given time field with the given value.
   1188     *
   1189     * @param field  The given time field.
   1190     * @param value  The value to be set for the given time field.
   1191     * @stable ICU 2.6.
   1192     */
   1193    U_I18N_API void set(UCalendarDateFields field, int32_t value);
   1194 
   1195    /**
   1196     * Sets the values for the fields YEAR, MONTH, and DATE. Other field values are
   1197     * retained; call clear() first if this is not desired.
   1198     *
   1199     * @param year   The value used to set the YEAR time field.
   1200     * @param month  The value used to set the MONTH time field. Month value is 0-based.
   1201     *               e.g., 0 for January.
   1202     * @param date   The value used to set the DATE time field.
   1203     * @stable ICU 2.0
   1204     */
   1205    U_I18N_API void set(int32_t year, int32_t month, int32_t date);
   1206 
   1207    /**
   1208     * Sets the values for the fields YEAR, MONTH, DATE, HOUR_OF_DAY, and MINUTE. Other
   1209     * field values are retained; call clear() first if this is not desired.
   1210     *
   1211     * @param year    The value used to set the YEAR time field.
   1212     * @param month   The value used to set the MONTH time field. Month value is
   1213     *                0-based. E.g., 0 for January.
   1214     * @param date    The value used to set the DATE time field.
   1215     * @param hour    The value used to set the HOUR_OF_DAY time field.
   1216     * @param minute  The value used to set the MINUTE time field.
   1217     * @stable ICU 2.0
   1218     */
   1219    U_I18N_API void set(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute);
   1220 
   1221    /**
   1222     * Sets the values for the fields YEAR, MONTH, DATE, HOUR_OF_DAY, MINUTE, and SECOND.
   1223     * Other field values are retained; call clear() first if this is not desired.
   1224     *
   1225     * @param year    The value used to set the YEAR time field.
   1226     * @param month   The value used to set the MONTH time field. Month value is
   1227     *                0-based. E.g., 0 for January.
   1228     * @param date    The value used to set the DATE time field.
   1229     * @param hour    The value used to set the HOUR_OF_DAY time field.
   1230     * @param minute  The value used to set the MINUTE time field.
   1231     * @param second  The value used to set the SECOND time field.
   1232     * @stable ICU 2.0
   1233     */
   1234    U_I18N_API void set(int32_t year, int32_t month, int32_t date,
   1235                        int32_t hour, int32_t minute, int32_t second);
   1236 
   1237    /**
   1238     * Clears the values of all the time fields, making them both unset and assigning
   1239     * them a value of zero. The field values will be determined during the next
   1240     * resolving of time into time fields.
   1241     * @stable ICU 2.0
   1242     */
   1243    U_I18N_API void clear();
   1244 
   1245    /**
   1246     * Clears the value in the given time field, both making it unset and assigning it a
   1247     * value of zero. This field value will be determined during the next resolving of
   1248     * time into time fields. Clearing UCAL_ORDINAL_MONTH or UCAL_MONTH will
   1249     * clear both fields.
   1250     *
   1251     * @param field  The time field to be cleared.
   1252     * @stable ICU 2.6.
   1253     */
   1254    U_I18N_API void clear(UCalendarDateFields field);
   1255 
   1256    /**
   1257     * Returns a unique class ID POLYMORPHICALLY. Pure virtual method. This method is to
   1258     * implement a simple version of RTTI, since not all C++ compilers support genuine
   1259     * RTTI. Polymorphic operator==() and clone() methods call this method.
   1260     * <P>
   1261     * Concrete subclasses of Calendar must implement getDynamicClassID() and also a
   1262     * static method and data member:
   1263     *
   1264     *      static UClassID getStaticClassID() { return (UClassID)&amp;fgClassID; }
   1265     *      static char fgClassID;
   1266     *
   1267     * @return   The class ID for this object. All objects of a given class have the
   1268     *           same class ID. Objects of other classes have different class IDs.
   1269     * @stable ICU 2.0
   1270     */
   1271    U_I18N_API virtual UClassID getDynamicClassID() const override = 0;
   1272 
   1273    /**
   1274     * Returns the calendar type name string for this Calendar object.
   1275     * The returned string is the legacy ICU calendar attribute value,
   1276     * for example, "gregorian" or "japanese".
   1277     *
   1278     * See type="old type name" for the calendar attribute of locale IDs
   1279     * at http://www.unicode.org/reports/tr35/#Key_Type_Definitions
   1280     *
   1281     * Sample code for getting the LDML/BCP 47 calendar key value:
   1282     * \code
   1283     * const char *calType = cal->getType();
   1284     * if (0 == strcmp(calType, "unknown")) {
   1285     *     // deal with unknown calendar type
   1286     * } else {
   1287     *     string localeID("root@calendar=");
   1288     *     localeID.append(calType);
   1289     *     char langTag[100];
   1290     *     UErrorCode errorCode = U_ZERO_ERROR;
   1291     *     int32_t length = uloc_toLanguageTag(localeID.c_str(), langTag, (int32_t)sizeof(langTag), true, &errorCode);
   1292     *     if (U_FAILURE(errorCode)) {
   1293     *         // deal with errors & overflow
   1294     *     }
   1295     *     string lang(langTag, length);
   1296     *     size_t caPos = lang.find("-ca-");
   1297     *     lang.erase(0, caPos + 4);
   1298     *     // lang now contains the LDML calendar type
   1299     * }
   1300     * \endcode
   1301     *
   1302     * @return legacy calendar type name string
   1303     * @stable ICU 49
   1304     */
   1305    U_I18N_API virtual const char* getType() const = 0;
   1306 
   1307    /**
   1308     * Returns whether the given day of the week is a weekday, a weekend day,
   1309     * or a day that transitions from one to the other, for the locale and
   1310     * calendar system associated with this Calendar (the locale's region is
   1311     * often the most determinant factor). If a transition occurs at midnight,
   1312     * then the days before and after the transition will have the
   1313     * type UCAL_WEEKDAY or UCAL_WEEKEND. If a transition occurs at a time
   1314     * other than midnight, then the day of the transition will have
   1315     * the type UCAL_WEEKEND_ONSET or UCAL_WEEKEND_CEASE. In this case, the
   1316     * method getWeekendTransition() will return the point of
   1317     * transition.
   1318     * @param dayOfWeek The day of the week whose type is desired (UCAL_SUNDAY..UCAL_SATURDAY).
   1319     * @param status The error code for the operation.
   1320     * @return The UCalendarWeekdayType for the day of the week.
   1321     * @stable ICU 4.4
   1322     */
   1323    U_I18N_API virtual UCalendarWeekdayType getDayOfWeekType(UCalendarDaysOfWeek dayOfWeek,
   1324                                                             UErrorCode& status) const;
   1325 
   1326    /**
   1327     * Returns the time during the day at which the weekend begins or ends in
   1328     * this calendar system.  If getDayOfWeekType() returns UCAL_WEEKEND_ONSET
   1329     * for the specified dayOfWeek, return the time at which the weekend begins.
   1330     * If getDayOfWeekType() returns UCAL_WEEKEND_CEASE for the specified dayOfWeek,
   1331     * return the time at which the weekend ends. If getDayOfWeekType() returns
   1332     * some other UCalendarWeekdayType for the specified dayOfWeek, is it an error condition
   1333     * (U_ILLEGAL_ARGUMENT_ERROR).
   1334     * @param dayOfWeek The day of the week for which the weekend transition time is
   1335     * desired (UCAL_SUNDAY..UCAL_SATURDAY).
   1336     * @param status The error code for the operation.
   1337     * @return The milliseconds after midnight at which the weekend begins or ends.
   1338     * @stable ICU 4.4
   1339     */
   1340    U_I18N_API virtual int32_t getWeekendTransition(UCalendarDaysOfWeek dayOfWeek,
   1341                                                    UErrorCode& status) const;
   1342 
   1343    /**
   1344     * Returns true if the given UDate is in the weekend in
   1345     * this calendar system.
   1346     * @param date The UDate in question.
   1347     * @param status The error code for the operation.
   1348     * @return true if the given UDate is in the weekend in
   1349     * this calendar system, false otherwise.
   1350     * @stable ICU 4.4
   1351     */
   1352    U_I18N_API virtual UBool isWeekend(UDate date, UErrorCode& status) const;
   1353 
   1354    /**
   1355     * Returns true if this Calendar's current date-time is in the weekend in
   1356     * this calendar system.
   1357     * @return true if this Calendar's current date-time is in the weekend in
   1358     * this calendar system, false otherwise.
   1359     * @stable ICU 4.4
   1360     */
   1361    U_I18N_API virtual UBool isWeekend() const;
   1362 
   1363    /**
   1364     * Returns true if the date is in a leap year. Recalculate the current time
   1365     * field values if the time value has been changed by a call to * setTime().
   1366     * This method is semantically const, but may alter the object in memory.
   1367     * A "leap year" is a year that contains more days than other years (for
   1368     * solar or lunar calendars) or more months than other years (for lunisolar
   1369     * calendars like Hebrew or Chinese), as defined in the ECMAScript Temporal
   1370     * proposal.
   1371     *
   1372     * @param status        ICU Error Code
   1373     * @return       True if the date in the fields is in a Temporal proposal
   1374     *               defined leap year. False otherwise.
   1375     * @stable ICU 73
   1376     */
   1377    U_I18N_API virtual bool inTemporalLeapYear(UErrorCode& status) const;
   1378 
   1379    /**
   1380     * Gets The Temporal monthCode value corresponding to the month for the date.
   1381     * The value is a string identifier that starts with the literal grapheme
   1382     * "M" followed by two graphemes representing the zero-padded month number
   1383     * of the current month in a normal (non-leap) year and suffixed by an
   1384     * optional literal grapheme "L" if this is a leap month in a lunisolar
   1385     * calendar. The 25 possible values are "M01" .. "M13" and "M01L" .. "M12L".
   1386     * For the Hebrew calendar, the values are "M01" .. "M12" for non-leap year, and
   1387     * "M01" .. "M05", "M05L", "M06" .. "M12" for leap year.
   1388     * For the Chinese calendar, the values are "M01" .. "M12" for non-leap year and
   1389     * in leap year with another monthCode in "M01L" .. "M12L".
   1390     * For Coptic and Ethiopian calendar, the Temporal monthCode values for any
   1391     * years are "M01" to "M13".
   1392     *
   1393     * @param status        ICU Error Code
   1394     * @return       One of 25 possible strings in {"M01".."M13", "M01L".."M12L"}.
   1395     * @stable ICU 73
   1396     */
   1397    U_I18N_API virtual const char* getTemporalMonthCode(UErrorCode& status) const;
   1398 
   1399    /**
   1400     * Sets The Temporal monthCode which is a string identifier that starts
   1401     * with the literal grapheme "M" followed by two graphemes representing
   1402     * the zero-padded month number of the current month in a normal
   1403     * (non-leap) year and suffixed by an optional literal grapheme "L" if this
   1404     * is a leap month in a lunisolar calendar. The 25 possible values are
   1405     * "M01" .. "M13" and "M01L" .. "M12L". For Hebrew calendar, the values are
   1406     * "M01" .. "M12" for non-leap years, and "M01" .. "M05", "M05L", "M06"
   1407     * .. "M12" for leap year.
   1408     * For the Chinese calendar, the values are "M01" .. "M12" for non-leap year and
   1409     * in leap year with another monthCode in "M01L" .. "M12L".
   1410     * For Coptic and Ethiopian calendar, the Temporal monthCode values for any
   1411     * years are "M01" to "M13".
   1412     *
   1413     * @param temporalMonth  The value to be set for temporal monthCode.
   1414     * @param status        ICU Error Code
   1415     *
   1416     * @stable ICU 73
   1417     */
   1418    U_I18N_API virtual void setTemporalMonthCode(const char* temporalMonth, UErrorCode& status);
   1419 
   1420 protected:
   1421 
   1422     /**
   1423      * Constructs a Calendar with the default time zone as returned by
   1424      * TimeZone::createInstance(), and the default locale.
   1425      *
   1426      * @param success  Indicates the status of Calendar object construction. Returns
   1427      *                 U_ZERO_ERROR if constructed successfully.
   1428     * @stable ICU 2.0
   1429      */
   1430    U_I18N_API Calendar(UErrorCode& success);
   1431 
   1432    /**
   1433     * Copy constructor
   1434     *
   1435     * @param source    Calendar object to be copied from
   1436     * @stable ICU 2.0
   1437     */
   1438    U_I18N_API Calendar(const Calendar& source);
   1439 
   1440    /**
   1441     * Default assignment operator
   1442     *
   1443     * @param right    Calendar object to be copied
   1444     * @stable ICU 2.0
   1445     */
   1446    U_I18N_API Calendar& operator=(const Calendar& right);
   1447 
   1448    /**
   1449     * Constructs a Calendar with the given time zone and locale. Clients are no longer
   1450     * responsible for deleting the given time zone object after it's adopted.
   1451     *
   1452     * @param zone     The given time zone.
   1453     * @param aLocale  The given locale.
   1454     * @param success  Indicates the status of Calendar object construction. Returns
   1455     *                 U_ZERO_ERROR if constructed successfully.
   1456     * @stable ICU 2.0
   1457     */
   1458    U_I18N_API Calendar(TimeZone* zone, const Locale& aLocale, UErrorCode& success);
   1459 
   1460    /**
   1461     * Constructs a Calendar with the given time zone and locale.
   1462     *
   1463     * @param zone     The given time zone.
   1464     * @param aLocale  The given locale.
   1465     * @param success  Indicates the status of Calendar object construction. Returns
   1466     *                 U_ZERO_ERROR if constructed successfully.
   1467     * @stable ICU 2.0
   1468     */
   1469    U_I18N_API Calendar(const TimeZone& zone, const Locale& aLocale, UErrorCode& success);
   1470 
   1471    /**
   1472     * Converts Calendar's time field values to GMT as milliseconds.
   1473     *
   1474     * @param status  Output param set to success/failure code on exit. If any value
   1475     *                previously set in the time field is invalid or restricted by
   1476     *                leniency, this will be set to an error status.
   1477     * @stable ICU 2.0
   1478     */
   1479    U_I18N_API virtual void computeTime(UErrorCode& status);
   1480 
   1481    /**
   1482     * Converts GMT as milliseconds to time field values. This allows you to sync up the
   1483     * time field values with a new time that is set for the calendar.  This method
   1484     * does NOT recompute the time first; to recompute the time, then the fields, use
   1485     * the method complete().
   1486     *
   1487     * @param status  Output param set to success/failure code on exit. If any value
   1488     *                previously set in the time field is invalid or restricted by
   1489     *                leniency, this will be set to an error status.
   1490     * @stable ICU 2.0
   1491     */
   1492    U_I18N_API virtual void computeFields(UErrorCode& status);
   1493 
   1494    /**
   1495     * Gets this Calendar's current time as a long.
   1496     *
   1497     * @param status  Output param set to success/failure code on exit. If any value
   1498     *                previously set in the time field is invalid or restricted by
   1499     *                leniency, this will be set to an error status.
   1500     * @return the current time as UTC milliseconds from the epoch.
   1501     * @stable ICU 2.0
   1502     */
   1503    U_I18N_API double getTimeInMillis(UErrorCode& status) const;
   1504 
   1505    /**
   1506     * Sets this Calendar's current time from the given long value.
   1507     * @param millis  the new time in UTC milliseconds from the epoch.
   1508     * @param status  Output param set to success/failure code on exit. If any value
   1509     *                previously set in the time field is invalid or restricted by
   1510     *                leniency, this will be set to an error status.
   1511     * @stable ICU 2.0
   1512     */
   1513    U_I18N_API void setTimeInMillis(double millis, UErrorCode& status);
   1514 
   1515    /**
   1516     * Recomputes the current time from currently set fields, and then fills in any
   1517     * unset fields in the time field list.
   1518     *
   1519     * @param status  Output param set to success/failure code on exit. If any value
   1520     *                previously set in the time field is invalid or restricted by
   1521     *                leniency, this will be set to an error status.
   1522     * @stable ICU 2.0
   1523     */
   1524    U_I18N_API void complete(UErrorCode& status);
   1525 
   1526 #ifndef U_HIDE_DEPRECATED_API
   1527    /**
   1528     * Gets the value for a given time field. Subclasses can use this function to get
   1529     * field values without forcing recomputation of time.
   1530     *
   1531     * @param field  The given time field.
   1532     * @return       The value for the given time field.
   1533     * @deprecated ICU 2.6. Use internalGet(UCalendarDateFields field) instead.
   1534     */
   1535    U_I18N_API inline int32_t internalGet(EDateFields field) const { return fFields[field]; }
   1536 #endif  /* U_HIDE_DEPRECATED_API */
   1537 
   1538 #ifndef U_HIDE_INTERNAL_API
   1539    /**
   1540     * Gets the value for a given time field. Subclasses can use this function to get
   1541     * field values without forcing recomputation of time. If the field's stamp is UNSET,
   1542     * the defaultValue is used.
   1543     *
   1544     * @param field  The given time field.
   1545     * @param defaultValue a default value used if the field is unset.
   1546     * @return       The value for the given time field.
   1547     * @internal
   1548     */
   1549    U_I18N_API inline int32_t internalGet(UCalendarDateFields field, int32_t defaultValue) const {
   1550        return fStamp[field] > kUnset ? fFields[field] : defaultValue;
   1551    }
   1552 
   1553    /**
   1554     * Gets the value for a given time field. Subclasses can use this function to get
   1555     * field values without forcing recomputation of time.
   1556     *
   1557     * @param field  The given time field.
   1558     * @return       The value for the given time field.
   1559     * @internal
   1560     */
   1561    U_I18N_API inline int32_t internalGet(UCalendarDateFields field) const { return fFields[field]; }
   1562 
   1563    /**
   1564     * The year in this calendar is counting from 1 backward if the era is 0.
   1565     * @return The year in era 0 of this calendar is counting backward from 1.
   1566     * @internal
   1567     */
   1568    U_I18N_API virtual bool isEra0CountingBackward() const { return false; }
   1569 
   1570    /**
   1571     * Related year difference.
   1572     * @return The difference in Related year.
   1573     * @internal
   1574     */
   1575    U_I18N_API virtual int32_t getRelatedYearDifference() const;
   1576 
   1577 #endif  /* U_HIDE_INTERNAL_API */
   1578 
   1579    /**
   1580     * Use this function instead of internalGet(UCAL_MONTH). The implementation
   1581     * check the timestamp of UCAL_MONTH and UCAL_ORDINAL_MONTH and use the
   1582     * one set later. The subclass should override it to conver the value of UCAL_ORDINAL_MONTH
   1583     * to UCAL_MONTH correctly if UCAL_ORDINAL_MONTH has higher priority.
   1584     *
   1585     * @return       The value for the UCAL_MONTH.
   1586     * @internal
   1587     */
   1588    U_I18N_API virtual int32_t internalGetMonth(UErrorCode& status) const;
   1589 
   1590    /**
   1591     * Use this function instead of internalGet(UCAL_MONTH, defaultValue). The implementation
   1592     * check the timestamp of UCAL_MONTH and UCAL_ORDINAL_MONTH and use the
   1593     * one set later. The subclass should override it to conver the value of UCAL_ORDINAL_MONTH
   1594     * to UCAL_MONTH correctly if UCAL_ORDINAL_MONTH has higher priority.
   1595     *
   1596     * @param defaultValue a default value used if the UCAL_MONTH and
   1597     *   UCAL_ORDINAL are both unset.
   1598     * @param status Output param set to failure code on function return
   1599     *          when this function fails.
   1600     * @return       The value for the UCAL_MONTH.
   1601     * @internal
   1602     */
   1603    U_I18N_API virtual int32_t internalGetMonth(int32_t defaultValue, UErrorCode& status) const;
   1604 
   1605 #ifndef U_HIDE_DEPRECATED_API
   1606    /**
   1607     * Sets the value for a given time field.  This is a fast internal method for
   1608     * subclasses.  It does not affect the areFieldsInSync, isTimeSet, or areAllFieldsSet
   1609     * flags.
   1610     *
   1611     * @param field    The given time field.
   1612     * @param value    The value for the given time field.
   1613     * @deprecated ICU 2.6. Use internalSet(UCalendarDateFields field, int32_t value) instead.
   1614     */
   1615    U_I18N_API void internalSet(EDateFields field, int32_t value);
   1616 #endif  /* U_HIDE_DEPRECATED_API */
   1617 
   1618    /**
   1619     * Sets the value for a given time field.  This is a fast internal method for
   1620     * subclasses.  It does not affect the areFieldsInSync, isTimeSet, or areAllFieldsSet
   1621     * flags.
   1622     *
   1623     * @param field    The given time field.
   1624     * @param value    The value for the given time field.
   1625     * @stable ICU 2.6.
   1626     */
   1627    U_I18N_API inline void internalSet(UCalendarDateFields field, int32_t value);
   1628 
   1629    /**
   1630     * Prepare this calendar for computing the actual minimum or maximum.
   1631     * This method modifies this calendar's fields; it is called on a
   1632     * temporary calendar.
   1633     * @internal
   1634     */
   1635    U_I18N_API virtual void prepareGetActual(UCalendarDateFields field,
   1636                                             UBool isMinimum,
   1637                                             UErrorCode& status);
   1638 
   1639    /**
   1640     * Limit enums. Not in sync with UCalendarLimitType (refers to internal fields).
   1641     * @internal
   1642     */
   1643    enum ELimitType {
   1644 #ifndef U_HIDE_INTERNAL_API
   1645      UCAL_LIMIT_MINIMUM = 0,
   1646      UCAL_LIMIT_GREATEST_MINIMUM,
   1647      UCAL_LIMIT_LEAST_MAXIMUM,
   1648      UCAL_LIMIT_MAXIMUM,
   1649      UCAL_LIMIT_COUNT
   1650 #endif  /* U_HIDE_INTERNAL_API */
   1651    };
   1652 
   1653    /**
   1654     * Subclass API for defining limits of different types.
   1655     * Subclasses must implement this method to return limits for the
   1656     * following fields:
   1657     *
   1658     * <pre>UCAL_ERA
   1659     * UCAL_YEAR
   1660     * UCAL_MONTH
   1661     * UCAL_WEEK_OF_YEAR
   1662     * UCAL_WEEK_OF_MONTH
   1663     * UCAL_DATE (DAY_OF_MONTH on Java)
   1664     * UCAL_DAY_OF_YEAR
   1665     * UCAL_DAY_OF_WEEK_IN_MONTH
   1666     * UCAL_YEAR_WOY
   1667     * UCAL_EXTENDED_YEAR</pre>
   1668     *
   1669     * @param field one of the above field numbers
   1670     * @param limitType one of <code>MINIMUM</code>, <code>GREATEST_MINIMUM</code>,
   1671     * <code>LEAST_MAXIMUM</code>, or <code>MAXIMUM</code>
   1672     * @internal
   1673     */
   1674    U_I18N_API virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const = 0;
   1675 
   1676    /**
   1677     * Return a limit for a field.
   1678     * @param field the field, from <code>0..UCAL_MAX_FIELD</code>
   1679     * @param limitType the type specifier for the limit
   1680     * @see #ELimitType
   1681     * @internal
   1682     */
   1683    U_I18N_API virtual int32_t getLimit(UCalendarDateFields field, ELimitType limitType) const;
   1684 
   1685    /**
   1686     * Return the Julian day number of day before the first day of the
   1687     * given month in the given extended year.  Subclasses should override
   1688     * this method to implement their calendar system.
   1689     * @param eyear the extended year
   1690     * @param month the zero-based month, or 0 if useMonth is false
   1691     * @param useMonth if false, compute the day before the first day of
   1692     * the given year, otherwise, compute the day before the first day of
   1693     * the given month
   1694     * @param status Output param set to failure code on function return
   1695     *          when this function fails.
   1696     * @return the Julian day number of the day before the first
   1697     * day of the given month and year
   1698     * @internal
   1699     */
   1700    U_I18N_API virtual int64_t handleComputeMonthStart(int32_t eyear,
   1701                                                       int32_t month,
   1702                                                       UBool useMonth,
   1703                                                       UErrorCode& status) const = 0;
   1704 
   1705    /**
   1706     * Return the number of days in the given month of the given extended
   1707     * year of this calendar system.  Subclasses should override this
   1708     * method if they can provide a more correct or more efficient
   1709     * implementation than the default implementation in Calendar.
   1710     * @internal
   1711     */
   1712    U_I18N_API virtual int32_t handleGetMonthLength(int32_t extendedYear,
   1713                                                    int32_t month,
   1714                                                    UErrorCode& status) const;
   1715 
   1716    /**
   1717     * Return the number of days in the given extended year of this
   1718     * calendar system.  Subclasses should override this method if they can
   1719     * provide a more correct or more efficient implementation than the
   1720     * default implementation in Calendar.
   1721     * @internal
   1722     */
   1723    U_I18N_API virtual int32_t handleGetYearLength(int32_t eyear, UErrorCode& status) const;
   1724 
   1725    /**
   1726     * Return the extended year defined by the current fields.  This will
   1727     * use the UCAL_EXTENDED_YEAR field or the UCAL_YEAR and supra-year fields (such
   1728     * as UCAL_ERA) specific to the calendar system, depending on which set of
   1729     * fields is newer.
   1730     * @param status        ICU Error Code
   1731     * @return the extended year
   1732     * @internal
   1733     */
   1734    U_I18N_API virtual int32_t handleGetExtendedYear(UErrorCode& status) = 0;
   1735 
   1736    /**
   1737     * Subclasses may override this.  This method calls
   1738     * handleGetMonthLength() to obtain the calendar-specific month
   1739     * length.
   1740     * @param bestField which field to use to calculate the date
   1741     * @param status        ICU Error Code
   1742     * @return julian day specified by calendar fields.
   1743     * @internal
   1744     */
   1745    U_I18N_API virtual int32_t handleComputeJulianDay(UCalendarDateFields bestField, UErrorCode& status);
   1746 
   1747    /**
   1748     * Subclasses must override this to convert from week fields
   1749     * (YEAR_WOY and WEEK_OF_YEAR) to an extended year in the case
   1750     * where YEAR, EXTENDED_YEAR are not set.
   1751     * The Calendar implementation assumes yearWoy is in extended gregorian form
   1752     * @return the extended year, UCAL_EXTENDED_YEAR
   1753     * @internal
   1754     */
   1755    U_I18N_API virtual int32_t handleGetExtendedYearFromWeekFields(int32_t yearWoy,
   1756                                                                   int32_t woy,
   1757                                                                   UErrorCode& status);
   1758 
   1759    /**
   1760     * Validate a single field of this calendar.  Subclasses should
   1761     * override this method to validate any calendar-specific fields.
   1762     * Generic fields can be handled by `Calendar::validateField()`.
   1763     * @internal
   1764     */
   1765    U_I18N_API virtual void validateField(UCalendarDateFields field, UErrorCode& status);
   1766 
   1767 #ifndef U_HIDE_INTERNAL_API
   1768    /**
   1769     * Compute the Julian day from fields.  Will determine whether to use
   1770     * the JULIAN_DAY field directly, or other fields.
   1771     * @param status        ICU Error Code
   1772     * @return the julian day
   1773     * @internal
   1774     */
   1775    U_I18N_API int32_t computeJulianDay(UErrorCode& status);
   1776 
   1777    /**
   1778     * Compute the milliseconds in the day from the fields.  This is a
   1779     * value from 0 to 23:59:59.999 inclusive, unless fields are out of
   1780     * range, in which case it can be an arbitrary value.  This value
   1781     * reflects local zone wall time.
   1782     * @internal
   1783     */
   1784    U_I18N_API double computeMillisInDay();
   1785 
   1786    /**
   1787     * This method can assume EXTENDED_YEAR has been set.
   1788     * @param millis milliseconds of the date fields
   1789     * @param millisInDay milliseconds of the time fields; may be out
   1790     * or range.
   1791     * @param ec Output param set to failure code on function return
   1792     *          when this function fails.
   1793     * @internal
   1794     */
   1795    U_I18N_API int32_t computeZoneOffset(double millis, double millisInDay, UErrorCode& ec);
   1796 
   1797    /**
   1798     * Determine the best stamp in a range.
   1799     * @param start first enum to look at
   1800     * @param end last enum to look at
   1801     * @param bestSoFar stamp prior to function call
   1802     * @return the stamp value of the best stamp
   1803     * @internal
   1804     */
   1805    U_I18N_API int32_t newestStamp(UCalendarDateFields start,
   1806                                   UCalendarDateFields end,
   1807                                   int32_t bestSoFar) const;
   1808 
   1809    /**
   1810     * Marker for end of resolve set (row or group). Value for field resolution tables.
   1811     *
   1812     * @see #resolveFields
   1813     * @internal
   1814     */
   1815    U_I18N_API static constexpr int32_t kResolveSTOP = -1;
   1816 
   1817    /**
   1818     * Value to be bitwised "ORed" against resolve table field values for remapping.
   1819     * Example: (UCAL_DATE | kResolveRemap) in 1st column will cause 'UCAL_DATE' to be returned,
   1820     * but will not examine the value of UCAL_DATE.
   1821     * Value for field resolution tables.
   1822     *
   1823     * @see #resolveFields
   1824     * @internal
   1825     */
   1826    U_I18N_API static constexpr int32_t kResolveRemap = 32;
   1827 
   1828    /**
   1829     * Precedence table for Dates
   1830     * @see #resolveFields
   1831     * @internal
   1832     */
   1833    U_I18N_API static const UFieldResolutionTable kDatePrecedence[];
   1834 
   1835    /**
   1836     * Precedence table for Year
   1837     * @see #resolveFields
   1838     * @internal
   1839     */
   1840    U_I18N_API static const UFieldResolutionTable kYearPrecedence[];
   1841 
   1842    /**
   1843     * Precedence table for Day of Week
   1844     * @see #resolveFields
   1845     * @internal
   1846     */
   1847    U_I18N_API static const UFieldResolutionTable kDOWPrecedence[];
   1848 
   1849    /**
   1850     * Precedence table for Months
   1851     * @see #resolveFields
   1852     * @internal
   1853     */
   1854    U_I18N_API static const UFieldResolutionTable kMonthPrecedence[];
   1855 
   1856    /**
   1857     * Given a precedence table, return the newest field combination in
   1858     * the table, or UCAL_FIELD_COUNT if none is found.
   1859     *
   1860     * <p>The precedence table is a 3-dimensional array of integers.  It
   1861     * may be thought of as an array of groups.  Each group is an array of
   1862     * lines.  Each line is an array of field numbers.  Within a line, if
   1863     * all fields are set, then the time stamp of the line is taken to be
   1864     * the stamp of the most recently set field.  If any field of a line is
   1865     * unset, then the line fails to match.  Within a group, the line with
   1866     * the newest time stamp is selected.  The first field of the line is
   1867     * returned to indicate which line matched.
   1868     *
   1869     * <p>In some cases, it may be desirable to map a line to field that
   1870     * whose stamp is NOT examined.  For example, if the best field is
   1871     * DAY_OF_WEEK then the DAY_OF_WEEK_IN_MONTH algorithm may be used.  In
   1872     * order to do this, insert the value <code>kResolveRemap | F</code> at
   1873     * the start of the line, where <code>F</code> is the desired return
   1874     * field value.  This field will NOT be examined; it only determines
   1875     * the return value if the other fields in the line are the newest.
   1876     *
   1877     * <p>If all lines of a group contain at least one unset field, then no
   1878     * line will match, and the group as a whole will fail to match.  In
   1879     * that case, the next group will be processed.  If all groups fail to
   1880     * match, then UCAL_FIELD_COUNT is returned.
   1881     * @internal
   1882     */
   1883    U_I18N_API UCalendarDateFields resolveFields(const UFieldResolutionTable* precedenceTable) const;
   1884 #endif  /* U_HIDE_INTERNAL_API */
   1885 
   1886    /**
   1887     * @internal
   1888     */
   1889    U_I18N_API virtual const UFieldResolutionTable* getFieldResolutionTable() const;
   1890 
   1891 #ifndef U_HIDE_INTERNAL_API
   1892    /**
   1893     * Return the field that is newer, either defaultField, or
   1894     * alternateField.  If neither is newer or neither is set, return defaultField.
   1895     * @internal
   1896     */
   1897    U_I18N_API UCalendarDateFields newerField(UCalendarDateFields defaultField,
   1898                                              UCalendarDateFields alternateField) const;
   1899 #endif  /* U_HIDE_INTERNAL_API */
   1900 
   1901 
   1902 private:
   1903    /**
   1904     * Helper function for calculating limits by trial and error
   1905     * @param field The field being investigated
   1906     * @param startValue starting (least max) value of field
   1907     * @param endValue ending (greatest max) value of field
   1908     * @param status return type
   1909     */
   1910    int32_t getActualHelper(UCalendarDateFields field, int32_t startValue, int32_t endValue, UErrorCode &status) const;
   1911 
   1912 protected:
   1913    /**
   1914     * Get the current time without recomputing.
   1915     *
   1916     * @return     the current time without recomputing.
   1917     * @stable ICU 2.0
   1918     */
   1919    U_I18N_API UDate internalGetTime() const { return fTime; }
   1920 
   1921    /**
   1922     * Set the current time without affecting flags or fields.
   1923     *
   1924     * @param time    The time to be set
   1925     * @return        the current time without recomputing.
   1926     * @stable ICU 2.0
   1927     */
   1928    U_I18N_API void internalSetTime(UDate time) { fTime = time; }
   1929 
   1930    /**
   1931     * The time fields containing values into which the millis is computed.
   1932     * @stable ICU 2.0
   1933     */
   1934    int32_t     fFields[UCAL_FIELD_COUNT];
   1935 
   1936 protected:
   1937    /** Special values of stamp[]
   1938     * @stable ICU 2.0
   1939     */
   1940    enum {
   1941        kUnset                 = 0,
   1942        kInternallySet,
   1943        kMinimumUserStamp
   1944    };
   1945 
   1946 private:
   1947    /**
   1948     * Pseudo-time-stamps which specify when each field was set. There
   1949     * are two special values, UNSET and INTERNALLY_SET. Values from
   1950     * MINIMUM_USER_SET to STAMP_MAX are legal user set values.
   1951     */
   1952    int8_t        fStamp[UCAL_FIELD_COUNT];
   1953 
   1954 protected:
   1955    /**
   1956     * Subclasses may override this method to compute several fields
   1957     * specific to each calendar system.  These are:
   1958     *
   1959     * <ul><li>ERA
   1960     * <li>YEAR
   1961     * <li>MONTH
   1962     * <li>DAY_OF_MONTH
   1963     * <li>DAY_OF_YEAR
   1964     * <li>EXTENDED_YEAR</ul>
   1965     *
   1966     * Subclasses can refer to the DAY_OF_WEEK and DOW_LOCAL fields, which
   1967     * will be set when this method is called.  Subclasses can also call
   1968     * the getGregorianXxx() methods to obtain Gregorian calendar
   1969     * equivalents for the given Julian day.
   1970     *
   1971     * <p>In addition, subclasses should compute any subclass-specific
   1972     * fields, that is, fields from BASE_FIELD_COUNT to
   1973     * getFieldCount() - 1.
   1974     *
   1975     * <p>The default implementation in <code>Calendar</code> implements
   1976     * a pure proleptic Gregorian calendar.
   1977     * @internal
   1978     */
   1979  U_I18N_API virtual void handleComputeFields(int32_t julianDay, UErrorCode& status);
   1980 
   1981 #ifndef U_HIDE_INTERNAL_API
   1982    /**
   1983     * Return the extended year on the Gregorian calendar as computed by
   1984     * <code>computeGregorianFields()</code>.
   1985     * @internal
   1986     */
   1987    U_I18N_API int32_t getGregorianYear() const {
   1988        return fGregorianYear;
   1989    }
   1990 
   1991    /**
   1992     * Return the month (0-based) on the Gregorian calendar as computed by
   1993     * <code>computeGregorianFields()</code>.
   1994     * @internal
   1995     */
   1996    U_I18N_API int32_t getGregorianMonth() const {
   1997        return fGregorianMonth;
   1998    }
   1999 
   2000    /**
   2001     * Return the day of year (1-based) on the Gregorian calendar as
   2002     * computed by <code>computeGregorianFields()</code>.
   2003     * @internal
   2004     */
   2005    U_I18N_API int32_t getGregorianDayOfYear() const {
   2006        return fGregorianDayOfYear;
   2007    }
   2008 
   2009    /**
   2010     * Return the day of month (1-based) on the Gregorian calendar as
   2011     * computed by <code>computeGregorianFields()</code>.
   2012     * @internal
   2013     */
   2014    U_I18N_API int32_t getGregorianDayOfMonth() const {
   2015      return fGregorianDayOfMonth;
   2016    }
   2017 #endif  /* U_HIDE_INTERNAL_API */
   2018 
   2019    /**
   2020     * Called by computeJulianDay.  Returns the default month (0-based) for the year,
   2021     * taking year and era into account.  Defaults to 0 for Gregorian, which doesn't care.
   2022     * @param eyear The extended year
   2023     * @param status Output param set to failure code on function return
   2024     *          when this function fails.
   2025     * @internal
   2026     */
   2027    U_I18N_API virtual int32_t getDefaultMonthInYear(int32_t eyear, UErrorCode& status);
   2028 
   2029    /**
   2030     * Called by computeJulianDay.  Returns the default day (1-based) for the month,
   2031     * taking currently-set year and era into account.  Defaults to 1 for Gregorian.
   2032     * @param eyear the extended year
   2033     * @param month the month in the year
   2034     * @param status Output param set to failure code on function return
   2035     *          when this function fails.
   2036     * @internal
   2037     */
   2038    U_I18N_API virtual int32_t getDefaultDayInMonth(int32_t eyear, int32_t month, UErrorCode& status);
   2039 
   2040    //-------------------------------------------------------------------------
   2041    // Protected utility methods for use by subclasses.  These are very handy
   2042    // for implementing add, roll, and computeFields.
   2043    //-------------------------------------------------------------------------
   2044 
   2045    /**
   2046     * Adjust the specified field so that it is within
   2047     * the allowable range for the date to which this calendar is set.
   2048     * For example, in a Gregorian calendar pinning the {@link #UCalendarDateFields DAY_OF_MONTH}
   2049     * field for a calendar set to April 31 would cause it to be set
   2050     * to April 30.
   2051     * <p>
   2052     * <b>Subclassing:</b>
   2053     * <br>
   2054     * This utility method is intended for use by subclasses that need to implement
   2055     * their own overrides of {@link #roll roll} and {@link #add add}.
   2056     * <p>
   2057     * <b>Note:</b>
   2058     * <code>pinField</code> is implemented in terms of
   2059     * {@link #getActualMinimum getActualMinimum}
   2060     * and {@link #getActualMaximum getActualMaximum}.  If either of those methods uses
   2061     * a slow, iterative algorithm for a particular field, it would be
   2062     * unwise to attempt to call <code>pinField</code> for that field.  If you
   2063     * really do need to do so, you should override this method to do
   2064     * something more efficient for that field.
   2065     * <p>
   2066     * @param field The calendar field whose value should be pinned.
   2067     * @param status Output param set to failure code on function return
   2068     *          when this function fails.
   2069     *
   2070     * @see #getActualMinimum
   2071     * @see #getActualMaximum
   2072     * @stable ICU 2.0
   2073     */
   2074    U_I18N_API virtual void pinField(UCalendarDateFields field, UErrorCode& status);
   2075 
   2076    /**
   2077     * Return the week number of a day, within a period. This may be the week number in
   2078     * a year or the week number in a month. Usually this will be a value >= 1, but if
   2079     * some initial days of the period are excluded from week 1, because
   2080     * {@link #getMinimalDaysInFirstWeek getMinimalDaysInFirstWeek} is > 1, then
   2081     * the week number will be zero for those
   2082     * initial days. This method requires the day number and day of week for some
   2083     * known date in the period in order to determine the day of week
   2084     * on the desired day.
   2085     * <p>
   2086     * <b>Subclassing:</b>
   2087     * <br>
   2088     * This method is intended for use by subclasses in implementing their
   2089     * {@link #computeTime computeTime} and/or {@link #computeFields computeFields} methods.
   2090     * It is often useful in {@link #getActualMinimum getActualMinimum} and
   2091     * {@link #getActualMaximum getActualMaximum} as well.
   2092     * <p>
   2093     * This variant is handy for computing the week number of some other
   2094     * day of a period (often the first or last day of the period) when its day
   2095     * of the week is not known but the day number and day of week for some other
   2096     * day in the period (e.g. the current date) <em>is</em> known.
   2097     * <p>
   2098     * @param desiredDay    The {@link #UCalendarDateFields DAY_OF_YEAR} or
   2099     *              {@link #UCalendarDateFields DAY_OF_MONTH} whose week number is desired.
   2100     *              Should be 1 for the first day of the period.
   2101     *
   2102     * @param dayOfPeriod   The {@link #UCalendarDateFields DAY_OF_YEAR}
   2103     *              or {@link #UCalendarDateFields DAY_OF_MONTH} for a day in the period whose
   2104     *              {@link #UCalendarDateFields DAY_OF_WEEK} is specified by the
   2105     *              <code>knownDayOfWeek</code> parameter.
   2106     *              Should be 1 for first day of period.
   2107     *
   2108     * @param dayOfWeek  The {@link #UCalendarDateFields DAY_OF_WEEK} for the day
   2109     *              corresponding to the <code>knownDayOfPeriod</code> parameter.
   2110     *              1-based with 1=Sunday.
   2111     *
   2112     * @return      The week number (one-based), or zero if the day falls before
   2113     *              the first week because
   2114     *              {@link #getMinimalDaysInFirstWeek getMinimalDaysInFirstWeek}
   2115     *              is more than one.
   2116     *
   2117     * @stable ICU 2.8
   2118     */
   2119    U_I18N_API int32_t weekNumber(int32_t desiredDay, int32_t dayOfPeriod, int32_t dayOfWeek);
   2120 
   2121 #ifndef U_HIDE_INTERNAL_API
   2122    /**
   2123     * Return the week number of a day, within a period. This may be the week number in
   2124     * a year, or the week number in a month. Usually this will be a value >= 1, but if
   2125     * some initial days of the period are excluded from week 1, because
   2126     * {@link #getMinimalDaysInFirstWeek getMinimalDaysInFirstWeek} is > 1,
   2127     * then the week number will be zero for those
   2128     * initial days. This method requires the day of week for the given date in order to
   2129     * determine the result.
   2130     * <p>
   2131     * <b>Subclassing:</b>
   2132     * <br>
   2133     * This method is intended for use by subclasses in implementing their
   2134     * {@link #computeTime computeTime} and/or {@link #computeFields computeFields} methods.
   2135     * It is often useful in {@link #getActualMinimum getActualMinimum} and
   2136     * {@link #getActualMaximum getActualMaximum} as well.
   2137     * <p>
   2138     * @param dayOfPeriod   The {@link #UCalendarDateFields DAY_OF_YEAR} or
   2139     *                      {@link #UCalendarDateFields DAY_OF_MONTH} whose week number is desired.
   2140     *                      Should be 1 for the first day of the period.
   2141     *
   2142     * @param dayOfWeek     The {@link #UCalendarDateFields DAY_OF_WEEK} for the day
   2143     *                      corresponding to the <code>dayOfPeriod</code> parameter.
   2144     *                      1-based with 1=Sunday.
   2145     *
   2146     * @return      The week number (one-based), or zero if the day falls before
   2147     *              the first week because
   2148     *              {@link #getMinimalDaysInFirstWeek getMinimalDaysInFirstWeek}
   2149     *              is more than one.
   2150     * @internal
   2151     */
   2152    U_I18N_API inline int32_t weekNumber(int32_t dayOfPeriod, int32_t dayOfWeek);
   2153 
   2154    /**
   2155     * returns the local DOW, valid range 0..6
   2156     * @internal
   2157     */
   2158    U_I18N_API int32_t getLocalDOW(UErrorCode& status);
   2159 #endif  /* U_HIDE_INTERNAL_API */
   2160 
   2161 private:
   2162 
   2163    /**
   2164     * The next available value for fStamp[]
   2165     */
   2166    int8_t fNextStamp = kMinimumUserStamp;
   2167 
   2168    /**
   2169     * Recalculates the time stamp array (fStamp).
   2170     * Resets fNextStamp to lowest next stamp value.
   2171     */
   2172    void recalculateStamp();
   2173 
   2174    /**
   2175     * The current time set for the calendar.
   2176     */
   2177    UDate        fTime = 0;
   2178 
   2179    /**
   2180     * Time zone affects the time calculation done by Calendar. Calendar subclasses use
   2181     * the time zone data to produce the local time. Always set; never nullptr.
   2182     */
   2183    TimeZone*   fZone = nullptr;
   2184 
   2185    /**
   2186     * The flag which indicates if the current time is set in the calendar.
   2187     */
   2188    bool      fIsTimeSet:1;
   2189 
   2190    /**
   2191     * True if the fields are in sync with the currently set time of this Calendar.
   2192     * If false, then the next attempt to get the value of a field will
   2193     * force a recomputation of all fields from the current value of the time
   2194     * field.
   2195     * <P>
   2196     * This should really be named areFieldsInSync, but the old name is retained
   2197     * for backward compatibility.
   2198     */
   2199    bool      fAreFieldsSet:1;
   2200 
   2201    /**
   2202     * True if all of the fields have been set.  This is initially false, and set to
   2203     * true by computeFields().
   2204     */
   2205    bool      fAreAllFieldsSet:1;
   2206 
   2207    /**
   2208     * True if all fields have been virtually set, but have not yet been
   2209     * computed.  This occurs only in setTimeInMillis().  A calendar set
   2210     * to this state will compute all fields from the time if it becomes
   2211     * necessary, but otherwise will delay such computation.
   2212     */
   2213    bool      fAreFieldsVirtuallySet:1;
   2214 
   2215    /**
   2216     * @see   #setLenient
   2217     */
   2218    bool      fLenient:1;
   2219 
   2220    /**
   2221     * Option for repeated wall time
   2222     * @see #setRepeatedWallTimeOption
   2223     */
   2224    UCalendarWallTimeOption fRepeatedWallTime:3; // Somehow MSVC need 3 bits for UCalendarWallTimeOption
   2225 
   2226    /**
   2227     * Option for skipped wall time
   2228     * @see #setSkippedWallTimeOption
   2229     */
   2230    UCalendarWallTimeOption fSkippedWallTime:3; // Somehow MSVC need 3 bits for UCalendarWallTimeOption
   2231 
   2232    /**
   2233     * Both firstDayOfWeek and minimalDaysInFirstWeek are locale-dependent. They are
   2234     * used to figure out the week count for a specific date for a given locale. These
   2235     * must be set when a Calendar is constructed. For example, in US locale,
   2236     * firstDayOfWeek is SUNDAY; minimalDaysInFirstWeek is 1. They are used to figure
   2237     * out the week count for a specific date for a given locale. These must be set when
   2238     * a Calendar is constructed.
   2239     */
   2240    UCalendarDaysOfWeek fFirstDayOfWeek:4; // Somehow MSVC need 4 bits for
   2241                                           // UCalendarDaysOfWeek
   2242    UCalendarDaysOfWeek fWeekendOnset:4; // Somehow MSVC need 4 bits for
   2243                                         // UCalendarDaysOfWeek
   2244    UCalendarDaysOfWeek fWeekendCease:4; // Somehow MSVC need 4 bits for
   2245                                         // UCalendarDaysOfWeek
   2246    uint8_t fMinimalDaysInFirstWeek;
   2247    int32_t fWeekendOnsetMillis;
   2248    int32_t fWeekendCeaseMillis;
   2249 
   2250    /**
   2251     * Sets firstDayOfWeek and minimalDaysInFirstWeek. Called at Calendar construction
   2252     * time.
   2253     *
   2254     * @param desiredLocale  The given locale.
   2255     * @param type           The calendar type identifier, e.g: gregorian, buddhist, etc.
   2256     * @param success        Indicates the status of setting the week count data from
   2257     *                       the resource for the given locale. Returns U_ZERO_ERROR if
   2258     *                       constructed successfully.
   2259     */
   2260    void        setWeekData(const Locale& desiredLocale, const char *type, UErrorCode& success);
   2261 
   2262    /**
   2263     * Recompute the time and update the status fields isTimeSet
   2264     * and areFieldsSet.  Callers should check isTimeSet and only
   2265     * call this method if isTimeSet is false.
   2266     *
   2267     * @param status  Output param set to success/failure code on exit. If any value
   2268     *                previously set in the time field is invalid or restricted by
   2269     *                leniency, this will be set to an error status.
   2270     */
   2271    void updateTime(UErrorCode& status);
   2272 
   2273    /**
   2274     * The Gregorian year, as computed by computeGregorianFields() and
   2275     * returned by getGregorianYear().
   2276     * @see #computeGregorianFields
   2277     */
   2278    int32_t fGregorianYear;
   2279 
   2280    /**
   2281     * The Gregorian month, as computed by computeGregorianFields() and
   2282     * returned by getGregorianMonth().
   2283     * @see #computeGregorianFields
   2284     */
   2285    int8_t fGregorianMonth;
   2286 
   2287    /**
   2288     * The Gregorian day of the month, as computed by
   2289     * computeGregorianFields() and returned by getGregorianDayOfMonth().
   2290     * @see #computeGregorianFields
   2291     */
   2292    int8_t fGregorianDayOfMonth;
   2293 
   2294    /**
   2295     * The Gregorian day of the year, as computed by
   2296     * computeGregorianFields() and returned by getGregorianDayOfYear().
   2297     * @see #computeGregorianFields
   2298     */
   2299    int16_t fGregorianDayOfYear;
   2300 
   2301    /* calculations */
   2302 
   2303 protected:
   2304 
   2305    /**
   2306     * Compute the Gregorian calendar year, month, and day of month from the
   2307     * Julian day.  These values are not stored in fields, but in member
   2308     * variables gregorianXxx.  They are used for time zone computations and by
   2309     * subclasses that are Gregorian derivatives.  Subclasses may call this
   2310     * method to perform a Gregorian calendar millis->fields computation.
   2311     */
   2312    U_I18N_API void computeGregorianFields(int32_t julianDay, UErrorCode& ec);
   2313 
   2314 private:
   2315 
   2316    /**
   2317     * Compute the fields WEEK_OF_YEAR, YEAR_WOY, WEEK_OF_MONTH,
   2318     * DAY_OF_WEEK_IN_MONTH, and DOW_LOCAL from EXTENDED_YEAR, YEAR,
   2319     * DAY_OF_WEEK, and DAY_OF_YEAR.  The latter fields are computed by the
   2320     * subclass based on the calendar system.
   2321     *
   2322     * <p>The YEAR_WOY field is computed simplistically.  It is equal to YEAR
   2323     * most of the time, but at the year boundary it may be adjusted to YEAR-1
   2324     * or YEAR+1 to reflect the overlap of a week into an adjacent year.  In
   2325     * this case, a simple increment or decrement is performed on YEAR, even
   2326     * though this may yield an invalid YEAR value.  For instance, if the YEAR
   2327     * is part of a calendar system with an N-year cycle field CYCLE, then
   2328     * incrementing the YEAR may involve incrementing CYCLE and setting YEAR
   2329     * back to 0 or 1.  This is not handled by this code, and in fact cannot be
   2330     * simply handled without having subclasses define an entire parallel set of
   2331     * fields for fields larger than or equal to a year.  This additional
   2332     * complexity is not warranted, since the intention of the YEAR_WOY field is
   2333     * to support ISO 8601 notation, so it will typically be used with a
   2334     * proleptic Gregorian calendar, which has no field larger than a year.
   2335     */
   2336    void computeWeekFields(UErrorCode &ec);
   2337 
   2338 
   2339    /**
   2340     * Ensure that each field is within its valid range by calling {@link
   2341     * #validateField(int, int&)} on each field that has been set.  This method
   2342     * should only be called if this calendar is not lenient.
   2343     * @see #isLenient
   2344     * @see #validateField(int, int&)
   2345     */
   2346    void validateFields(UErrorCode &status);
   2347 
   2348    /**
   2349     * Validate a single field of this calendar given its minimum and
   2350     * maximum allowed value.  If the field is out of range,
   2351     * <code>U_ILLEGAL_ARGUMENT_ERROR</code> will be set.  Subclasses may
   2352     * use this method in their implementation of {@link
   2353     * #validateField(int, int&)}.
   2354     */
   2355    void validateField(UCalendarDateFields field, int32_t min, int32_t max, UErrorCode& status);
   2356 
   2357 protected:
   2358 #ifndef U_HIDE_INTERNAL_API
   2359    /**
   2360     * Convert a quasi Julian date to the day of the week. The Julian date used here is
   2361     * not a true Julian date, since it is measured from midnight, not noon. Return
   2362     * value is one-based.
   2363     *
   2364     * @param julian  The given Julian date number.
   2365     * @return   Day number from 1..7 (SUN..SAT).
   2366     * @internal
   2367     */
   2368    U_I18N_API static uint8_t julianDayToDayOfWeek(int32_t julian);
   2369 #endif  /* U_HIDE_INTERNAL_API */
   2370 
   2371 private:
   2372    Locale validLocale;
   2373    Locale actualLocale;
   2374 
   2375 public:
   2376 #if !UCONFIG_NO_SERVICE
   2377    /**
   2378     * INTERNAL FOR 2.6 --  Registration.
   2379     */
   2380 
   2381 #ifndef U_HIDE_INTERNAL_API
   2382    /**
   2383     * Return a StringEnumeration over the locales available at the time of the call,
   2384     * including registered locales.
   2385     * @return a StringEnumeration over the locales available at the time of the call
   2386     * @internal
   2387     */
   2388    U_I18N_API static StringEnumeration* getAvailableLocales();
   2389 
   2390    /**
   2391     * Register a new Calendar factory.  The factory will be adopted.
   2392     * INTERNAL in 2.6
   2393     *
   2394     * Because ICU may choose to cache Calendars internally, this must
   2395     * be called at application startup, prior to any calls to
   2396     * Calendar::createInstance to avoid undefined behavior.
   2397     *
   2398     * @param toAdopt the factory instance to be adopted
   2399     * @param status the in/out status code, no special meanings are assigned
   2400     * @return a registry key that can be used to unregister this factory
   2401     * @internal
   2402     */
   2403    U_I18N_API static URegistryKey registerFactory(ICUServiceFactory* toAdopt, UErrorCode& status);
   2404 
   2405    /**
   2406     * Unregister a previously-registered CalendarFactory using the key returned from the
   2407     * register call.  Key becomes invalid after a successful call and should not be used again.
   2408     * The CalendarFactory corresponding to the key will be deleted.
   2409     * INTERNAL in 2.6
   2410     *
   2411     * Because ICU may choose to cache Calendars internally, this should
   2412     * be called during application shutdown, after all calls to
   2413     * Calendar::createInstance to avoid undefined behavior.
   2414     *
   2415     * @param key the registry key returned by a previous call to registerFactory
   2416     * @param status the in/out status code, no special meanings are assigned
   2417     * @return true if the factory for the key was successfully unregistered
   2418     * @internal
   2419     */
   2420    U_I18N_API static UBool unregister(URegistryKey key, UErrorCode& status);
   2421 #endif  /* U_HIDE_INTERNAL_API */
   2422 
   2423    /**
   2424     * Multiple Calendar Implementation
   2425     * @internal
   2426     */
   2427    friend class CalendarFactory;
   2428 
   2429    /**
   2430     * Multiple Calendar Implementation
   2431     * @internal
   2432     */
   2433    friend class CalendarService;
   2434 
   2435    /**
   2436     * Multiple Calendar Implementation
   2437     * @internal
   2438     */
   2439    friend class DefaultCalendarFactory;
   2440 #endif /* !UCONFIG_NO_SERVICE */
   2441 
   2442    /**
   2443     * @return true if this calendar has a default century (i.e. 03 -> 2003)
   2444     * @internal
   2445     */
   2446    U_I18N_API virtual UBool haveDefaultCentury() const = 0;
   2447 
   2448    /**
   2449     * @return the start of the default century, as a UDate
   2450     * @internal
   2451     */
   2452    U_I18N_API virtual UDate defaultCenturyStart() const = 0;
   2453 
   2454    /**
   2455     * @return the beginning year of the default century, as a year
   2456     * @internal
   2457     */
   2458    U_I18N_API virtual int32_t defaultCenturyStartYear() const = 0;
   2459 
   2460    /** Get the locale for this calendar object. You can choose between valid and actual locale.
   2461     *  @param type type of the locale we're looking for (valid or actual)
   2462     *  @param status error code for the operation
   2463     *  @return the locale
   2464     *  @stable ICU 2.8
   2465     */
   2466    U_I18N_API Locale getLocale(ULocDataLocaleType type, UErrorCode& status) const;
   2467 
   2468    /**
   2469     * @return      The related Gregorian year; will be obtained by modifying the value
   2470     *              obtained by get from UCAL_EXTENDED_YEAR field
   2471     * @internal
   2472     */
   2473    U_I18N_API virtual int32_t getRelatedYear(UErrorCode& status) const;
   2474 
   2475    /**
   2476     * @param year  The related Gregorian year to set; will be modified as necessary then
   2477     *              set in UCAL_EXTENDED_YEAR field
   2478     * @internal
   2479     */
   2480    U_I18N_API virtual void setRelatedYear(int32_t year);
   2481 
   2482 #ifndef U_HIDE_INTERNAL_API
   2483    /** Get the locale for this calendar object. You can choose between valid and actual locale.
   2484     *  @param type type of the locale we're looking for (valid or actual)
   2485     *  @param status error code for the operation
   2486     *  @return the locale
   2487     *  @internal
   2488     */
   2489    U_I18N_API const char* getLocaleID(ULocDataLocaleType type, UErrorCode& status) const;
   2490 #endif  /* U_HIDE_INTERNAL_API */
   2491 
   2492 private:
   2493    /**
   2494     * Cast TimeZone used by this object to BasicTimeZone, or nullptr if the TimeZone
   2495     * is not an instance of BasicTimeZone.
   2496     */
   2497    BasicTimeZone* getBasicTimeZone() const;
   2498 
   2499    /**
   2500     * Find the previous zone transition near the given time.
   2501     * @param base The base time, inclusive
   2502     * @param transitionTime Receives the result time
   2503     * @param status The error status
   2504     * @return true if a transition is found.
   2505     */
   2506    UBool getImmediatePreviousZoneTransition(UDate base, UDate *transitionTime, UErrorCode& status) const;
   2507 
   2508 public:
   2509 #ifndef U_HIDE_INTERNAL_API
   2510    /**
   2511     * Creates a new Calendar from a Locale for the cache.
   2512     * This method does not set the time or timezone in returned calendar.
   2513     * @param locale the locale.
   2514     * @param status any error returned here.
   2515     * @return the new Calendar object with no time or timezone set.
   2516     * @internal For ICU use only.
   2517     */
   2518    U_I18N_API static Calendar* U_EXPORT2 makeInstance(const Locale& locale, UErrorCode& status);
   2519 
   2520    /**
   2521     * Get the calendar type for given locale.
   2522     * @param locale the locale
   2523     * @param typeBuffer calendar type returned here
   2524     * @param typeBufferSize The size of typeBuffer in bytes. If the type
   2525     *   can't fit in the buffer, this method sets status to
   2526     *   U_BUFFER_OVERFLOW_ERROR
   2527     * @param status error, if any, returned here.
   2528     * @internal For ICU use only.
   2529     */
   2530    U_I18N_API static void U_EXPORT2 getCalendarTypeFromLocale(const Locale& locale,
   2531                                                               char* typeBuffer,
   2532                                                               int32_t typeBufferSize,
   2533                                                               UErrorCode& status);
   2534 #endif  /* U_HIDE_INTERNAL_API */
   2535 };
   2536 
   2537 // -------------------------------------
   2538 
   2539 inline Calendar*
   2540 Calendar::createInstance(TimeZone* zone, UErrorCode& errorCode)
   2541 {
   2542    // since the Locale isn't specified, use the default locale
   2543    return createInstance(zone, Locale::getDefault(), errorCode);
   2544 }
   2545 
   2546 // -------------------------------------
   2547 
   2548 inline void
   2549 Calendar::roll(UCalendarDateFields field, UBool up, UErrorCode& status)
   2550 {
   2551    roll(field, static_cast<int32_t>(up ? +1 : -1), status);
   2552 }
   2553 
   2554 #ifndef U_HIDE_DEPRECATED_API
   2555 inline void
   2556 Calendar::roll(EDateFields field, UBool up, UErrorCode& status)
   2557 {
   2558    roll(static_cast<UCalendarDateFields>(field), up, status);
   2559 }
   2560 #endif  /* U_HIDE_DEPRECATED_API */
   2561 
   2562 
   2563 // -------------------------------------
   2564 
   2565 /**
   2566 * Fast method for subclasses.  The caller must maintain fUserSetDSTOffset and
   2567 * fUserSetZoneOffset, as well as the isSet[] array.
   2568 */
   2569 
   2570 inline void
   2571 Calendar::internalSet(UCalendarDateFields field, int32_t value)
   2572 {
   2573    fFields[field] = value;
   2574    fStamp[field] = kInternallySet;
   2575 }
   2576 
   2577 /**
   2578 * Macro for the class to declare it override
   2579 * haveDefaultCentury, defaultCenturyStart, and
   2580 * defaultCenturyStartYear functions in this class.
   2581 * @internal
   2582 */
   2583 #define DECLARE_OVERRIDE_SYSTEM_DEFAULT_CENTURY \
   2584    virtual UBool haveDefaultCentury() const override; \
   2585    virtual UDate defaultCenturyStart() const override; \
   2586    virtual int32_t defaultCenturyStartYear() const override;
   2587 
   2588 #ifndef U_HIDE_INTERNAL_API
   2589 inline int32_t  Calendar::weekNumber(int32_t dayOfPeriod, int32_t dayOfWeek)
   2590 {
   2591  return weekNumber(dayOfPeriod, dayOfPeriod, dayOfWeek);
   2592 }
   2593 #endif  /* U_HIDE_INTERNAL_API */
   2594 
   2595 U_NAMESPACE_END
   2596 
   2597 #endif /* #if !UCONFIG_NO_FORMATTING */
   2598 
   2599 #endif /* U_SHOW_CPLUSPLUS_API */
   2600 
   2601 #endif // _CALENDAR