ICU 74.1 74.1

Public Types | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends
icu::Calendar Class Referenceabstract

`Calendar` is an abstract base class for converting between a `UDate` object and a set of integer fields such as `YEAR`, `MONTH`, `DAY`, `HOUR`, and so on. More...

`#include <calendar.h>`

Inheritance diagram for icu::Calendar:

## Public Types
enum | EDateFields { ERA , YEAR , MONTH , WEEK_OF_YEAR , WEEK_OF_MONTH , DATE , DAY_OF_YEAR , DAY_OF_WEEK , DAY_OF_WEEK_IN_MONTH , AM_PM , HOUR , HOUR_OF_DAY , MINUTE , SECOND , MILLISECOND , ZONE_OFFSET , DST_OFFSET , YEAR_WOY , DOW_LOCAL , EXTENDED_YEAR , JULIAN_DAY , MILLISECONDS_IN_DAY , IS_LEAP_MONTH , FIELD_COUNT = UCAL_FIELD_COUNT }
| Field IDs for date and time. More...
enum | EDaysOfWeek { SUNDAY = 1 , MONDAY , TUESDAY , WEDNESDAY , THURSDAY , FRIDAY , SATURDAY }
| Useful constant for days of week. More...
enum | EMonths { JANUARY , FEBRUARY , MARCH , APRIL , MAY , JUNE , JULY , AUGUST , SEPTEMBER , OCTOBER , NOVEMBER , DECEMBER , UNDECIMBER }
| Useful constants for month. More...
enum | EAmpm { AM , PM }
| Useful constants for hour in 12-hour clock. More...

## Public Member Functions
virtual | ~Calendar ()
| destructor More...
virtual Calendar * | clone () const =0
| Create and return a polymorphic copy of this calendar. More...
UDate | getTime (UErrorCode &status) const
| Gets this Calendar's time as milliseconds. More...
void | setTime (UDate date, UErrorCode &status)
| Sets this Calendar's current time with the given UDate. More...
virtual bool | operator== (const Calendar &that) const
| Compares the equality of two Calendar objects. More...
bool | operator!= (const Calendar &that) const
| Compares the inequality of two Calendar objects. More...
virtual UBool | isEquivalentTo (const Calendar &other) const
| Returns true if the given Calendar object is equivalent to this one. More...
UBool | equals (const Calendar &when, UErrorCode &status) const
| Compares the Calendar time, whereas Calendar::operator== compares the equality of Calendar objects. More...
UBool | before (const Calendar &when, UErrorCode &status) const
| Returns true if this Calendar's current time is before "when"'s current time. More...
UBool | after (const Calendar &when, UErrorCode &status) const
| Returns true if this Calendar's current time is after "when"'s current time. More...
virtual void | add (EDateFields field, int32_t amount, UErrorCode &status)
| UDate Arithmetic function. More...
virtual void | add (UCalendarDateFields field, int32_t amount, UErrorCode &status)
| UDate Arithmetic function. More...
void | roll (EDateFields field, UBool up, UErrorCode &status)
| Time Field Rolling function. More...
void | roll (UCalendarDateFields field, UBool up, UErrorCode &status)
| Time Field Rolling function. More...
virtual void | roll (EDateFields field, int32_t amount, UErrorCode &status)
| Time Field Rolling function. More...
virtual void | roll (UCalendarDateFields field, int32_t amount, UErrorCode &status)
| Time Field Rolling function. More...
virtual int32_t | fieldDifference (UDate when, EDateFields field, UErrorCode &status)
| Return the difference between the given time and the time this calendar object is set to. More...
virtual int32_t | fieldDifference (UDate when, UCalendarDateFields field, UErrorCode &status)
| Return the difference between the given time and the time this calendar object is set to. More...
void | adoptTimeZone (TimeZone *value)
| Sets the calendar's time zone to be the one passed in. More...
void | setTimeZone (const TimeZone &zone)
| Sets the calendar's time zone to be the same as the one passed in. More...
const TimeZone & | getTimeZone (void) const
| Returns a reference to the time zone owned by this calendar. More...
TimeZone * | orphanTimeZone (void)
| Returns the time zone owned by this calendar. More...
virtual UBool | inDaylightTime (UErrorCode &status) const
| Queries if the current date for this Calendar is in Daylight Savings Time. More...
void | setLenient (UBool lenient)
| Specifies whether or not date/time interpretation is to be lenient. More...
UBool | isLenient (void) const
| Tells whether date/time interpretation is to be lenient. More...
void | setRepeatedWallTimeOption (UCalendarWallTimeOption option)
| Sets the behavior for handling wall time repeating multiple times at negative time zone offset transitions. More...
UCalendarWallTimeOption | getRepeatedWallTimeOption (void) const
| Gets the behavior for handling wall time repeating multiple times at negative time zone offset transitions. More...
void | setSkippedWallTimeOption (UCalendarWallTimeOption option)
| Sets the behavior for handling skipped wall time at positive time zone offset transitions. More...
UCalendarWallTimeOption | getSkippedWallTimeOption (void) const
| Gets the behavior for handling skipped wall time at positive time zone offset transitions. More...
void | setFirstDayOfWeek (UCalendarDaysOfWeek value)
| Sets what the first day of the week is; e.g., Sunday in US, Monday in France. More...
EDaysOfWeek | getFirstDayOfWeek (void) const
| Gets what the first day of the week is; e.g., Sunday in US, Monday in France. More...
UCalendarDaysOfWeek | getFirstDayOfWeek (UErrorCode &status) const
| Gets what the first day of the week is; e.g., Sunday in US, Monday in France. More...
void | setMinimalDaysInFirstWeek (uint8_t value)
| Sets what the minimal days required in the first week of the year are; For example, if the first week is defined as one that contains the first day of the first month of a year, call the method with value 1. More...
uint8_t | getMinimalDaysInFirstWeek (void) const
| Gets what the minimal days required in the first week of the year are; e.g., if the first week is defined as one that contains the first day of the first month of a year, getMinimalDaysInFirstWeek returns 1. More...
virtual int32_t | getMinimum (EDateFields field) const
| Gets the minimum value for the given time field. More...
virtual int32_t | getMinimum (UCalendarDateFields field) const
| Gets the minimum value for the given time field. More...
virtual int32_t | getMaximum (EDateFields field) const
| Gets the maximum value for the given time field. More...
virtual int32_t | getMaximum (UCalendarDateFields field) const
| Gets the maximum value for the given time field. More...
virtual int32_t | getGreatestMinimum (EDateFields field) const
| Gets the highest minimum value for the given field if varies. More...
virtual int32_t | getGreatestMinimum (UCalendarDateFields field) const
| Gets the highest minimum value for the given field if varies. More...
virtual int32_t | getLeastMaximum (EDateFields field) const
| Gets the lowest maximum value for the given field if varies. More...
virtual int32_t | getLeastMaximum (UCalendarDateFields field) const
| Gets the lowest maximum value for the given field if varies. More...
int32_t | getActualMinimum (EDateFields field, UErrorCode &status) const
| Return the minimum value that this field could have, given the current date. More...
virtual int32_t | getActualMinimum (UCalendarDateFields field, UErrorCode &status) const
| Return the minimum value that this field could have, given the current date. More...
virtual int32_t | getActualMaximum (UCalendarDateFields field, UErrorCode &status) const
| Return the maximum value that this field could have, given the current date. More...
int32_t | get (UCalendarDateFields field, UErrorCode &status) const
| Gets the value for a given time field. More...
UBool | isSet (UCalendarDateFields field) const
| Determines if the given time field has a value set. More...
void | set (UCalendarDateFields field, int32_t value)
| Sets the given time field with the given value. More...
void | set (int32_t year, int32_t month, int32_t date)
| Sets the values for the fields YEAR, MONTH, and DATE. More...
void | set (int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute)
| Sets the values for the fields YEAR, MONTH, DATE, HOUR_OF_DAY, and MINUTE. More...
void | set (int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, int32_t second)
| Sets the values for the fields YEAR, MONTH, DATE, HOUR_OF_DAY, MINUTE, and SECOND. More...
void | clear (void)
| Clears the values of all the time fields, making them both unset and assigning them a value of zero. More...
void | clear (UCalendarDateFields field)
| Clears the value in the given time field, both making it unset and assigning it a value of zero. More...
virtual UClassID | getDynamicClassID (void) const override=0
| Returns a unique class ID POLYMORPHICALLY. More...
virtual const char * | getType () const =0
| Returns the calendar type name string for this Calendar object. More...
virtual UCalendarWeekdayType | getDayOfWeekType (UCalendarDaysOfWeek dayOfWeek, UErrorCode &status) const
| Returns whether the given day of the week is a weekday, a weekend day, or a day that transitions from one to the other, for the locale and calendar system associated with this Calendar (the locale's region is often the most determinant factor). More...
virtual int32_t | getWeekendTransition (UCalendarDaysOfWeek dayOfWeek, UErrorCode &status) const
| Returns the time during the day at which the weekend begins or ends in this calendar system. More...
virtual UBool | isWeekend (UDate date, UErrorCode &status) const
| Returns true if the given UDate is in the weekend in this calendar system. More...
virtual UBool | isWeekend (void) const
| Returns true if this Calendar's current date-time is in the weekend in this calendar system. More...
virtual bool | inTemporalLeapYear (UErrorCode &status) const
| Returns true if the date is in a leap year. More...
virtual const char * | getTemporalMonthCode (UErrorCode &status) const
| Gets The Temporal monthCode value corresponding to the month for the date. More...
virtual void | setTemporalMonthCode (const char *temporalMonth, UErrorCode &status)
| Sets The Temporal monthCode which is a string identifier that starts with the literal grapheme "M" followed by two graphemes representing the zero-padded month number of the current month in a normal (non-leap) year and suffixed by an optional literal grapheme "L" if this is a leap month in a lunisolar calendar. More...
virtual UBool | haveDefaultCentury () const =0
virtual UDate | defaultCenturyStart () const =0
virtual int32_t | defaultCenturyStartYear () const =0
Locale | getLocale (ULocDataLocaleType type, UErrorCode &status) const
| Get the locale for this calendar object. More...
virtual int32_t | getRelatedYear (UErrorCode &status) const
virtual void | setRelatedYear (int32_t year)
const char * | getLocaleID (ULocDataLocaleType type, UErrorCode &status) const
| Get the locale for this calendar object. More...
Public Member Functions inherited from icu::UObject
virtual | ~UObject ()
| Destructor. More...

## Static Public Member Functions
static Calendar * | createInstance (UErrorCode &success)
| Creates a Calendar using the default timezone and locale. More...
static Calendar * | createInstance (TimeZone *zoneToAdopt, UErrorCode &success)
| Creates a Calendar using the given timezone and the default locale. More...
static Calendar * | createInstance (const TimeZone &zone, UErrorCode &success)
| Creates a Calendar using the given timezone and the default locale. More...
static Calendar * | createInstance (const Locale &aLocale, UErrorCode &success)
| Creates a Calendar using the default timezone and the given locale. More...
static Calendar * | createInstance (TimeZone *zoneToAdopt, const Locale &aLocale, UErrorCode &success)
| Creates a Calendar using the given timezone and given locale. More...
static Calendar * | createInstance (const TimeZone &zone, const Locale &aLocale, UErrorCode &success)
| Gets a Calendar using the given timezone and given locale. More...
static const Locale * | getAvailableLocales (int32_t &count)
| Returns a list of the locales for which Calendars are installed. More...
static StringEnumeration * | getKeywordValuesForLocale (const char *key, const Locale &locale, UBool commonlyUsed, UErrorCode &status)
| Given a key and a locale, returns an array of string values in a preferred order that would make a difference. More...
static UDate | getNow (void)
| Returns the current UTC (GMT) time measured in milliseconds since 0:00:00 on 1/1/70 (derived from the system time). More...
static StringEnumeration * | getAvailableLocales (void)
| INTERNAL FOR 2.6 – Registration. More...
static URegistryKey | registerFactory (ICUServiceFactory *toAdopt, UErrorCode &status)
| Register a new Calendar factory. More...
static UBool | unregister (URegistryKey key, UErrorCode &status)
| Unregister a previously-registered CalendarFactory using the key returned from the register call. More...
static Calendar * | makeInstance (const Locale &locale, UErrorCode &status)
| Creates a new Calendar from a Locale for the cache. More...
static void | getCalendarTypeFromLocale (const Locale &locale, char *typeBuffer, int32_t typeBufferSize, UErrorCode &status)
| Get the calendar type for given locale. More...

## Protected Types
enum | ELimitType { UCAL_LIMIT_MINIMUM = 0 , UCAL_LIMIT_GREATEST_MINIMUM , UCAL_LIMIT_LEAST_MAXIMUM , UCAL_LIMIT_MAXIMUM , UCAL_LIMIT_COUNT }
| Limit enums. More...
enum | { kUnset = 0 , kInternallySet , kMinimumUserStamp }
| Special values of stamp[]. More...

## Protected Member Functions
| Calendar (UErrorCode &success)
| Constructs a Calendar with the default time zone as returned by TimeZone::createInstance(), and the default locale. More...
| Calendar (const Calendar &source)
| Copy constructor. More...
Calendar & | operator= (const Calendar &right)
| Default assignment operator. More...
| Calendar (TimeZone *zone, const Locale &aLocale, UErrorCode &success)
| Constructs a Calendar with the given time zone and locale. More...
| Calendar (const TimeZone &zone, const Locale &aLocale, UErrorCode &success)
| Constructs a Calendar with the given time zone and locale. More...
virtual void | computeTime (UErrorCode &status)
| Converts Calendar's time field values to GMT as milliseconds. More...
virtual void | computeFields (UErrorCode &status)
| Converts GMT as milliseconds to time field values. More...
double | getTimeInMillis (UErrorCode &status) const
| Gets this Calendar's current time as a long. More...
void | setTimeInMillis (double millis, UErrorCode &status)
| Sets this Calendar's current time from the given long value. More...
void | complete (UErrorCode &status)
| Recomputes the current time from currently set fields, and then fills in any unset fields in the time field list. More...
int32_t | internalGet (EDateFields field) const
| Gets the value for a given time field. More...
int32_t | internalGet (UCalendarDateFields field, int32_t defaultValue) const
| Gets the value for a given time field. More...
int32_t | internalGet (UCalendarDateFields field) const
| Gets the value for a given time field. More...
virtual int32_t | internalGetMonth () const
| Use this function instead of internalGet(UCAL_MONTH). More...
virtual int32_t | internalGetMonth (int32_t defaultValue) const
| Use this function instead of internalGet(UCAL_MONTH, defaultValue). More...
void | internalSet (EDateFields field, int32_t value)
| Sets the value for a given time field. More...
void | internalSet (UCalendarDateFields field, int32_t value)
| Sets the value for a given time field. More...
virtual void | prepareGetActual (UCalendarDateFields field, UBool isMinimum, UErrorCode &status)
| Prepare this calendar for computing the actual minimum or maximum. More...
virtual int32_t | handleGetLimit (UCalendarDateFields field, ELimitType limitType) const =0
| Subclass API for defining limits of different types. More...
virtual int32_t | getLimit (UCalendarDateFields field, ELimitType limitType) const
| Return a limit for a field. More...
virtual int32_t | handleComputeMonthStart (int32_t eyear, int32_t month, UBool useMonth) const =0
| Return the Julian day number of day before the first day of the given month in the given extended year. More...
virtual int32_t | handleGetMonthLength (int32_t extendedYear, int32_t month) const
| Return the number of days in the given month of the given extended year of this calendar system. More...
virtual int32_t | handleGetYearLength (int32_t eyear) const
| Return the number of days in the given extended year of this calendar system. More...
virtual int32_t | handleGetExtendedYear ()=0
| Return the extended year defined by the current fields. More...
virtual int32_t | handleComputeJulianDay (UCalendarDateFields bestField)
| Subclasses may override this. More...
virtual int32_t | handleGetExtendedYearFromWeekFields (int32_t yearWoy, int32_t woy)
| Subclasses must override this to convert from week fields (YEAR_WOY and WEEK_OF_YEAR) to an extended year in the case where YEAR, EXTENDED_YEAR are not set. More...
virtual void | validateField (UCalendarDateFields field, UErrorCode &status)
| Validate a single field of this calendar. More...
int32_t | computeJulianDay ()
| Compute the Julian day from fields. More...
double | computeMillisInDay ()
| Compute the milliseconds in the day from the fields. More...
int32_t | computeZoneOffset (double millis, double millisInDay, UErrorCode &ec)
| This method can assume EXTENDED_YEAR has been set. More...
int32_t | newestStamp (UCalendarDateFields start, UCalendarDateFields end, int32_t bestSoFar) const
| Determine the best stamp in a range. More...
UCalendarDateFields | resolveFields (const UFieldResolutionTable *precedenceTable) const
| Given a precedence table, return the newest field combination in the table, or UCAL_FIELD_COUNT if none is found. More...
virtual const UFieldResolutionTable * | getFieldResolutionTable () const
UCalendarDateFields | newerField (UCalendarDateFields defaultField, UCalendarDateFields alternateField) const
| Return the field that is newer, either defaultField, or alternateField. More...
UDate | internalGetTime (void) const
| Get the current time without recomputing. More...
void | internalSetTime (UDate time)
| Set the current time without affecting flags or fields. More...
virtual void | handleComputeFields (int32_t julianDay, UErrorCode &status)
| Subclasses may override this method to compute several fields specific to each calendar system. More...
int32_t | getGregorianYear () const
| Return the extended year on the Gregorian calendar as computed by `computeGregorianFields()`. More...
int32_t | getGregorianMonth () const
| Return the month (0-based) on the Gregorian calendar as computed by `computeGregorianFields()`. More...
int32_t | getGregorianDayOfYear () const
| Return the day of year (1-based) on the Gregorian calendar as computed by `computeGregorianFields()`. More...
int32_t | getGregorianDayOfMonth () const
| Return the day of month (1-based) on the Gregorian calendar as computed by `computeGregorianFields()`. More...
virtual int32_t | getDefaultMonthInYear (int32_t eyear)
| Called by computeJulianDay. More...
virtual int32_t | getDefaultDayInMonth (int32_t eyear, int32_t month)
| Called by computeJulianDay. More...
virtual void | pinField (UCalendarDateFields field, UErrorCode &status)
| Adjust the specified field so that it is within the allowable range for the date to which this calendar is set. More...
int32_t | weekNumber (int32_t desiredDay, int32_t dayOfPeriod, int32_t dayOfWeek)
| Return the week number of a day, within a period. More...
int32_t | weekNumber (int32_t dayOfPeriod, int32_t dayOfWeek)
| Return the week number of a day, within a period. More...
int32_t | getLocalDOW ()
| returns the local DOW, valid range 0..6 More...
void | computeGregorianFields (int32_t julianDay, UErrorCode &ec)
| Compute the Gregorian calendar year, month, and day of month from the Julian day. More...

## Static Protected Member Functions
static uint8_t | julianDayToDayOfWeek (double julian)
| Convert a quasi Julian date to the day of the week. More...

## Protected Attributes
UBool | fIsTimeSet
| The flag which indicates if the current time is set in the calendar. More...
UBool | fAreFieldsSet
| True if the fields are in sync with the currently set time of this Calendar. More...
UBool | fAreAllFieldsSet
| True if all of the fields have been set. More...
UBool | fAreFieldsVirtuallySet
| True if all fields have been virtually set, but have not yet been computed. More...
int32_t | fFields [UCAL_FIELD_COUNT]
| The time fields containing values into which the millis is computed. More...
UBool | fIsSet [UCAL_FIELD_COUNT]
| The flags which tell if a specified time field for the calendar is set. More...
int32_t | fStamp [UCAL_FIELD_COUNT]
| Pseudo-time-stamps which specify when each field was set. More...

## Static Protected Attributes
static constexpr int32_t | kResolveSTOP = -1
| Marker for end of resolve set (row or group). More...
static constexpr int32_t | kResolveRemap = 32
| Value to be bitwised "ORed" against resolve table field values for remapping. More...
static const UFieldResolutionTable | kDatePrecedence []
| Precedence table for Dates. More...
static const UFieldResolutionTable | kYearPrecedence []
| Precedence table for Year. More...
static const UFieldResolutionTable | kDOWPrecedence []
| Precedence table for Day of Week. More...
static const UFieldResolutionTable | kMonthPrecedence []
| Precedence table for Months. More...

## Friends
class | CalendarFactory
| Multiple Calendar Implementation. More...
class | CalendarService
| Multiple Calendar Implementation. More...
class | DefaultCalendarFactory
| Multiple Calendar Implementation. More...

## Detailed Description

`Calendar` is an abstract base class for converting between a `UDate` object and a set of integer fields such as `YEAR`, `MONTH`, `DAY`, `HOUR`, and so on.

(A `UDate` object represents a specific instant in time with millisecond precision. See UDate for information about the `UDate` class.)

Subclasses of `Calendar` interpret a `UDate` according to the rules of a specific calendar system. The most commonly used subclass of `Calendar` is `GregorianCalendar`. Other subclasses could represent the various types of lunar calendars in use in many parts of the world.

NOTE: (ICU 2.6) The subclass interface should be considered unstable - it WILL change.

Like other locale-sensitive classes, `Calendar` provides a static method, `createInstance`, for getting a generally useful object of this type. `Calendar`'s `createInstance` method returns the appropriate `Calendar` subclass whose time fields have been initialized with the current date and time:

    Calendar *rightNow = Calendar::createInstance(errCode);

A `Calendar` object can produce all the time field values needed to implement the date-time formatting for a particular language and calendar style (for example, Japanese-Gregorian, Japanese-Traditional).

When computing a `UDate` from time fields, some special circumstances may arise: there may be insufficient information to compute the `UDate` (such as only year and month but no day in the month), there may be inconsistent information (such as "Tuesday, July 15, 1996" – July 15, 1996 is actually a Monday), or the input time might be ambiguous because of time zone transition.

Insufficient information. The calendar will use default information to specify the missing fields. This may vary by calendar; for the Gregorian calendar, the default for a field is the same as that of the start of the epoch: i.e., YEAR = 1970, MONTH = JANUARY, DATE = 1, etc.

Inconsistent information. If fields conflict, the calendar will give preference to fields set more recently. For example, when determining the day, the calendar will look for one of the following combinations of fields. The most recent combination, as determined by the most recently set single field, will be used.

    MONTH + DAY_OF_MONTH
    MONTH + WEEK_OF_MONTH + DAY_OF_WEEK
    MONTH + DAY_OF_WEEK_IN_MONTH + DAY_OF_WEEK
    DAY_OF_YEAR
    DAY_OF_WEEK + WEEK_OF_YEAR

For the time of day:

    HOUR_OF_DAY
    AM_PM + HOUR

Ambiguous Wall Clock Time. When time offset from UTC has changed, it produces an ambiguous time slot around the transition. For example, many US locations observe daylight saving time. On the date switching to daylight saving time in US, wall clock time jumps from 12:59 AM (standard) to 2:00 AM (daylight). Therefore, wall clock time from 1:00 AM to 1:59 AM do not exist on the date. When the input wall time fall into this missing time slot, the ICU Calendar resolves the time using the UTC offset before the transition by default. In this example, 1:30 AM is interpreted as 1:30 AM standard time (non-exist), so the final result will be 2:30 AM daylight time.

On the date switching back to standard time, wall clock time is moved back one hour at 2:00 AM. So wall clock time from 1:00 AM to 1:59 AM occur twice. In this case, the ICU Calendar resolves the time using the UTC offset after the transition by default. For example, 1:30 AM on the date is resolved as 1:30 AM standard time.

Ambiguous wall clock time resolution behaviors can be customized by Calendar APIs setRepeatedWallTimeOption and setSkippedWallTimeOption. These methods are available in ICU 49 or later versions.

Note: for some non-Gregorian calendars, different fields may be necessary for complete disambiguation. For example, a full specification of the historical Arabic astronomical calendar requires year, month, day-of-month and day-of-week in some cases.

Note: There are certain possible ambiguities in interpretation of certain singular times, which are resolved in the following ways:

1. 24:00:00 "belongs" to the following day. That is, 23:59 on Dec 31, 1969 < 24:00 on Jan 1, 1970 < 24:01:00 on Jan 1, 1970
2. Although historically not precise, midnight also belongs to "am", and noon belongs to "pm", so on the same day, 12:00 am (midnight) < 12:01 am, and 12:00 pm (noon) < 12:01 pm

The date or time format strings are not part of the definition of a calendar, as those must be modifiable or overridable by the user at runtime. Use `DateFormat` to format dates.

`Calendar` provides an API for field "rolling", where fields can be incremented or decremented, but wrap around. For example, rolling the month up in the date December 12, 1996 results in January 12, 1996.

`Calendar` also provides a date arithmetic function for adding the specified (signed) amount of time to a particular time field. For example, subtracting 5 days from the date `September 12, 1996` results in `September 7, 1996`.

Supported range

The allowable range of `Calendar` has been narrowed. `GregorianCalendar` used to attempt to support the range of dates with millisecond values from `Long.MIN_VALUE` to `Long.MAX_VALUE`. The new `Calendar` protocol specifies the maximum range of supportable dates as those having Julian day numbers of `-0x7F000000` to `+0x7F000000`. This corresponds to years from ~5,800,000 BCE to ~5,800,000 CE. Programmers should use the protected constants in `Calendar` to specify an extremely early or extremely late date.

The Japanese calendar uses a combination of era name and year number. When an emperor of Japan abdicates and a new emperor ascends the throne, a new era is declared and year number is reset to 1. Even if the date of abdication is scheduled ahead of time, the new era name might not be announced until just before the date. In such case, ICU4C may include a start date of future era without actual era name, but not enabled by default. ICU4C users who want to test the behavior of the future era can enable the tentative era by:

- Environment variable `ICU_ENABLE_TENTATIVE_ERA=true`.

Stable:
  ICU 2.0

Definition at line 189 of file calendar.h.

## Member Enumeration Documentation

## ◆ anonymous enum

anonymous enum
| protected

Special values of stamp[].

Stable:
  ICU 2.0

Definition at line 1943 of file calendar.h.

## ◆ EAmpm

enum icu::Calendar::EAmpm

Useful constants for hour in 12-hour clock.

Used in GregorianCalendar.

Deprecated:
  ICU 2.6. Use C enum UCalendarAMPMs defined in ucal.h

Definition at line 277 of file calendar.h.

## ◆ EDateFields

enum icu::Calendar::EDateFields

Field IDs for date and time.

Used to specify date/time fields. ERA is calendar specific. Example ranges given are for illustration only; see specific Calendar subclasses for actual ranges.

Deprecated:
  ICU 2.6. Use C enum UCalendarDateFields defined in ucal.h

Definition at line 198 of file calendar.h.

## ◆ EDaysOfWeek

enum icu::Calendar::EDaysOfWeek

Useful constant for days of week.

Note: Calendar day-of-week is 1-based. Clients who create locale resources for the field of first-day-of-week should be aware of this. For instance, in US locale, first-day-of-week is set to 1, i.e., SUNDAY.

Deprecated:
  ICU 2.6. Use C enum UCalendarDaysOfWeek defined in ucal.h

Definition at line 243 of file calendar.h.

## ◆ ELimitType

enum icu::Calendar::ELimitType
| protected

Limit enums.

Not in sync with UCalendarLimitType (refers to internal fields).

Internal:
  Do not use. This API is for internal use only.

Definition at line 1615 of file calendar.h.

## ◆ EMonths

enum icu::Calendar::EMonths

Useful constants for month.

Note: Calendar month is 0-based.

Deprecated:
  ICU 2.6. Use C enum UCalendarMonths defined in ucal.h

Definition at line 257 of file calendar.h.

## Constructor & Destructor Documentation

## ◆ ~Calendar()

virtual icu::Calendar::~Calendar | ( |  | ) |
| virtual

destructor

Stable:
  ICU 2.0

## ◆ Calendar() [1/4]

icu::Calendar::Calendar | ( | UErrorCode & | success | ) |
| protected

Constructs a Calendar with the default time zone as returned by TimeZone::createInstance(), and the default locale.

Parameters

  success | Indicates the status of Calendar object construction. Returns U_ZERO_ERROR if constructed successfully.

Stable:
  ICU 2.0

## ◆ Calendar() [2/4]

icu::Calendar::Calendar | ( | const Calendar & | source | ) |
| protected

Copy constructor.

Parameters

  source | Calendar object to be copied from

Stable:
  ICU 2.0

## ◆ Calendar() [3/4]

icu::Calendar::Calendar | ( | TimeZone * | zone,
|  | const Locale & | aLocale,
|  | UErrorCode & | success
| ) |  |
| protected

Constructs a Calendar with the given time zone and locale.

Clients are no longer responsible for deleting the given time zone object after it's adopted.

Parameters

  zone | The given time zone.
  aLocale | The given locale.
  success | Indicates the status of Calendar object construction. Returns U_ZERO_ERROR if constructed successfully.

Stable:
  ICU 2.0

## ◆ Calendar() [4/4]

icu::Calendar::Calendar | ( | const TimeZone & | zone,
|  | const Locale & | aLocale,
|  | UErrorCode & | success
| ) |  |
| protected

Constructs a Calendar with the given time zone and locale.

Parameters

  zone | The given time zone.
  aLocale | The given locale.
  success | Indicates the status of Calendar object construction. Returns U_ZERO_ERROR if constructed successfully.

Stable:
  ICU 2.0

## Member Function Documentation

## ◆ add() [1/2]

virtual void icu::Calendar::add | ( | EDateFields | field,
|  | int32_t | amount,
|  | UErrorCode & | status
| ) |  |
| virtual

UDate Arithmetic function.

Adds the specified (signed) amount of time to the given time field, based on the calendar's rules. For example, to subtract 5 days from the current time of the calendar, call add(Calendar::DATE, -5). When adding on the month or Calendar::MONTH field, other fields like date might conflict and need to be changed. For instance, adding 1 month on the date 01/31/96 will result in 02/29/96. Adding a positive value always means moving forward in time, so for the Gregorian calendar, starting with 100 BC and adding +1 to year results in 99 BC (even though this actually reduces the numeric value of the field itself).

Parameters

  field | Specifies which date field to modify.
  amount | The amount of time to be added to the field, in the natural unit for that field (e.g., days for the day fields, hours for the hour field.)
  status | Output param set to success/failure code on exit. If any value previously set in the time field is invalid or restricted by leniency, this will be set to an error status.

Deprecated:
  ICU 2.6. use add(UCalendarDateFields field, int32_t amount, UErrorCode& status) instead.

## ◆ add() [2/2]

virtual void icu::Calendar::add | ( | UCalendarDateFields | field,
|  | int32_t | amount,
|  | UErrorCode & | status
| ) |  |
| virtual

UDate Arithmetic function.

Adds the specified (signed) amount of time to the given time field, based on the calendar's rules. For example, to subtract 5 days from the current time of the calendar, call add(Calendar::DATE, -5). When adding on the month or Calendar::MONTH field, other fields like date might conflict and need to be changed. For instance, adding 1 month on the date 01/31/96 will result in 02/29/96. Adding a positive value always means moving forward in time, so for the Gregorian calendar, starting with 100 BC and adding +1 to year results in 99 BC (even though this actually reduces the numeric value of the field itself).

Parameters

  field | Specifies which date field to modify.
  amount | The amount of time to be added to the field, in the natural unit for that field (e.g., days for the day fields, hours for the hour field.)
  status | Output param set to success/failure code on exit. If any value previously set in the time field is invalid or restricted by leniency, this will be set to an error status.

Stable:
  ICU 2.6.

## ◆ adoptTimeZone()

void icu::Calendar::adoptTimeZone | ( | TimeZone * | value | ) |

Sets the calendar's time zone to be the one passed in.

The Calendar takes ownership of the TimeZone; the caller is no longer responsible for deleting it. If the given time zone is nullptr, this function has no effect.

Parameters

  value | The given time zone.

Stable:
  ICU 2.0

## ◆ after()

UBool icu::Calendar::after | ( | const Calendar & | when,
|  | UErrorCode & | status
| ) |  | const

Returns true if this Calendar's current time is after "when"'s current time.

Parameters

  when | The Calendar to be compared with this Calendar. Although this is a const parameter, the object may be modified physically (semantically const).
  status | Output param set to success/failure code on exit. If any value previously set in the time field is invalid or restricted by leniency, this will be set to an error status.

Returns
  True if the current time of this Calendar is after the time of Calendar when; false otherwise.

Stable:
  ICU 2.0

## ◆ before()

UBool icu::Calendar::before | ( | const Calendar & | when,
|  | UErrorCode & | status
| ) |  | const

Returns true if this Calendar's current time is before "when"'s current time.

Parameters

  when | The Calendar to be compared with this Calendar. Although this is a const parameter, the object may be modified physically (semantically const).
  status | Output param set to success/failure code on exit. If any value previously set in the time field is invalid or restricted by leniency, this will be set to an error status.

Returns
  True if the current time of this Calendar is before the time of Calendar when; false otherwise.

Stable:
  ICU 2.0

## ◆ clear() [1/2]

void icu::Calendar::clear | ( | UCalendarDateFields | field | ) |

Clears the value in the given time field, both making it unset and assigning it a value of zero.

This field value will be determined during the next resolving of time into time fields. Clearing UCAL_ORDINAL_MONTH or UCAL_MONTH will clear both fields.

Parameters

  field | The time field to be cleared.

Stable:
  ICU 2.6.

## ◆ clear() [2/2]

void icu::Calendar::clear | ( | void |  | ) |

Clears the values of all the time fields, making them both unset and assigning them a value of zero.

The field values will be determined during the next resolving of time into time fields.

Stable:
  ICU 2.0

## ◆ clone()

virtual Calendar* icu::Calendar::clone | ( |  | ) | const
| pure virtual

Create and return a polymorphic copy of this calendar.

Returns
  a polymorphic copy of this calendar.

Stable:
  ICU 2.0

Implemented in icu::GregorianCalendar.

## ◆ complete()

void icu::Calendar::complete | ( | UErrorCode & | status | ) |
| protected

Recomputes the current time from currently set fields, and then fills in any unset fields in the time field list.

Parameters

  status | Output param set to success/failure code on exit. If any value previously set in the time field is invalid or restricted by leniency, this will be set to an error status.

Stable:
  ICU 2.0

## ◆ computeFields()

virtual void icu::Calendar::computeFields | ( | UErrorCode & | status | ) |
| protected virtual

Converts GMT as milliseconds to time field values.

This allows you to sync up the time field values with a new time that is set for the calendar. This method does NOT recompute the time first; to recompute the time, then the fields, use the method complete().

Parameters

  status | Output param set to success/failure code on exit. If any value previously set in the time field is invalid or restricted by leniency, this will be set to an error status.

Stable:
  ICU 2.0

## ◆ computeGregorianFields()

void icu::Calendar::computeGregorianFields | ( | int32_t | julianDay,
|  | UErrorCode & | ec
| ) |  |
| protected

Compute the Gregorian calendar year, month, and day of month from the Julian day.

These values are not stored in fields, but in member variables gregorianXxx. They are used for time zone computations and by subclasses that are Gregorian derivatives. Subclasses may call this method to perform a Gregorian calendar millis->fields computation.

## ◆ computeJulianDay()

int32_t icu::Calendar::computeJulianDay | ( |  | ) |
| protected

Compute the Julian day from fields.

Will determine whether to use the JULIAN_DAY field directly, or other fields.

Returns
  the julian day

Internal:
  Do not use. This API is for internal use only.

## ◆ computeMillisInDay()

double icu::Calendar::computeMillisInDay | ( |  | ) |
| protected

Compute the milliseconds in the day from the fields.

This is a value from 0 to 23:59:59.999 inclusive, unless fields are out of range, in which case it can be an arbitrary value. This value reflects local zone wall time.

Internal:
  Do not use. This API is for internal use only.

## ◆ computeTime()

virtual void icu::Calendar::computeTime | ( | UErrorCode & | status | ) |
| protected virtual

Converts Calendar's time field values to GMT as milliseconds.

Parameters

  status | Output param set to success/failure code on exit. If any value previously set in the time field is invalid or restricted by leniency, this will be set to an error status.

Stable:
  ICU 2.0

## ◆ computeZoneOffset()

int32_t icu::Calendar::computeZoneOffset | ( | double | millis,
|  | double | millisInDay,
|  | UErrorCode & | ec
| ) |  |
| protected

This method can assume EXTENDED_YEAR has been set.

Parameters

  millis | milliseconds of the date fields
  millisInDay | milliseconds of the time fields; may be out or range.
  ec | Output param set to failure code on function return when this function fails.

Internal:
  Do not use. This API is for internal use only.

## ◆ createInstance() [1/6]

static Calendar* icu::Calendar::createInstance | ( | const Locale & | aLocale,
|  | UErrorCode & | success
| ) |  |
| static

Creates a Calendar using the default timezone and the given locale.

Parameters

  aLocale | The given locale.
  success | Indicates the success/failure of Calendar creation. Filled in with U_ZERO_ERROR if created successfully, set to a failure result otherwise.

Returns
  A Calendar if created successfully. nullptr otherwise.

Stable:
  ICU 2.0

## ◆ createInstance() [2/6]

static Calendar* icu::Calendar::createInstance | ( | const TimeZone & | zone,
|  | const Locale & | aLocale,
|  | UErrorCode & | success
| ) |  |
| static

Gets a Calendar using the given timezone and given locale.

The TimeZone is not adopted; the client is still responsible for deleting it.

Parameters

  zone | The given timezone.
  aLocale | The given locale.
  success | Indicates the success/failure of Calendar creation. Filled in with U_ZERO_ERROR if created successfully, set to a failure result otherwise.

Returns
  A Calendar if created successfully. nullptr otherwise.

Stable:
  ICU 2.0

## ◆ createInstance() [3/6]

static Calendar* icu::Calendar::createInstance | ( | const TimeZone & | zone,
|  | UErrorCode & | success
| ) |  |
| static

Creates a Calendar using the given timezone and the default locale.

The TimeZone is not adopted; the client is still responsible for deleting it.

Parameters

  zone | The timezone.
  success | Indicates the success/failure of Calendar creation. Filled in with U_ZERO_ERROR if created successfully, set to a failure result otherwise.

Returns
  A Calendar if created successfully. nullptr otherwise.

Stable:
  ICU 2.0

## ◆ createInstance() [4/6]

static Calendar* icu::Calendar::createInstance | ( | TimeZone * | zoneToAdopt,
|  | const Locale & | aLocale,
|  | UErrorCode & | success
| ) |  |
| static

Creates a Calendar using the given timezone and given locale.

The Calendar takes ownership of zoneToAdopt; the client must not delete it.

Parameters

  zoneToAdopt | The given timezone to be adopted.
  aLocale | The given locale.
  success | Indicates the success/failure of Calendar creation. Filled in with U_ZERO_ERROR if created successfully, set to a failure result otherwise.

Returns
  A Calendar if created successfully. nullptr otherwise.

Stable:
  ICU 2.0

## ◆ createInstance() [5/6]

Calendar * icu::Calendar::createInstance | ( | TimeZone * | zoneToAdopt,
|  | UErrorCode & | success
| ) |  |
| inline static

Creates a Calendar using the given timezone and the default locale.

The Calendar takes ownership of zoneToAdopt; the client must not delete it.

Parameters

  zoneToAdopt | The given timezone to be adopted.
  success | Indicates the success/failure of Calendar creation. Filled in with U_ZERO_ERROR if created successfully, set to a failure result otherwise.

Returns
  A Calendar if created successfully. nullptr otherwise.

Stable:
  ICU 2.0

Definition at line 2516 of file calendar.h.

## ◆ createInstance() [6/6]

static Calendar* icu::Calendar::createInstance | ( | UErrorCode & | success | ) |
| static

Creates a Calendar using the default timezone and locale.

Clients are responsible for deleting the object returned.

Parameters

  success | Indicates the success/failure of Calendar creation. Filled in with U_ZERO_ERROR if created successfully, set to a failure result otherwise. U_MISSING_RESOURCE_ERROR will be returned if the resource data requests a calendar type which has not been installed.

Returns
  A Calendar if created successfully. nullptr otherwise.

Stable:
  ICU 2.0

## ◆ defaultCenturyStart()

virtual UDate icu::Calendar::defaultCenturyStart | ( |  | ) | const
| pure virtual

Returns
  the start of the default century, as a UDate

Internal:
  Do not use. This API is for internal use only.

Implemented in icu::GregorianCalendar.

## ◆ defaultCenturyStartYear()

virtual int32_t icu::Calendar::defaultCenturyStartYear | ( |  | ) | const
| pure virtual

Returns
  the beginning year of the default century, as a year

Internal:
  Do not use. This API is for internal use only.

Implemented in icu::GregorianCalendar.

## ◆ equals()

UBool icu::Calendar::equals | ( | const Calendar & | when,
|  | UErrorCode & | status
| ) |  | const

Compares the Calendar time, whereas Calendar::operator== compares the equality of Calendar objects.

Parameters

  when | The Calendar to be compared with this Calendar. Although this is a const parameter, the object may be modified physically (semantically const).
  status | Output param set to success/failure code on exit. If any value previously set in the time field is invalid or restricted by leniency, this will be set to an error status.

Returns
  True if the current time of this Calendar is equal to the time of Calendar when; false otherwise.

Stable:
  ICU 2.0

## ◆ fieldDifference() [1/2]

virtual int32_t icu::Calendar::fieldDifference | ( | UDate | when,
|  | EDateFields | field,
|  | UErrorCode & | status
| ) |  |
| virtual

Return the difference between the given time and the time this calendar object is set to.

If this calendar is set before the given time, the returned value will be positive. If this calendar is set after the given time, the returned value will be negative. The `field` parameter specifies the units of the return value. For example, if `fieldDifference(when, Calendar::MONTH)` returns 3, then this calendar is set to 3 months before `when`, and possibly some addition time less than one month.

As a side effect of this call, this calendar is advanced toward `when` by the given amount. That is, calling this method has the side effect of calling `add(field, n)`, where `n` is the return value.

Usage: To use this method, call it first with the largest field of interest, then with progressively smaller fields. For example:

    int y = cal->fieldDifference(when, Calendar::YEAR, err);
    int m = cal->fieldDifference(when, Calendar::MONTH, err);
    int d = cal->fieldDifference(when, Calendar::DATE, err);

computes the difference between `cal` and `when` in years, months, and days.

Note: `fieldDifference()` is asymmetrical. That is, in the following code:

    cal->setTime(date1, err);
    int m1 = cal->fieldDifference(date2, Calendar::MONTH, err);
    int d1 = cal->fieldDifference(date2, Calendar::DATE, err);
    cal->setTime(date2, err);
    int m2 = cal->fieldDifference(date1, Calendar::MONTH, err);
    int d2 = cal->fieldDifference(date1, Calendar::DATE, err);

one might expect that `m1 == -m2 && d1 == -d2`. However, this is not generally the case, because of irregularities in the underlying calendar system (e.g., the Gregorian calendar has a varying number of days per month).

Parameters

  when | the date to compare this calendar's time to
  field | the field in which to compute the result
  status | Output param set to success/failure code on exit. If any value previously set in the time field is invalid, this will be set to an error status.

Returns
  the difference, either positive or negative, between this calendar's time and `when`, in terms of `field`.

Deprecated:
  ICU 2.6. Use fieldDifference(UDate when, UCalendarDateFields field, UErrorCode& status).

## ◆ fieldDifference() [2/2]

virtual int32_t icu::Calendar::fieldDifference | ( | UDate | when,
|  | UCalendarDateFields | field,
|  | UErrorCode & | status
| ) |  |
| virtual

Return the difference between the given time and the time this calendar object is set to.

If this calendar is set before the given time, the returned value will be positive. If this calendar is set after the given time, the returned value will be negative. The `field` parameter specifies the units of the return value. For example, if `fieldDifference(when, Calendar::MONTH)` returns 3, then this calendar is set to 3 months before `when`, and possibly some addition time less than one month.

As a side effect of this call, this calendar is advanced toward `when` by the given amount. That is, calling this method has the side effect of calling `add(field, n)`, where `n` is the return value.

Usage: To use this method, call it first with the largest field of interest, then with progressively smaller fields. For example:

    int y = cal->fieldDifference(when, Calendar::YEAR, err);
    int m = cal->fieldDifference(when, Calendar::MONTH, err);
    int d = cal->fieldDifference(when, Calendar::DATE, err);

computes the difference between `cal` and `when` in years, months, and days.

Note: `fieldDifference()` is asymmetrical. That is, in the following code:

    cal->setTime(date1, err);
    int m1 = cal->fieldDifference(date2, Calendar::MONTH, err);
    int d1 = cal->fieldDifference(date2, Calendar::DATE, err);
    cal->setTime(date2, err);
    int m2 = cal->fieldDifference(date1, Calendar::MONTH, err);
    int d2 = cal->fieldDifference(date1, Calendar::DATE, err);

one might expect that `m1 == -m2 && d1 == -d2`. However, this is not generally the case, because of irregularities in the underlying calendar system (e.g., the Gregorian calendar has a varying number of days per month).

Parameters

  when | the date to compare this calendar's time to
  field | the field in which to compute the result
  status | Output param set to success/failure code on exit. If any value previously set in the time field is invalid, this will be set to an error status.

Returns
  the difference, either positive or negative, between this calendar's time and `when`, in terms of `field`.

Stable:
  ICU 2.6.

## ◆ get()

int32_t icu::Calendar::get | ( | UCalendarDateFields | field,
|  | UErrorCode & | status
| ) |  | const

Gets the value for a given time field.

Recalculate the current time field values if the time value has been changed by a call to setTime(). Return zero for unset fields if any fields have been explicitly set by a call to set(). To force a recomputation of all fields regardless of the previous state, call complete(). This method is semantically const, but may alter the object in memory.

Parameters

  field | The given time field.
  status | Fill-in parameter which receives the status of the operation.

Returns
  The value for the given time field, or zero if the field is unset, and set() has been called for any other field.

Stable:
  ICU 2.6.

## ◆ getActualMaximum()

virtual int32_t icu::Calendar::getActualMaximum | ( | UCalendarDateFields | field,
|  | UErrorCode & | status
| ) |  | const
| virtual

Return the maximum value that this field could have, given the current date.

For example, with the date "Feb 3, 1997" and the DAY_OF_MONTH field, the actual maximum would be 28; for "Feb 3, 1996" it s 29. Similarly for a Hebrew calendar, for some years the actual maximum for MONTH is 12, and for others 13.

The version of this function on Calendar uses an iterative algorithm to determine the actual maximum value for the field. There is almost always a more efficient way to accomplish this (in most cases, you can simply return getMaximum()). GregorianCalendar overrides this function with a more efficient implementation.

Parameters

  field | the field to determine the maximum of
  status | Fill-in parameter which receives the status of this operation.

Returns
  the maximum of the given field for the current date of this Calendar

Stable:
  ICU 2.6.

Reimplemented in icu::GregorianCalendar.

## ◆ getActualMinimum() [1/2]

int32_t icu::Calendar::getActualMinimum | ( | EDateFields | field,
|  | UErrorCode & | status
| ) |  | const

Return the minimum value that this field could have, given the current date.

For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum().

The version of this function on Calendar uses an iterative algorithm to determine the actual minimum value for the field. There is almost always a more efficient way to accomplish this (in most cases, you can simply return getMinimum()). GregorianCalendar overrides this function with a more efficient implementation.

Parameters

  field | the field to determine the minimum of
  status | Fill-in parameter which receives the status of this operation.

Returns
  the minimum of the given field for the current date of this Calendar

Deprecated:
  ICU 2.6. Use getActualMinimum(UCalendarDateFields field, UErrorCode& status) instead.

## ◆ getActualMinimum() [2/2]

virtual int32_t icu::Calendar::getActualMinimum | ( | UCalendarDateFields | field,
|  | UErrorCode & | status
| ) |  | const
| virtual

Return the minimum value that this field could have, given the current date.

For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum().

The version of this function on Calendar uses an iterative algorithm to determine the actual minimum value for the field. There is almost always a more efficient way to accomplish this (in most cases, you can simply return getMinimum()). GregorianCalendar overrides this function with a more efficient implementation.

Parameters

  field | the field to determine the minimum of
  status | Fill-in parameter which receives the status of this operation.

Returns
  the minimum of the given field for the current date of this Calendar

Stable:
  ICU 2.6.

Reimplemented in icu::GregorianCalendar.

## ◆ getAvailableLocales() [1/2]

static const Locale* icu::Calendar::getAvailableLocales | ( | int32_t & | count | ) |
| static

Returns a list of the locales for which Calendars are installed.

Parameters

  count | Number of locales returned.

Returns
  An array of Locale objects representing the set of locales for which Calendars are installed. The system retains ownership of this list; the caller must NOT delete it. Does not include user-registered Calendars.

Stable:
  ICU 2.0

## ◆ getAvailableLocales() [2/2]

static StringEnumeration* icu::Calendar::getAvailableLocales | ( | void |  | ) |
| static

INTERNAL FOR 2.6 – Registration.

Return a StringEnumeration over the locales available at the time of the call, including registered locales.

Returns
  a StringEnumeration over the locales available at the time of the call

Internal:
  Do not use. This API is for internal use only.

## ◆ getCalendarTypeFromLocale()

static void icu::Calendar::getCalendarTypeFromLocale | ( | const Locale & | locale,
|  | char * | typeBuffer,
|  | int32_t | typeBufferSize,
|  | UErrorCode & | status
| ) |  |
| static

Get the calendar type for given locale.

Parameters

  locale | the locale
  typeBuffer | calendar type returned here
  typeBufferSize | The size of typeBuffer in bytes. If the type can't fit in the buffer, this method sets status to U_BUFFER_OVERFLOW_ERROR
  status | error, if any, returned here.

Internal:
  Do not use. This API is for internal use only. For ICU use only.

## ◆ getDayOfWeekType()

virtual UCalendarWeekdayType icu::Calendar::getDayOfWeekType | ( | UCalendarDaysOfWeek | dayOfWeek,
|  | UErrorCode & | status
| ) |  | const
| virtual

Returns whether the given day of the week is a weekday, a weekend day, or a day that transitions from one to the other, for the locale and calendar system associated with this Calendar (the locale's region is often the most determinant factor).

If a transition occurs at midnight, then the days before and after the transition will have the type UCAL_WEEKDAY or UCAL_WEEKEND. If a transition occurs at a time other than midnight, then the day of the transition will have the type UCAL_WEEKEND_ONSET or UCAL_WEEKEND_CEASE. In this case, the method getWeekendTransition() will return the point of transition.

Parameters

  dayOfWeek | The day of the week whose type is desired (UCAL_SUNDAY..UCAL_SATURDAY).
  status | The error code for the operation.

Returns
  The UCalendarWeekdayType for the day of the week.

Stable:
  ICU 4.4

## ◆ getDefaultDayInMonth()

virtual int32_t icu::Calendar::getDefaultDayInMonth | ( | int32_t | eyear,
|  | int32_t | month
| ) |  |
| protected virtual

Called by computeJulianDay.

Returns the default day (1-based) for the month, taking currently-set year and era into account. Defaults to 1 for Gregorian.

Parameters

  eyear | the extended year
  month | the month in the year

Internal:
  Do not use. This API is for internal use only.

## ◆ getDefaultMonthInYear()

virtual int32_t icu::Calendar::getDefaultMonthInYear | ( | int32_t | eyear | ) |
| protected virtual

Called by computeJulianDay.

Returns the default month (0-based) for the year, taking year and era into account. Defaults to 0 for Gregorian, which doesn't care.

Parameters

  eyear | The extended year

Internal:
  Do not use. This API is for internal use only.

## ◆ getDynamicClassID()

virtual UClassID icu::Calendar::getDynamicClassID | ( | void |  | ) | const
| override pure virtual

Returns a unique class ID POLYMORPHICALLY.

Pure virtual method. This method is to implement a simple version of RTTI, since not all C++ compilers support genuine RTTI. Polymorphic operator==() and clone() methods call this method.

Concrete subclasses of Calendar must implement getDynamicClassID() and also a static method and data member:

     static UClassID getStaticClassID() { return (UClassID)&amp;fgClassID; }
     static char fgClassID;

Returns
  The class ID for this object. All objects of a given class have the same class ID. Objects of other classes have different class IDs.

Stable:
  ICU 2.0

Reimplemented from icu::UObject.

Implemented in icu::GregorianCalendar.

## ◆ getFieldResolutionTable()

virtual const UFieldResolutionTable* icu::Calendar::getFieldResolutionTable | ( |  | ) | const
| protected virtual

Internal:
  Do not use.

This API is for internal use only.

## ◆ getFirstDayOfWeek() [1/2]

UCalendarDaysOfWeek icu::Calendar::getFirstDayOfWeek | ( | UErrorCode & | status | ) | const

Gets what the first day of the week is; e.g., Sunday in US, Monday in France.

Parameters

  status | error code

Returns
  The first day of the week.

Stable:
  ICU 2.6

## ◆ getFirstDayOfWeek() [2/2]

EDaysOfWeek icu::Calendar::getFirstDayOfWeek | ( | void |  | ) | const

Gets what the first day of the week is; e.g., Sunday in US, Monday in France.

Returns
  The first day of the week.

Deprecated:
  ICU 2.6 use the overload with error code

## ◆ getGreatestMinimum() [1/2]

virtual int32_t icu::Calendar::getGreatestMinimum | ( | EDateFields | field | ) | const
| virtual

Gets the highest minimum value for the given field if varies.

Otherwise same as getMinimum(). For Gregorian, no difference.

Parameters

  field | The given time field.

Returns
  The highest minimum value for the given time field.

Deprecated:
  ICU 2.6. Use getGreatestMinimum(UCalendarDateFields field) instead.

## ◆ getGreatestMinimum() [2/2]

virtual int32_t icu::Calendar::getGreatestMinimum | ( | UCalendarDateFields | field | ) | const
| virtual

Gets the highest minimum value for the given field if varies.

Otherwise same as getMinimum(). For Gregorian, no difference.

Parameters

  field | The given time field.

Returns
  The highest minimum value for the given time field.

Stable:
  ICU 2.6.

## ◆ getGregorianDayOfMonth()

int32_t icu::Calendar::getGregorianDayOfMonth | ( |  | ) | const
| inline protected

Return the day of month (1-based) on the Gregorian calendar as computed by `computeGregorianFields()`.

Internal:
  Do not use. This API is for internal use only.

Definition at line 2016 of file calendar.h.

## ◆ getGregorianDayOfYear()

int32_t icu::Calendar::getGregorianDayOfYear | ( |  | ) | const
| inline protected

Return the day of year (1-based) on the Gregorian calendar as computed by `computeGregorianFields()`.

Internal:
  Do not use. This API is for internal use only.

Definition at line 2007 of file calendar.h.

## ◆ getGregorianMonth()

int32_t icu::Calendar::getGregorianMonth | ( |  | ) | const
| inline protected

Return the month (0-based) on the Gregorian calendar as computed by `computeGregorianFields()`.

Internal:
  Do not use. This API is for internal use only.

Definition at line 1998 of file calendar.h.

## ◆ getGregorianYear()

int32_t icu::Calendar::getGregorianYear | ( |  | ) | const
| inline protected

Return the extended year on the Gregorian calendar as computed by `computeGregorianFields()`.

Internal:
  Do not use. This API is for internal use only.

Definition at line 1989 of file calendar.h.

## ◆ getKeywordValuesForLocale()

static StringEnumeration* icu::Calendar::getKeywordValuesForLocale | ( | const char * | key,
|  | const Locale & | locale,
|  | UBool | commonlyUsed,
|  | UErrorCode & | status
| ) |  |
| static

Given a key and a locale, returns an array of string values in a preferred order that would make a difference.

These are all and only those values where the open (creation) of the service with the locale formed from the input locale plus input keyword and that value has different behavior than creation with the input locale alone.

Parameters

  key | one of the keys supported by this service. For now, only "calendar" is supported.
  locale | the locale
  commonlyUsed | if set to true it will return only commonly used values with the given locale in preferred order. Otherwise, it will return all the available values for the locale.
  status | ICU Error Code

Returns
  a string enumeration over keyword values for the given key and the locale.

Stable:
  ICU 4.2

## ◆ getLeastMaximum() [1/2]

virtual int32_t icu::Calendar::getLeastMaximum | ( | EDateFields | field | ) | const
| virtual

Gets the lowest maximum value for the given field if varies.

Otherwise same as getMaximum(). e.g., for Gregorian DAY_OF_MONTH, 28.

Parameters

  field | The given time field.

Returns
  The lowest maximum value for the given time field.

Deprecated:
  ICU 2.6. Use getLeastMaximum(UCalendarDateFields field) instead.

## ◆ getLeastMaximum() [2/2]

virtual int32_t icu::Calendar::getLeastMaximum | ( | UCalendarDateFields | field | ) | const
| virtual

Gets the lowest maximum value for the given field if varies.

Otherwise same as getMaximum(). e.g., for Gregorian DAY_OF_MONTH, 28.

Parameters

  field | The given time field.

Returns
  The lowest maximum value for the given time field.

Stable:
  ICU 2.6.

## ◆ getLimit()

virtual int32_t icu::Calendar::getLimit | ( | UCalendarDateFields | field,
|  | ELimitType | limitType
| ) |  | const
| protected virtual

Return a limit for a field.

Parameters

  field | the field, from `0..UCAL_MAX_FIELD`
  limitType | the type specifier for the limit

See also
  ELimitType

Internal:
  Do not use. This API is for internal use only.

## ◆ getLocalDOW()

int32_t icu::Calendar::getLocalDOW | ( |  | ) |
| protected

returns the local DOW, valid range 0..6

Internal:
  Do not use.

This API is for internal use only.

## ◆ getLocale()

Locale icu::Calendar::getLocale | ( | ULocDataLocaleType | type,
|  | UErrorCode & | status
| ) |  | const

Get the locale for this calendar object.

You can choose between valid and actual locale.

Parameters

  type | type of the locale we're looking for (valid or actual)
  status | error code for the operation

Returns
  the locale

Stable:
  ICU 2.8

## ◆ getLocaleID()

const char* icu::Calendar::getLocaleID | ( | ULocDataLocaleType | type,
|  | UErrorCode & | status
| ) |  | const

Get the locale for this calendar object.

You can choose between valid and actual locale.

Parameters

  type | type of the locale we're looking for (valid or actual)
  status | error code for the operation

Returns
  the locale

Internal:
  Do not use. This API is for internal use only.

## ◆ getMaximum() [1/2]

virtual int32_t icu::Calendar::getMaximum | ( | EDateFields | field | ) | const
| virtual

Gets the maximum value for the given time field.

e.g. for Gregorian DAY_OF_MONTH, 31.

Parameters

  field | The given time field.

Returns
  The maximum value for the given time field.

Deprecated:
  ICU 2.6. Use getMaximum(UCalendarDateFields field) instead.

## ◆ getMaximum() [2/2]

virtual int32_t icu::Calendar::getMaximum | ( | UCalendarDateFields | field | ) | const
| virtual

Gets the maximum value for the given time field.

e.g. for Gregorian DAY_OF_MONTH, 31.

Parameters

  field | The given time field.

Returns
  The maximum value for the given time field.

Stable:
  ICU 2.6.

## ◆ getMinimalDaysInFirstWeek()

uint8_t icu::Calendar::getMinimalDaysInFirstWeek | ( | void |  | ) | const

Gets what the minimal days required in the first week of the year are; e.g., if the first week is defined as one that contains the first day of the first month of a year, getMinimalDaysInFirstWeek returns 1.

If the minimal days required must be a full week, getMinimalDaysInFirstWeek returns 7.

Returns
  The minimal days required in the first week of the year.

Stable:
  ICU 2.0

## ◆ getMinimum() [1/2]

virtual int32_t icu::Calendar::getMinimum | ( | EDateFields | field | ) | const
| virtual

Gets the minimum value for the given time field.

e.g., for Gregorian DAY_OF_MONTH, 1.

Parameters

  field | The given time field.

Returns
  The minimum value for the given time field.

Deprecated:
  ICU 2.6. Use getMinimum(UCalendarDateFields field) instead.

## ◆ getMinimum() [2/2]

virtual int32_t icu::Calendar::getMinimum | ( | UCalendarDateFields | field | ) | const
| virtual

Gets the minimum value for the given time field.

e.g., for Gregorian DAY_OF_MONTH, 1.

Parameters

  field | The given time field.

Returns
  The minimum value for the given time field.

Stable:
  ICU 2.6.

## ◆ getNow()

static UDate icu::Calendar::getNow | ( | void |  | ) |
| static

Returns the current UTC (GMT) time measured in milliseconds since 0:00:00 on 1/1/70 (derived from the system time).

Returns
  The current UTC time in milliseconds.

Stable:
  ICU 2.0

## ◆ getRelatedYear()

virtual int32_t icu::Calendar::getRelatedYear | ( | UErrorCode & | status | ) | const
| virtual

Returns
  The related Gregorian year; will be obtained by modifying the value obtained by get from UCAL_EXTENDED_YEAR field

Internal:
  Do not use. This API is for internal use only.

## ◆ getRepeatedWallTimeOption()

UCalendarWallTimeOption icu::Calendar::getRepeatedWallTimeOption | ( | void |  | ) | const

Gets the behavior for handling wall time repeating multiple times at negative time zone offset transitions.

Returns
  the behavior for handling repeating wall time, either `UCAL_WALLTIME_FIRST` or `UCAL_WALLTIME_LAST`.

See also
  setRepeatedWallTimeOption

Stable:
  ICU 49

## ◆ getSkippedWallTimeOption()

UCalendarWallTimeOption icu::Calendar::getSkippedWallTimeOption | ( | void |  | ) | const

Gets the behavior for handling skipped wall time at positive time zone offset transitions.

Returns
  the behavior for handling skipped wall time, one of `UCAL_WALLTIME_FIRST`, `UCAL_WALLTIME_LAST` and `UCAL_WALLTIME_NEXT_VALID`.

See also
  setSkippedWallTimeOption

Stable:
  ICU 49

## ◆ getTemporalMonthCode()

virtual const char* icu::Calendar::getTemporalMonthCode | ( | UErrorCode & | status | ) | const
| virtual

Gets The Temporal monthCode value corresponding to the month for the date.

The value is a string identifier that starts with the literal grapheme "M" followed by two graphemes representing the zero-padded month number of the current month in a normal (non-leap) year and suffixed by an optional literal grapheme "L" if this is a leap month in a lunisolar calendar. The 25 possible values are "M01" .. "M13" and "M01L" .. "M12L". For the Hebrew calendar, the values are "M01" .. "M12" for non-leap year, and "M01" .. "M05", "M05L", "M06" .. "M12" for leap year. For the Chinese calendar, the values are "M01" .. "M12" for non-leap year and in leap year with another monthCode in "M01L" .. "M12L". For Coptic and Ethiopian calendar, the Temporal monthCode values for any years are "M01" to "M13".

Parameters

  status | ICU Error Code

Returns
  One of 25 possible strings in {"M01".."M13", "M01L".."M12L"}.

Draft:
  This API may be changed in the future versions and was introduced in ICU 73

## ◆ getTime()

UDate icu::Calendar::getTime | ( | UErrorCode & | status | ) | const
| inline

Gets this Calendar's time as milliseconds.

May involve recalculation of time due to previous calls to set time field values. The time specified is non-local UTC (GMT) time. Although this method is const, this object may actually be changed (semantically const).

Parameters

  status | Output param set to success/failure code on exit. If any value previously set in the time field is invalid or restricted by leniency, this will be set to an error status.

Returns
  The current time in UTC (GMT) time, or zero if the operation failed.

Stable:
  ICU 2.0

Definition at line 431 of file calendar.h.

## ◆ getTimeInMillis()

double icu::Calendar::getTimeInMillis | ( | UErrorCode & | status | ) | const
| protected

Gets this Calendar's current time as a long.

Parameters

  status | Output param set to success/failure code on exit. If any value previously set in the time field is invalid or restricted by leniency, this will be set to an error status.

Returns
  the current time as UTC milliseconds from the epoch.

Stable:
  ICU 2.0

## ◆ getTimeZone()

const TimeZone& icu::Calendar::getTimeZone | ( | void |  | ) | const

Returns a reference to the time zone owned by this calendar.

The returned reference is only valid until clients make another call to adoptTimeZone or setTimeZone, or this Calendar is destroyed.

Returns
  The time zone object associated with this calendar.

Stable:
  ICU 2.0

## ◆ getType()

virtual const char* icu::Calendar::getType | ( |  | ) | const
| pure virtual

Returns the calendar type name string for this Calendar object.

The returned string is the legacy ICU calendar attribute value, for example, "gregorian" or "japanese".

See type="old type name" for the calendar attribute of locale IDs at http://www.unicode.org/reports/tr35/#Key_Type_Definitions

Sample code for getting the LDML/BCP 47 calendar key value:

const char *calType = cal->getType();
if (0 == strcmp(calType, "unknown")) {
// deal with unknown calendar type
} else {
string localeID("root@calendar=");
localeID.append(calType);
char langTag[100];
UErrorCode errorCode = U_ZERO_ERROR;
int32_t length = uloc_toLanguageTag(localeID.c_str(), langTag, (int32_t)sizeof(langTag), true, &errorCode);
if (U_FAILURE(errorCode)) {
// deal with errors & overflow
}
string lang(langTag, length);
size_t caPos = lang.find("-ca-");
lang.erase(0, caPos + 4);
// lang now contains the LDML calendar type
}
uloc_toLanguageTag
U_CAPI int32_t uloc_toLanguageTag(const char *localeID, char *langtag, int32_t langtagCapacity, UBool strict, UErrorCode *err)
Returns a well-formed language tag for this locale ID.
UErrorCode
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:415
U_ZERO_ERROR
@ U_ZERO_ERROR
No error, no warning.
Definition: utypes.h:449
U_FAILURE
#define U_FAILURE(x)
Does the error code indicate a failure?
Definition: utypes.h:717

Returns
  legacy calendar type name string

Stable:
  ICU 49

Implemented in icu::GregorianCalendar.

## ◆ getWeekendTransition()

virtual int32_t icu::Calendar::getWeekendTransition | ( | UCalendarDaysOfWeek | dayOfWeek,
|  | UErrorCode & | status
| ) |  | const
| virtual

Returns the time during the day at which the weekend begins or ends in this calendar system.

If getDayOfWeekType() returns UCAL_WEEKEND_ONSET for the specified dayOfWeek, return the time at which the weekend begins. If getDayOfWeekType() returns UCAL_WEEKEND_CEASE for the specified dayOfWeek, return the time at which the weekend ends. If getDayOfWeekType() returns some other UCalendarWeekdayType for the specified dayOfWeek, is it an error condition (U_ILLEGAL_ARGUMENT_ERROR).

Parameters

  dayOfWeek | The day of the week for which the weekend transition time is desired (UCAL_SUNDAY..UCAL_SATURDAY).
  status | The error code for the operation.

Returns
  The milliseconds after midnight at which the weekend begins or ends.

Stable:
  ICU 4.4

## ◆ handleComputeFields()

virtual void icu::Calendar::handleComputeFields | ( | int32_t | julianDay,
|  | UErrorCode & | status
| ) |  |
| protected virtual

Subclasses may override this method to compute several fields specific to each calendar system.

These are:

- ERA
- YEAR
- MONTH
- DAY_OF_MONTH
- DAY_OF_YEAR
- EXTENDED_YEAR

Subclasses can refer to the DAY_OF_WEEK and DOW_LOCAL fields, which will be set when this method is called. Subclasses can also call the getGregorianXxx() methods to obtain Gregorian calendar equivalents for the given Julian day.

In addition, subclasses should compute any subclass-specific fields, that is, fields from BASE_FIELD_COUNT to getFieldCount() - 1.

The default implementation in `Calendar` implements a pure proleptic Gregorian calendar.

Internal:
  Do not use. This API is for internal use only.

Reimplemented in icu::GregorianCalendar.

## ◆ handleComputeJulianDay()

virtual int32_t icu::Calendar::handleComputeJulianDay | ( | UCalendarDateFields | bestField | ) |
| protected virtual

Subclasses may override this.

This method calls handleGetMonthLength() to obtain the calendar-specific month length.

Parameters

  bestField | which field to use to calculate the date

Returns
  julian day specified by calendar fields.

Internal:
  Do not use. This API is for internal use only.

Reimplemented in icu::GregorianCalendar.

## ◆ handleComputeMonthStart()

virtual int32_t icu::Calendar::handleComputeMonthStart | ( | int32_t | eyear,
|  | int32_t | month,
|  | UBool | useMonth
| ) |  | const
| protected pure virtual

Return the Julian day number of day before the first day of the given month in the given extended year.

Subclasses should override this method to implement their calendar system.

Parameters

  eyear | the extended year
  month | the zero-based month, or 0 if useMonth is false
  useMonth | if false, compute the day before the first day of the given year, otherwise, compute the day before the first day of the given month

Returns
  the Julian day number of the day before the first day of the given month and year

Internal:
  Do not use. This API is for internal use only.

Implemented in icu::GregorianCalendar.

## ◆ handleGetExtendedYear()

virtual int32_t icu::Calendar::handleGetExtendedYear | ( |  | ) |
| protected pure virtual

Return the extended year defined by the current fields.

This will use the UCAL_EXTENDED_YEAR field or the UCAL_YEAR and supra-year fields (such as UCAL_ERA) specific to the calendar system, depending on which set of fields is newer.

Returns
  the extended year

Internal:
  Do not use. This API is for internal use only.

Implemented in icu::GregorianCalendar.

## ◆ handleGetExtendedYearFromWeekFields()

virtual int32_t icu::Calendar::handleGetExtendedYearFromWeekFields | ( | int32_t | yearWoy,
|  | int32_t | woy
| ) |  |
| protected virtual

Subclasses must override this to convert from week fields (YEAR_WOY and WEEK_OF_YEAR) to an extended year in the case where YEAR, EXTENDED_YEAR are not set.

The Calendar implementation assumes yearWoy is in extended gregorian form

Returns
  the extended year, UCAL_EXTENDED_YEAR

Internal:
  Do not use. This API is for internal use only.

Reimplemented in icu::GregorianCalendar.

## ◆ handleGetLimit()

virtual int32_t icu::Calendar::handleGetLimit | ( | UCalendarDateFields | field,
|  | ELimitType | limitType
| ) |  | const
| protected pure virtual

Subclass API for defining limits of different types.

Subclasses must implement this method to return limits for the following fields:

    UCAL_ERA
    UCAL_YEAR
    UCAL_MONTH
    UCAL_WEEK_OF_YEAR
    UCAL_WEEK_OF_MONTH
    UCAL_DATE (DAY_OF_MONTH on Java)
    UCAL_DAY_OF_YEAR
    UCAL_DAY_OF_WEEK_IN_MONTH
    UCAL_YEAR_WOY
    UCAL_EXTENDED_YEAR

Parameters

  field | one of the above field numbers
  limitType | one of `MINIMUM`, `GREATEST_MINIMUM`, `LEAST_MAXIMUM`, or `MAXIMUM`

Internal:
  Do not use. This API is for internal use only.

Implemented in icu::GregorianCalendar.

## ◆ handleGetMonthLength()

virtual int32_t icu::Calendar::handleGetMonthLength | ( | int32_t | extendedYear,
|  | int32_t | month
| ) |  | const
| protected virtual

Return the number of days in the given month of the given extended year of this calendar system.

Subclasses should override this method if they can provide a more correct or more efficient implementation than the default implementation in Calendar.

Internal:
  Do not use. This API is for internal use only.

Reimplemented in icu::GregorianCalendar.

## ◆ handleGetYearLength()

virtual int32_t icu::Calendar::handleGetYearLength | ( | int32_t | eyear | ) | const
| protected virtual

Return the number of days in the given extended year of this calendar system.

Subclasses should override this method if they can provide a more correct or more efficient implementation than the default implementation in Calendar.

Stable:
  ICU 2.0

Reimplemented in icu::GregorianCalendar.

## ◆ haveDefaultCentury()

virtual UBool icu::Calendar::haveDefaultCentury | ( |  | ) | const
| pure virtual

Returns
  true if this calendar has a default century (i.e. 03 -> 2003)

Internal:
  Do not use. This API is for internal use only.

Implemented in icu::GregorianCalendar.

## ◆ inDaylightTime()

virtual UBool icu::Calendar::inDaylightTime | ( | UErrorCode & | status | ) | const
| virtual

Queries if the current date for this Calendar is in Daylight Savings Time.

Parameters

  status | Fill-in parameter which receives the status of this operation.

Returns
  True if the current date for this Calendar is in Daylight Savings Time, false, otherwise.

Stable:
  ICU 2.0

## ◆ inTemporalLeapYear()

virtual bool icu::Calendar::inTemporalLeapYear | ( | UErrorCode & | status | ) | const
| virtual

Returns true if the date is in a leap year.

Recalculate the current time field values if the time value has been changed by a call to * setTime(). This method is semantically const, but may alter the object in memory. A "leap year" is a year that contains more days than other years (for solar or lunar calendars) or more months than other years (for lunisolar calendars like Hebrew or Chinese), as defined in the ECMAScript Temporal proposal.

Parameters

  status | ICU Error Code

Returns
  True if the date in the fields is in a Temporal proposal defined leap year. False otherwise.

Draft:
  This API may be changed in the future versions and was introduced in ICU 73

## ◆ internalGet() [1/3]

int32_t icu::Calendar::internalGet | ( | EDateFields | field | ) | const
| inline protected

Gets the value for a given time field.

Subclasses can use this function to get field values without forcing recomputation of time.

Parameters

  field | The given time field.

Returns
  The value for the given time field.

Deprecated:
  ICU 2.6. Use internalGet(UCalendarDateFields field) instead.

Definition at line 1528 of file calendar.h.

## ◆ internalGet() [2/3]

int32_t icu::Calendar::internalGet | ( | UCalendarDateFields | field | ) | const
| inline protected

Gets the value for a given time field.

Subclasses can use this function to get field values without forcing recomputation of time.

Parameters

  field | The given time field.

Returns
  The value for the given time field.

Internal:
  Do not use. This API is for internal use only.

Definition at line 1552 of file calendar.h.

## ◆ internalGet() [3/3]

int32_t icu::Calendar::internalGet | ( | UCalendarDateFields | field,
|  | int32_t | defaultValue
| ) |  | const
| inline protected

Gets the value for a given time field.

Subclasses can use this function to get field values without forcing recomputation of time. If the field's stamp is UNSET, the defaultValue is used.

Parameters

  field | The given time field.
  defaultValue | a default value used if the field is unset.

Returns
  The value for the given time field.

Internal:
  Do not use. This API is for internal use only.

Definition at line 1542 of file calendar.h.

## ◆ internalGetMonth() [1/2]

virtual int32_t icu::Calendar::internalGetMonth | ( |  | ) | const
| protected virtual

Use this function instead of internalGet(UCAL_MONTH).

The implementation check the timestamp of UCAL_MONTH and UCAL_ORDINAL_MONTH and use the one set later. The subclass should override it to conver the value of UCAL_ORDINAL_MONTH to UCAL_MONTH correctly if UCAL_ORDINAL_MONTH has higher priority.

Returns
  The value for the UCAL_MONTH.

Internal:
  Do not use. This API is for internal use only.

## ◆ internalGetMonth() [2/2]

virtual int32_t icu::Calendar::internalGetMonth | ( | int32_t | defaultValue | ) | const
| protected virtual

Use this function instead of internalGet(UCAL_MONTH, defaultValue).

The implementation check the timestamp of UCAL_MONTH and UCAL_ORDINAL_MONTH and use the one set later. The subclass should override it to conver the value of UCAL_ORDINAL_MONTH to UCAL_MONTH correctly if UCAL_ORDINAL_MONTH has higher priority.

Parameters

  defaultValue | a default value used if the UCAL_MONTH and UCAL_ORDINAL are both unset.

Returns
  The value for the UCAL_MONTH.

Internal:
  Do not use. This API is for internal use only.

## ◆ internalGetTime()

UDate icu::Calendar::internalGetTime | ( | void |  | ) | const
| inline protected

Get the current time without recomputing.

Returns
  the current time without recomputing.

Stable:
  ICU 2.0

Definition at line 1915 of file calendar.h.

## ◆ internalSet() [1/2]

void icu::Calendar::internalSet | ( | EDateFields | field,
|  | int32_t | value
| ) |  |
| protected

Sets the value for a given time field.

This is a fast internal method for subclasses. It does not affect the areFieldsInSync, isTimeSet, or areAllFieldsSet flags.

Parameters

  field | The given time field.
  value | The value for the given time field.

Deprecated:
  ICU 2.6. Use internalSet(UCalendarDateFields field, int32_t value) instead.

## ◆ internalSet() [2/2]

void icu::Calendar::internalSet | ( | UCalendarDateFields | field,
|  | int32_t | value
| ) |  |
| inline protected

Sets the value for a given time field.

Fast method for subclasses.

This is a fast internal method for subclasses. It does not affect the areFieldsInSync, isTimeSet, or areAllFieldsSet flags.

Parameters

  field | The given time field.
  value | The value for the given time field.

Stable:
  ICU 2.6.

The caller must maintain fUserSetDSTOffset and fUserSetZoneOffset, as well as the isSet[] array.

Definition at line 2547 of file calendar.h.

## ◆ internalSetTime()

void icu::Calendar::internalSetTime | ( | UDate | time | ) |
| inline protected

Set the current time without affecting flags or fields.

Parameters

  time | The time to be set

Returns
  the current time without recomputing.

Stable:
  ICU 2.0

Definition at line 1924 of file calendar.h.

## ◆ isEquivalentTo()

virtual UBool icu::Calendar::isEquivalentTo | ( | const Calendar & | other | ) | const
| virtual

Returns true if the given Calendar object is equivalent to this one.

An equivalent Calendar will behave exactly as this one does, but it may be set to a different time. By contrast, for the operator==() method to return true, the other Calendar must be set to the same time.

Parameters

  other | the Calendar to be compared with this Calendar

Stable:
  ICU 2.4

Reimplemented in icu::GregorianCalendar.

## ◆ isLenient()

UBool icu::Calendar::isLenient | ( | void |  | ) | const

Tells whether date/time interpretation is to be lenient.

Returns
  True tells that date/time interpretation is to be lenient.

Stable:
  ICU 2.0

## ◆ isSet()

UBool icu::Calendar::isSet | ( | UCalendarDateFields | field | ) | const

Determines if the given time field has a value set.

This can affect in the resolving of time in Calendar. Unset fields have a value of zero, by definition.

Parameters

  field | The given time field.

Returns
  True if the given time field has a value set; false otherwise.

Stable:
  ICU 2.6.

## ◆ isWeekend() [1/2]

virtual UBool icu::Calendar::isWeekend | ( | UDate | date,
|  | UErrorCode & | status
| ) |  | const
| virtual

Returns true if the given UDate is in the weekend in this calendar system.

Parameters

  date | The UDate in question.
  status | The error code for the operation.

Returns
  true if the given UDate is in the weekend in this calendar system, false otherwise.

Stable:
  ICU 4.4

## ◆ isWeekend() [2/2]

virtual UBool icu::Calendar::isWeekend | ( | void |  | ) | const
| virtual

Returns true if this Calendar's current date-time is in the weekend in this calendar system.

Returns
  true if this Calendar's current date-time is in the weekend in this calendar system, false otherwise.

Stable:
  ICU 4.4

## ◆ julianDayToDayOfWeek()

static uint8_t icu::Calendar::julianDayToDayOfWeek | ( | double | julian | ) |
| static protected

Convert a quasi Julian date to the day of the week.

The Julian date used here is not a true Julian date, since it is measured from midnight, not noon. Return value is one-based.

Parameters

  julian | The given Julian date number.

Returns
  Day number from 1..7 (SUN..SAT).

Internal:
  Do not use. This API is for internal use only.

## ◆ makeInstance()

static Calendar* icu::Calendar::makeInstance | ( | const Locale & | locale,
|  | UErrorCode & | status
| ) |  |
| static

Creates a new Calendar from a Locale for the cache.

This method does not set the time or timezone in returned calendar.

Parameters

  locale | the locale.
  status | any error returned here.

Returns
  the new Calendar object with no time or timezone set.

Internal:
  Do not use. This API is for internal use only. For ICU use only.

## ◆ newerField()

UCalendarDateFields icu::Calendar::newerField | ( | UCalendarDateFields | defaultField,
|  | UCalendarDateFields | alternateField
| ) |  | const
| protected

Return the field that is newer, either defaultField, or alternateField.

If neither is newer or neither is set, return defaultField.

Internal:
  Do not use. This API is for internal use only.

## ◆ newestStamp()

int32_t icu::Calendar::newestStamp | ( | UCalendarDateFields | start,
|  | UCalendarDateFields | end,
|  | int32_t | bestSoFar
| ) |  | const
| protected

Determine the best stamp in a range.

Parameters

  start | first enum to look at
  end | last enum to look at
  bestSoFar | stamp prior to function call

Returns
  the stamp value of the best stamp

Internal:
  Do not use. This API is for internal use only.

## ◆ operator!=()

bool icu::Calendar::operator!= | ( | const Calendar & | that | ) | const
| inline

Compares the inequality of two Calendar objects.

Parameters

  that | The Calendar object to be compared with.

Returns
  true if the given Calendar is not the same as this Calendar; false otherwise.

Stable:
  ICU 2.0

Definition at line 466 of file calendar.h.

References icu::operator==().

## ◆ operator=()

Calendar& icu::Calendar::operator= | ( | const Calendar & | right | ) |
| protected

Default assignment operator.

Parameters

  right | Calendar object to be copied

Stable:
  ICU 2.0

## ◆ operator==()

virtual bool icu::Calendar::operator== | ( | const Calendar & | that | ) | const
| virtual

Compares the equality of two Calendar objects.

Objects of different subclasses are considered unequal. This comparison is very exacting; two Calendar objects must be in exactly the same state to be considered equal. To compare based on the represented time, use equals() instead.

Parameters

  that | The Calendar object to be compared with.

Returns
  true if the given Calendar is the same as this Calendar; false otherwise.

Stable:
  ICU 2.0

## ◆ orphanTimeZone()

TimeZone* icu::Calendar::orphanTimeZone | ( | void |  | ) |

Returns the time zone owned by this calendar.

The caller owns the returned object and must delete it when done. After this call, the new time zone associated with this Calendar is the default TimeZone as returned by TimeZone::createDefault().

Returns
  The time zone object which was associated with this calendar.

Stable:
  ICU 2.0

## ◆ pinField()

virtual void icu::Calendar::pinField | ( | UCalendarDateFields | field,
|  | UErrorCode & | status
| ) |  |
| protected virtual

Adjust the specified field so that it is within the allowable range for the date to which this calendar is set.

For example, in a Gregorian calendar pinning the DAY_OF_MONTH field for a calendar set to April 31 would cause it to be set to April 30.

Subclassing:
This utility method is intended for use by subclasses that need to implement their own overrides of roll and add.

Note: `pinField` is implemented in terms of getActualMinimum and getActualMaximum. If either of those methods uses a slow, iterative algorithm for a particular field, it would be unwise to attempt to call `pinField` for that field. If you really do need to do so, you should override this method to do something more efficient for that field.

Parameters

  field | The calendar field whose value should be pinned.
  status | Output param set to failure code on function return when this function fails.

See also
  getActualMinimum
  getActualMaximum

Stable:
  ICU 2.0

## ◆ prepareGetActual()

virtual void icu::Calendar::prepareGetActual | ( | UCalendarDateFields | field,
|  | UBool | isMinimum,
|  | UErrorCode & | status
| ) |  |
| protected virtual

Prepare this calendar for computing the actual minimum or maximum.

This method modifies this calendar's fields; it is called on a temporary calendar.

Internal:
  Do not use. This API is for internal use only.

## ◆ registerFactory()

static URegistryKey icu::Calendar::registerFactory | ( | ICUServiceFactory * | toAdopt,
|  | UErrorCode & | status
| ) |  |
| static

Register a new Calendar factory.

The factory will be adopted. INTERNAL in 2.6

Because ICU may choose to cache Calendars internally, this must be called at application startup, prior to any calls to Calendar::createInstance to avoid undefined behavior.

Parameters

  toAdopt | the factory instance to be adopted
  status | the in/out status code, no special meanings are assigned

Returns
  a registry key that can be used to unregister this factory

Internal:
  Do not use. This API is for internal use only.

## ◆ resolveFields()

UCalendarDateFields icu::Calendar::resolveFields | ( | const UFieldResolutionTable * | precedenceTable | ) | const
| protected

Given a precedence table, return the newest field combination in the table, or UCAL_FIELD_COUNT if none is found.

The precedence table is a 3-dimensional array of integers. It may be thought of as an array of groups. Each group is an array of lines. Each line is an array of field numbers. Within a line, if all fields are set, then the time stamp of the line is taken to be the stamp of the most recently set field. If any field of a line is unset, then the line fails to match. Within a group, the line with the newest time stamp is selected. The first field of the line is returned to indicate which line matched.

In some cases, it may be desirable to map a line to field that whose stamp is NOT examined. For example, if the best field is DAY_OF_WEEK then the DAY_OF_WEEK_IN_MONTH algorithm may be used. In order to do this, insert the value `kResolveRemap | F` at the start of the line, where `F` is the desired return field value. This field will NOT be examined; it only determines the return value if the other fields in the line are the newest.

If all lines of a group contain at least one unset field, then no line will match, and the group as a whole will fail to match. In that case, the next group will be processed. If all groups fail to match, then UCAL_FIELD_COUNT is returned.

Internal:
  Do not use. This API is for internal use only.

## ◆ roll() [1/4]

virtual void icu::Calendar::roll | ( | EDateFields | field,
|  | int32_t | amount,
|  | UErrorCode & | status
| ) |  |
| virtual

Time Field Rolling function.

Rolls by the given amount on the given time field. For example, to roll the current date up by one day, call roll(Calendar::DATE, +1, status). When rolling on the month or Calendar::MONTH field, other fields like date might conflict and, need to be changed. For instance, rolling the month up on the date 01/31/96 will result in 02/29/96. Rolling by a positive value always means rolling forward in time (unless the limit of the field is reached, in which case it may pin or wrap), so for Gregorian calendar, starting with 100 BC and rolling the year by + 1 results in 99 BC. When eras have a definite beginning and end (as in the Chinese calendar, or as in most eras in the Japanese calendar) then rolling the year past either limit of the era will cause the year to wrap around. When eras only have a limit at one end, then attempting to roll the year past that limit will result in pinning the year at that limit. Note that for most calendars in which era 0 years move forward in time (such as Buddhist, Hebrew, or Islamic), it is possible for add or roll to result in negative years for era 0 (that is the only way to represent years before the calendar epoch). When rolling on the hour-in-day or Calendar::HOUR_OF_DAY field, it will roll the hour value in the range between 0 and 23, which is zero-based.

The only difference between roll() and add() is that roll() does not change the value of more significant fields when it reaches the minimum or maximum of its range, whereas add() does.

Parameters

  field | The time field.
  amount | Indicates amount to roll.
  status | Output param set to success/failure code on exit. If any value previously set in the time field is invalid, this will be set to an error status.

Deprecated:
  ICU 2.6. Use roll(UCalendarDateFields field, int32_t amount, UErrorCode& status) instead.

Reimplemented in icu::GregorianCalendar.

## ◆ roll() [2/4]

void icu::Calendar::roll | ( | EDateFields | field,
|  | UBool | up,
|  | UErrorCode & | status
| ) |  |
| inline

Time Field Rolling function.

Rolls (up/down) a single unit of time on the given time field. For example, to roll the current date up by one day, call roll(Calendar::DATE, true). When rolling on the year or Calendar::YEAR field, it will roll the year value in the range between getMinimum(Calendar::YEAR) and the value returned by getMaximum(Calendar::YEAR). When rolling on the month or Calendar::MONTH field, other fields like date might conflict and, need to be changed. For instance, rolling the month up on the date 01/31/96 will result in 02/29/96. Rolling up always means rolling forward in time (unless the limit of the field is reached, in which case it may pin or wrap), so for Gregorian calendar, starting with 100 BC and rolling the year up results in 99 BC. When eras have a definite beginning and end (as in the Chinese calendar, or as in most eras in the Japanese calendar) then rolling the year past either limit of the era will cause the year to wrap around. When eras only have a limit at one end, then attempting to roll the year past that limit will result in pinning the year at that limit. Note that for most calendars in which era 0 years move forward in time (such as Buddhist, Hebrew, or Islamic), it is possible for add or roll to result in negative years for era 0 (that is the only way to represent years before the calendar epoch). When rolling on the hour-in-day or Calendar::HOUR_OF_DAY field, it will roll the hour value in the range between 0 and 23, which is zero-based.

NOTE: Do not use this method – use roll(EDateFields, int, UErrorCode&) instead.

Parameters

  field | The time field.
  up | Indicates if the value of the specified time field is to be rolled up or rolled down. Use true if rolling up, false otherwise.
  status | Output param set to success/failure code on exit. If any value previously set in the time field is invalid or restricted by leniency, this will be set to an error status.

Deprecated:
  ICU 2.6. Use roll(UCalendarDateFields field, UBool up, UErrorCode& status) instead.

Definition at line 2532 of file calendar.h.

## ◆ roll() [3/4]

virtual void icu::Calendar::roll | ( | UCalendarDateFields | field,
|  | int32_t | amount,
|  | UErrorCode & | status
| ) |  |
| virtual

Time Field Rolling function.

Rolls by the given amount on the given time field. For example, to roll the current date up by one day, call roll(Calendar::DATE, +1, status). When rolling on the month or Calendar::MONTH field, other fields like date might conflict and, need to be changed. For instance, rolling the month up on the date 01/31/96 will result in 02/29/96. Rolling by a positive value always means rolling forward in time (unless the limit of the field is reached, in which case it may pin or wrap), so for Gregorian calendar, starting with 100 BC and rolling the year by + 1 results in 99 BC. When eras have a definite beginning and end (as in the Chinese calendar, or as in most eras in the Japanese calendar) then rolling the year past either limit of the era will cause the year to wrap around. When eras only have a limit at one end, then attempting to roll the year past that limit will result in pinning the year at that limit. Note that for most calendars in which era 0 years move forward in time (such as Buddhist, Hebrew, or Islamic), it is possible for add or roll to result in negative years for era 0 (that is the only way to represent years before the calendar epoch). When rolling on the hour-in-day or Calendar::HOUR_OF_DAY field, it will roll the hour value in the range between 0 and 23, which is zero-based.

The only difference between roll() and add() is that roll() does not change the value of more significant fields when it reaches the minimum or maximum of its range, whereas add() does.

Parameters

  field | The time field.
  amount | Indicates amount to roll.
  status | Output param set to success/failure code on exit. If any value previously set in the time field is invalid, this will be set to an error status.

Stable:
  ICU 2.6.

Reimplemented in icu::GregorianCalendar.

## ◆ roll() [4/4]

void icu::Calendar::roll | ( | UCalendarDateFields | field,
|  | UBool | up,
|  | UErrorCode & | status
| ) |  |
| inline

Time Field Rolling function.

Rolls (up/down) a single unit of time on the given time field. For example, to roll the current date up by one day, call roll(Calendar::DATE, true). When rolling on the year or Calendar::YEAR field, it will roll the year value in the range between getMinimum(Calendar::YEAR) and the value returned by getMaximum(Calendar::YEAR). When rolling on the month or Calendar::MONTH field, other fields like date might conflict and, need to be changed. For instance, rolling the month up on the date 01/31/96 will result in 02/29/96. Rolling up always means rolling forward in time (unless the limit of the field is reached, in which case it may pin or wrap), so for Gregorian calendar, starting with 100 BC and rolling the year up results in 99 BC. When eras have a definite beginning and end (as in the Chinese calendar, or as in most eras in the Japanese calendar) then rolling the year past either limit of the era will cause the year to wrap around. When eras only have a limit at one end, then attempting to roll the year past that limit will result in pinning the year at that limit. Note that for most calendars in which era 0 years move forward in time (such as Buddhist, Hebrew, or Islamic), it is possible for add or roll to result in negative years for era 0 (that is the only way to represent years before the calendar epoch). When rolling on the hour-in-day or Calendar::HOUR_OF_DAY field, it will roll the hour value in the range between 0 and 23, which is zero-based.

NOTE: Do not use this method – use roll(UCalendarDateFields, int, UErrorCode&) instead.

Parameters

  field | The time field.
  up | Indicates if the value of the specified time field is to be rolled up or rolled down. Use true if rolling up, false otherwise.
  status | Output param set to success/failure code on exit. If any value previously set in the time field is invalid or restricted by leniency, this will be set to an error status.

Stable:
  ICU 2.6.

Definition at line 2525 of file calendar.h.

## ◆ set() [1/4]

void icu::Calendar::set | ( | int32_t | year,
|  | int32_t | month,
|  | int32_t | date
| ) |  |

Sets the values for the fields YEAR, MONTH, and DATE.

Other field values are retained; call clear() first if this is not desired.

Parameters

  year | The value used to set the YEAR time field.
  month | The value used to set the MONTH time field. Month value is 0-based. e.g., 0 for January.
  date | The value used to set the DATE time field.

Stable:
  ICU 2.0

## ◆ set() [2/4]

void icu::Calendar::set | ( | int32_t | year,
|  | int32_t | month,
|  | int32_t | date,
|  | int32_t | hour,
|  | int32_t | minute
| ) |  |

Sets the values for the fields YEAR, MONTH, DATE, HOUR_OF_DAY, and MINUTE.

Other field values are retained; call clear() first if this is not desired.

Parameters

  year | The value used to set the YEAR time field.
  month | The value used to set the MONTH time field. Month value is 0-based. E.g., 0 for January.
  date | The value used to set the DATE time field.
  hour | The value used to set the HOUR_OF_DAY time field.
  minute | The value used to set the MINUTE time field.

Stable:
  ICU 2.0

## ◆ set() [3/4]

void icu::Calendar::set | ( | int32_t | year,
|  | int32_t | month,
|  | int32_t | date,
|  | int32_t | hour,
|  | int32_t | minute,
|  | int32_t | second
| ) |  |

Sets the values for the fields YEAR, MONTH, DATE, HOUR_OF_DAY, MINUTE, and SECOND.

Other field values are retained; call clear() first if this is not desired.

Parameters

  year | The value used to set the YEAR time field.
  month | The value used to set the MONTH time field. Month value is 0-based. E.g., 0 for January.
  date | The value used to set the DATE time field.
  hour | The value used to set the HOUR_OF_DAY time field.
  minute | The value used to set the MINUTE time field.
  second | The value used to set the SECOND time field.

Stable:
  ICU 2.0

## ◆ set() [4/4]

void icu::Calendar::set | ( | UCalendarDateFields | field,
|  | int32_t | value
| ) |  |

Sets the given time field with the given value.

Parameters

  field | The given time field.
  value | The value to be set for the given time field.

Stable:
  ICU 2.6.

## ◆ setFirstDayOfWeek()

void icu::Calendar::setFirstDayOfWeek | ( | UCalendarDaysOfWeek | value | ) |

Sets what the first day of the week is; e.g., Sunday in US, Monday in France.

Parameters

  value | The given first day of the week.

Stable:
  ICU 2.6.

## ◆ setLenient()

void icu::Calendar::setLenient | ( | UBool | lenient | ) |

Specifies whether or not date/time interpretation is to be lenient.

With lenient interpretation, a date such as "February 942, 1996" will be treated as being equivalent to the 941st day after February 1, 1996. With strict interpretation, such dates will cause an error when computing time from the time field values representing the dates.

Parameters

  lenient | True specifies date/time interpretation to be lenient.

See also
  DateFormat::setLenient

Stable:
  ICU 2.0

## ◆ setMinimalDaysInFirstWeek()

void icu::Calendar::setMinimalDaysInFirstWeek | ( | uint8_t | value | ) |

Sets what the minimal days required in the first week of the year are; For example, if the first week is defined as one that contains the first day of the first month of a year, call the method with value 1.

If it must be a full week, use value 7.

Parameters

  value | The given minimal days required in the first week of the year.

Stable:
  ICU 2.0

## ◆ setRelatedYear()

virtual void icu::Calendar::setRelatedYear | ( | int32_t | year | ) |
| virtual

Parameters

  year | The related Gregorian year to set; will be modified as necessary then set in UCAL_EXTENDED_YEAR field

Internal:
  Do not use. This API is for internal use only.

## ◆ setRepeatedWallTimeOption()

void icu::Calendar::setRepeatedWallTimeOption | ( | UCalendarWallTimeOption | option | ) |

Sets the behavior for handling wall time repeating multiple times at negative time zone offset transitions.

For example, 1:30 AM on November 6, 2011 in US Eastern time (America/New_York) occurs twice; 1:30 AM EDT, then 1:30 AM EST one hour later. When `UCAL_WALLTIME_FIRST` is used, the wall time 1:30AM in this example will be interpreted as 1:30 AM EDT (first occurrence). When `UCAL_WALLTIME_LAST` is used, it will be interpreted as 1:30 AM EST (last occurrence). The default value is `UCAL_WALLTIME_LAST`.

Note:When `UCAL_WALLTIME_NEXT_VALID` is not a valid option for this. When the argument is neither `UCAL_WALLTIME_FIRST` nor `UCAL_WALLTIME_LAST`, this method has no effect and will keep the current setting.

Parameters

  option | the behavior for handling repeating wall time, either `UCAL_WALLTIME_FIRST` or `UCAL_WALLTIME_LAST`.

See also
  getRepeatedWallTimeOption

Stable:
  ICU 49

## ◆ setSkippedWallTimeOption()

void icu::Calendar::setSkippedWallTimeOption | ( | UCalendarWallTimeOption | option | ) |

Sets the behavior for handling skipped wall time at positive time zone offset transitions.

For example, 2:30 AM on March 13, 2011 in US Eastern time (America/New_York) does not exist because the wall time jump from 1:59 AM EST to 3:00 AM EDT. When `UCAL_WALLTIME_FIRST` is used, 2:30 AM is interpreted as 30 minutes before 3:00 AM EDT, therefore, it will be resolved as 1:30 AM EST. When `UCAL_WALLTIME_LAST` is used, 2:30 AM is interpreted as 31 minutes after 1:59 AM EST, therefore, it will be resolved as 3:30 AM EDT. When `UCAL_WALLTIME_NEXT_VALID` is used, 2:30 AM will be resolved as next valid wall time, that is 3:00 AM EDT. The default value is `UCAL_WALLTIME_LAST`.

Note:This option is effective only when this calendar is lenient. When the calendar is strict, such non-existing wall time will cause an error.

Parameters

  option | the behavior for handling skipped wall time at positive time zone offset transitions, one of `UCAL_WALLTIME_FIRST`, `UCAL_WALLTIME_LAST` and `UCAL_WALLTIME_NEXT_VALID`.

See also
  getSkippedWallTimeOption

Stable:
  ICU 49

## ◆ setTemporalMonthCode()

virtual void icu::Calendar::setTemporalMonthCode | ( | const char * | temporalMonth,
|  | UErrorCode & | status
| ) |  |
| virtual

Sets The Temporal monthCode which is a string identifier that starts with the literal grapheme "M" followed by two graphemes representing the zero-padded month number of the current month in a normal (non-leap) year and suffixed by an optional literal grapheme "L" if this is a leap month in a lunisolar calendar.

The 25 possible values are "M01" .. "M13" and "M01L" .. "M12L". For Hebrew calendar, the values are "M01" .. "M12" for non-leap years, and "M01" .. "M05", "M05L", "M06" .. "M12" for leap year. For the Chinese calendar, the values are "M01" .. "M12" for non-leap year and in leap year with another monthCode in "M01L" .. "M12L". For Coptic and Ethiopian calendar, the Temporal monthCode values for any years are "M01" to "M13".

Parameters

  temporalMonth | The value to be set for temporal monthCode.
  status | ICU Error Code

Draft:
  This API may be changed in the future versions and was introduced in ICU 73

## ◆ setTime()

void icu::Calendar::setTime | ( | UDate | date,
|  | UErrorCode & | status
| ) |  |
| inline

Sets this Calendar's current time with the given UDate.

The time specified should be in non-local UTC (GMT) time.

Parameters

  date | The given UDate in UTC (GMT) time.
  status | Output param set to success/failure code on exit. If any value set in the time field is invalid or restricted by leniency, this will be set to an error status.

Stable:
  ICU 2.0

Definition at line 443 of file calendar.h.

## ◆ setTimeInMillis()

void icu::Calendar::setTimeInMillis | ( | double | millis,
|  | UErrorCode & | status
| ) |  |
| protected

Sets this Calendar's current time from the given long value.

Parameters

  millis | the new time in UTC milliseconds from the epoch.
  status | Output param set to success/failure code on exit. If any value previously set in the time field is invalid or restricted by leniency, this will be set to an error status.

Stable:
  ICU 2.0

## ◆ setTimeZone()

void icu::Calendar::setTimeZone | ( | const TimeZone & | zone | ) |

Sets the calendar's time zone to be the same as the one passed in.

The TimeZone passed in is not adopted; the client is still responsible for deleting it.

Parameters

  zone | The given time zone.

Stable:
  ICU 2.0

## ◆ unregister()

static UBool icu::Calendar::unregister | ( | URegistryKey | key,
|  | UErrorCode & | status
| ) |  |
| static

Unregister a previously-registered CalendarFactory using the key returned from the register call.

Key becomes invalid after a successful call and should not be used again. The CalendarFactory corresponding to the key will be deleted. INTERNAL in 2.6

Because ICU may choose to cache Calendars internally, this should be called during application shutdown, after all calls to Calendar::createInstance to avoid undefined behavior.

Parameters

  key | the registry key returned by a previous call to registerFactory
  status | the in/out status code, no special meanings are assigned

Returns
  true if the factory for the key was successfully unregistered

Internal:
  Do not use. This API is for internal use only.

## ◆ validateField()

virtual void icu::Calendar::validateField | ( | UCalendarDateFields | field,
|  | UErrorCode & | status
| ) |  |
| protected virtual

Validate a single field of this calendar.

Subclasses should override this method to validate any calendar-specific fields. Generic fields can be handled by `Calendar::validateField()`.

Internal:
  Do not use. This API is for internal use only.

## ◆ weekNumber() [1/2]

int32_t icu::Calendar::weekNumber | ( | int32_t | dayOfPeriod,
|  | int32_t | dayOfWeek
| ) |  |
| inline protected

Return the week number of a day, within a period.

This may be the week number in a year, or the week number in a month. Usually this will be a value >= 1, but if some initial days of the period are excluded from week 1, because getMinimalDaysInFirstWeek is > 1, then the week number will be zero for those initial days. This method requires the day of week for the given date in order to determine the result.

Subclassing:
This method is intended for use by subclasses in implementing their computeTime and/or computeFields methods. It is often useful in getActualMinimum and getActualMaximum as well.

Parameters

  dayOfPeriod | The DAY_OF_YEAR or DAY_OF_MONTH whose week number is desired. Should be 1 for the first day of the period.
  dayOfWeek | The DAY_OF_WEEK for the day corresponding to the `dayOfPeriod` parameter. 1-based with 1=Sunday.

Returns
  The week number (one-based), or zero if the day falls before the first week because getMinimalDaysInFirstWeek is more than one.

Internal:
  Do not use. This API is for internal use only.

Definition at line 2556 of file calendar.h.

## ◆ weekNumber() [2/2]

int32_t icu::Calendar::weekNumber | ( | int32_t | desiredDay,
|  | int32_t | dayOfPeriod,
|  | int32_t | dayOfWeek
| ) |  |
| protected

Return the week number of a day, within a period.

This may be the week number in a year or the week number in a month. Usually this will be a value >= 1, but if some initial days of the period are excluded from week 1, because getMinimalDaysInFirstWeek is > 1, then the week number will be zero for those initial days. This method requires the day number and day of week for some known date in the period in order to determine the day of week on the desired day.

Subclassing:
This method is intended for use by subclasses in implementing their computeTime and/or computeFields methods. It is often useful in getActualMinimum and getActualMaximum as well.

This variant is handy for computing the week number of some other day of a period (often the first or last day of the period) when its day of the week is not known but the day number and day of week for some other day in the period (e.g. the current date) is known.

Parameters

  desiredDay | The DAY_OF_YEAR or DAY_OF_MONTH whose week number is desired. Should be 1 for the first day of the period.
  dayOfPeriod | The DAY_OF_YEAR or DAY_OF_MONTH for a day in the period whose DAY_OF_WEEK is specified by the `knownDayOfWeek` parameter. Should be 1 for first day of period.
  dayOfWeek | The DAY_OF_WEEK for the day corresponding to the `knownDayOfPeriod` parameter. 1-based with 1=Sunday.

Returns
  The week number (one-based), or zero if the day falls before the first week because getMinimalDaysInFirstWeek is more than one.

Stable:
  ICU 2.8

## Friends And Related Function Documentation

## ◆ CalendarFactory

friend class CalendarFactory
| friend

Multiple Calendar Implementation.

Internal:
  Do not use.

This API is for internal use only.

Definition at line 2402 of file calendar.h.

## ◆ CalendarService

friend class CalendarService
| friend

Multiple Calendar Implementation.

Internal:
  Do not use.

This API is for internal use only.

Definition at line 2408 of file calendar.h.

## ◆ DefaultCalendarFactory

friend class DefaultCalendarFactory
| friend

Multiple Calendar Implementation.

Internal:
  Do not use.

This API is for internal use only.

Definition at line 2414 of file calendar.h.

## Field Documentation

## ◆ fAreAllFieldsSet

UBool icu::Calendar::fAreAllFieldsSet
| protected

True if all of the fields have been set.

This is initially false, and set to true by computeFields().

Stable:
  ICU 2.0

Definition at line 1898 of file calendar.h.

## ◆ fAreFieldsSet

UBool icu::Calendar::fAreFieldsSet
| protected

True if the fields are in sync with the currently set time of this Calendar.

If false, then the next attempt to get the value of a field will force a recomputation of all fields from the current value of the time field.

This should really be named areFieldsInSync, but the old name is retained for backward compatibility.

Stable:
  ICU 2.0

Definition at line 1891 of file calendar.h.

## ◆ fAreFieldsVirtuallySet

UBool icu::Calendar::fAreFieldsVirtuallySet
| protected

True if all fields have been virtually set, but have not yet been computed.

This occurs only in setTimeInMillis(). A calendar set to this state will compute all fields from the time if it becomes necessary, but otherwise will delay such computation.

Stable:
  ICU 3.0

Definition at line 1907 of file calendar.h.

## ◆ fFields

int32_t icu::Calendar::fFields[UCAL_FIELD_COUNT]
| protected

The time fields containing values into which the millis is computed.

Stable:
  ICU 2.0

Definition at line 1930 of file calendar.h.

## ◆ fIsSet

UBool icu::Calendar::fIsSet[UCAL_FIELD_COUNT]
| protected

The flags which tell if a specified time field for the calendar is set.

Deprecated:
  ICU 2.8 use (fStamp[n]!=kUnset)

Definition at line 1937 of file calendar.h.

## ◆ fIsTimeSet

UBool icu::Calendar::fIsTimeSet
| protected

The flag which indicates if the current time is set in the calendar.

Stable:
  ICU 2.0

Definition at line 1879 of file calendar.h.

## ◆ fStamp

int32_t icu::Calendar::fStamp[UCAL_FIELD_COUNT]
| protected

Pseudo-time-stamps which specify when each field was set.

There are two special values, UNSET and INTERNALLY_SET. Values from MINIMUM_USER_SET to Integer.MAX_VALUE are legal user set values.

Stable:
  ICU 2.0

Definition at line 1955 of file calendar.h.

## ◆ kDatePrecedence

const UFieldResolutionTable icu::Calendar::kDatePrecedence[]
| static protected

Precedence table for Dates.

See also
  resolveFields

Internal:
  Do not use. This API is for internal use only.

Definition at line 1793 of file calendar.h.

## ◆ kDOWPrecedence

const UFieldResolutionTable icu::Calendar::kDOWPrecedence[]
| static protected

Precedence table for Day of Week.

See also
  resolveFields

Internal:
  Do not use. This API is for internal use only.

Definition at line 1807 of file calendar.h.

## ◆ kMonthPrecedence

const UFieldResolutionTable icu::Calendar::kMonthPrecedence[]
| static protected

Precedence table for Months.

See also
  resolveFields

Internal:
  Do not use. This API is for internal use only.

Definition at line 1814 of file calendar.h.

## ◆ kResolveRemap

constexpr int32_t icu::Calendar::kResolveRemap = 32
| static constexpr protected

Value to be bitwised "ORed" against resolve table field values for remapping.

Example: (UCAL_DATE | kResolveRemap) in 1st column will cause 'UCAL_DATE' to be returned, but will not examine the value of UCAL_DATE. Value for field resolution tables.

See also
  resolveFields

Internal:
  Do not use. This API is for internal use only.

Definition at line 1786 of file calendar.h.

## ◆ kResolveSTOP

constexpr int32_t icu::Calendar::kResolveSTOP = -1
| static constexpr protected

Marker for end of resolve set (row or group).

Value for field resolution tables.

See also
  resolveFields

Internal:
  Do not use. This API is for internal use only.

Definition at line 1776 of file calendar.h.

## ◆ kYearPrecedence

const UFieldResolutionTable icu::Calendar::kYearPrecedence[]
| static protected

Precedence table for Year.

See also
  resolveFields

Internal:
  Do not use. This API is for internal use only.

Definition at line 1800 of file calendar.h.

The documentation for this class was generated from the following file:

- i18n/unicode/calendar.h