Go to the documentation of this file.
32 #if U_SHOW_CPLUSPLUS_API
38 #if !UCONFIG_NO_FORMATTING
48 class ICUServiceFactory;
191 #ifndef U_FORCE_HIDE_DEPRECATED_API
199 #ifndef U_HIDE_DEPRECATED_API
214 DAY_OF_WEEK_IN_MONTH,
234 #endif // U_FORCE_HIDE_DEPRECATED_API
236 #ifndef U_HIDE_DEPRECATED_API
526 #ifndef U_FORCE_HIDE_DEPRECATED_API
548 #endif // U_FORCE_HIDE_DEPRECATED_API
572 #ifndef U_HIDE_DEPRECATED_API
642 #ifndef U_FORCE_HIDE_DEPRECATED_API
675 #endif // U_FORCE_HIDE_DEPRECATED_API
710 #ifndef U_FORCE_HIDE_DEPRECATED_API
767 #endif // U_FORCE_HIDE_DEPRECATED_API
965 #ifndef U_HIDE_DEPRECATED_API
983 #ifndef U_HIDE_DEPRECATED_API
1024 #ifndef U_FORCE_HIDE_DEPRECATED_API
1034 #endif // U_FORCE_HIDE_DEPRECATED_API
1046 #ifndef U_FORCE_HIDE_DEPRECATED_API
1056 #endif // U_FORCE_HIDE_DEPRECATED_API
1068 #ifndef U_FORCE_HIDE_DEPRECATED_API
1078 #endif // U_FORCE_HIDE_DEPRECATED_API
1090 #ifndef U_FORCE_HIDE_DEPRECATED_API
1100 #endif // U_FORCE_HIDE_DEPRECATED_API
1112 #ifndef U_HIDE_DEPRECATED_API
1146 #ifndef U_HIDE_DEPRECATED_API
1184 #ifndef U_HIDE_DEPRECATED_API
1216 #ifndef U_HIDE_DEPRECATED_API
1238 #ifndef U_HIDE_DEPRECATED_API
1268 void set(int32_t year, int32_t month, int32_t date);
1282 void set(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute);
1297 void set(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, int32_t second);
1307 #ifndef U_HIDE_DEPRECATED_API
1540 #ifndef U_HIDE_DEPRECATED_API
1552 #ifndef U_HIDE_INTERNAL_API
1576 #ifndef U_HIDE_DEPRECATED_API
1613 #ifndef U_HIDE_INTERNAL_API
1614 UCAL_LIMIT_MINIMUM = 0,
1615 UCAL_LIMIT_GREATEST_MINIMUM,
1616 UCAL_LIMIT_LEAST_MAXIMUM,
1669 UBool useMonth)
const = 0;
1728 #ifndef U_HIDE_INTERNAL_API
1837 #ifndef U_HIDE_INTERNAL_API
1917 #ifndef U_FORCE_HIDE_DEPRECATED_API
1923 #endif // U_FORCE_HIDE_DEPRECATED_API
1968 #ifndef U_HIDE_INTERNAL_API
1975 return fGregorianYear;
1984 return fGregorianMonth;
1993 return fGregorianDayOfYear;
2002 return fGregorianDayOfMonth;
2103 int32_t
weekNumber(int32_t desiredDay, int32_t dayOfPeriod, int32_t dayOfWeek);
2106 #ifndef U_HIDE_INTERNAL_API
2137 inline int32_t weekNumber(int32_t dayOfPeriod, int32_t dayOfWeek);
2157 void recalculateStamp();
2196 uint8_t fMinimalDaysInFirstWeek;
2198 int32_t fWeekendOnsetMillis;
2200 int32_t fWeekendCeaseMillis;
2212 void setWeekData(
const Locale& desiredLocale,
const char *type,
UErrorCode& success);
2230 int32_t fGregorianYear;
2237 int32_t fGregorianMonth;
2244 int32_t fGregorianDayOfYear;
2251 int32_t fGregorianDayOfMonth;
2261 void computeGregorianAndDOWFields(int32_t julianDay,
UErrorCode &ec);
2318 #ifndef U_HIDE_INTERNAL_API
2336 #if !UCONFIG_NO_SERVICE
2341 #ifndef U_HIDE_INTERNAL_API
2387 friend class CalendarFactory;
2393 friend class CalendarService;
2399 friend class DefaultCalendarFactory;
2441 #ifndef U_HIDE_INTERNAL_API
2468 #ifndef U_HIDE_INTERNAL_API
2493 int32_t typeBufferSize,
2504 return createInstance(zone, Locale::getDefault(), errorCode);
2512 roll(field, (int32_t)(up ? +1 : -1), status);
2515 #ifndef U_HIDE_DEPRECATED_API
2534 fFields[field] = value;
2535 fStamp[field] = kInternallySet;
2536 fIsSet[field] =
true;
2540 #ifndef U_HIDE_INTERNAL_API
2541 inline int32_t Calendar::weekNumber(int32_t dayOfPeriod, int32_t dayOfWeek)
2543 return weekNumber(dayOfPeriod, dayOfPeriod, dayOfWeek);
UCalendarDaysOfWeek getFirstDayOfWeek(UErrorCode &status) const
Gets what the first day of the week is; e.g., Sunday in US, Monday in France.
void set(int32_t year, int32_t month, int32_t date)
Sets the values for the fields YEAR, MONTH, and DATE.
virtual void prepareGetActual(UCalendarDateFields field, UBool isMinimum, UErrorCode &status)
Prepare this calendar for computing the actual minimum or maximum.
int32_t getGregorianMonth() const
Return the month (0-based) on the Gregorian calendar as computed by computeGregorianFields().
virtual int32_t getDefaultMonthInYear(int32_t eyear)
Called by computeJulianDay.
Locale getLocale(ULocDataLocaleType type, UErrorCode &status) const
Get the locale for this calendar object.
int32_t getActualMaximum(EDateFields field, UErrorCode &status) const
Return the maximum value that this field could have, given the current date.
UBool isSet(UCalendarDateFields field) const
Determines if the given time field has a value set.
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.
virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const =0
Subclass API for defining limits of different types.
virtual Calendar * clone() const =0
Create and return a polymorphic copy of this calendar.
Calendar(const Calendar &source)
Copy constructor.
UBool isLenient(void) const
Tells whether date/time interpretation is to be lenient.
UBool fAreAllFieldsSet
True if all of the fields have been set.
Basic definitions for ICU, for both C and C++ APIs.
UCalendarWallTimeOption
Options for handling ambiguous wall time at time zone offset transitions.
int32_t internalGet(EDateFields field) const
Gets the value for a given time field.
void setFirstDayOfWeek(UCalendarDaysOfWeek value)
Sets what the first day of the week is; e.g., Sunday in US, Monday in France.
static URegistryKey registerFactory(ICUServiceFactory *toAdopt, UErrorCode &status)
Register a new Calendar factory.
double computeMillisInDay()
Compute the milliseconds in the day from the fields.
static Calendar * createInstance(UErrorCode &success)
Creates a Calendar using the default timezone and locale.
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Calendar is an abstract base class for converting between a UDate object and a set of integer fields ...
virtual int32_t getMaximum(UCalendarDateFields field) const
Gets the maximum value for the given time field.
int8_t UBool
The ICU boolean type, a signed-byte integer.
BasicTimeZone is an abstract class extending TimeZone.
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 ...
ULocDataLocaleType
Constants for *_getLocale() Allow user to select whether she wants information on requested,...
Calendar(TimeZone *zone, const Locale &aLocale, UErrorCode &success)
Constructs a Calendar with the given time zone and locale.
int32_t getActualMinimum(EDateFields field, UErrorCode &status) const
Return the minimum value that this field could have, given the current date.
virtual void validateField(UCalendarDateFields field, UErrorCode &status)
Validate a single field of this calendar.
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
UBool operator!=(const Calendar &that) const
Compares the inequality of two Calendar objects.
int32_t internalGet(UCalendarDateFields field, int32_t defaultValue) const
Gets the value for a given time field.
int32_t internalGet(UCalendarDateFields field) const
Gets the value for a given time field.
UCalendarDateFields newerField(UCalendarDateFields defaultField, UCalendarDateFields alternateField) const
Return the field that is newer, either defaultField, or alternateField.
void set(UCalendarDateFields field, int32_t value)
Sets the given time field with the given value.
void setFirstDayOfWeek(EDaysOfWeek value)
Sets what the first day of the week is; e.g., Sunday in US, Monday in France.
virtual UBool isWeekend(UDate date, UErrorCode &status) const
Returns true if the given UDate is in the weekend in this calendar system.
virtual int32_t defaultCenturyStartYear() const =0
virtual UDate defaultCenturyStart() const =0
UDate internalGetTime(void) const
Get the current time without recomputing.
virtual UBool haveDefaultCentury() const =0
void setLenient(UBool lenient)
Specifies whether or not date/time interpretation is to be lenient.
TimeZone represents a time zone offset, and also figures out daylight savings.
int32_t get(EDateFields field, UErrorCode &status) const
Gets the value for a given time field.
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.
const char * getLocaleID(ULocDataLocaleType type, UErrorCode &status) const
Get the locale for this calendar object.
virtual void add(UCalendarDateFields field, int32_t amount, UErrorCode &status)
UDate Arithmetic function.
EAmpm
Useful constants for hour in 12-hour clock.
static Calendar * createInstance(const TimeZone &zone, UErrorCode &success)
Creates a Calendar using the given timezone and the default locale.
virtual UBool operator==(const Calendar &that) const
Compares the equality of two Calendar objects.
void clear(EDateFields field)
Clears the value in the given time field, both making it unset and assigning it a value of zero.
int32_t computeZoneOffset(double millis, double millisInDay, UErrorCode &ec)
This method can assume EXTENDED_YEAR has been set.
virtual int32_t getMinimum(UCalendarDateFields field) const
Gets the minimum value for the given time field.
virtual int32_t getLimit(UCalendarDateFields field, ELimitType limitType) const
Return a limit for a field.
void clear(void)
Clears the values of all the time fields, making them both unset and assigning them a value of zero.
EDaysOfWeek getFirstDayOfWeek(void) const
Gets what the first day of the week is; e.g., Sunday in US, Monday in France.
static Calendar * createInstance(const TimeZone &zone, const Locale &aLocale, UErrorCode &success)
Gets a Calendar using the given timezone and given locale.
C++ API: TimeZone object.
TimeZone * orphanTimeZone(void)
Returns the time zone owned by this calendar.
void internalSetTime(UDate time)
Set the current time without affecting flags or fields.
virtual ~Calendar()
destructor
virtual const char * getType() const =0
Returns the calendar type name string for this Calendar object.
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 di...
const void * URegistryKey
Opaque type returned by registerInstance, registerFactory and unregister for service registration.
UCalendarDateFields resolveFields(const UFieldResolutionTable *precedenceTable)
Given a precedence table, return the newest field combination in the table, or UCAL_FIELD_COUNT if no...
int32_t newestStamp(UCalendarDateFields start, UCalendarDateFields end, int32_t bestSoFar) const
Determine the best stamp in a range.
UObject is the common ICU "boilerplate" class.
virtual int32_t getRelatedYear(UErrorCode &status) const
void computeGregorianFields(int32_t julianDay, UErrorCode &ec)
Compute the Gregorian calendar year, month, and day of month from the Julian day.
virtual UBool isEquivalentTo(const Calendar &other) const
Returns true if the given Calendar object is equivalent to this one.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
static Calendar * createInstance(const Locale &aLocale, UErrorCode &success)
Creates a Calendar using the default timezone and the given locale.
void setTimeInMillis(double millis, UErrorCode &status)
Sets this Calendar's current time from the given long value.
Base class for 'pure' C++ implementations of uenum api.
double getTimeInMillis(UErrorCode &status) const
Gets this Calendar's current time as a long.
virtual int32_t getMaximum(EDateFields field) const
Gets the maximum value for the given time field.
virtual void setRelatedYear(int32_t year)
UBool before(const Calendar &when, UErrorCode &status) const
Returns true if this Calendar's current time is before "when"'s current time.
UBool after(const Calendar &when, UErrorCode &status) const
Returns true if this Calendar's current time is after "when"'s current time.
virtual UBool isWeekend(void) const
Returns true if this Calendar's current date-time is in the weekend in this calendar system.
UBool isSet(EDateFields field) const
Determines if the given time field has a value set.
UCalendarWallTimeOption getRepeatedWallTimeOption(void) const
Gets the behavior for handling wall time repeating multiple times at negative time zone offset transi...
virtual int32_t handleComputeJulianDay(UCalendarDateFields bestField)
Subclasses may override this.
virtual UBool inDaylightTime(UErrorCode &status) const =0
Queries if the current date for this Calendar is in Daylight Savings Time.
static StringEnumeration * getAvailableLocales(void)
INTERNAL FOR 2.6 – Registration.
virtual void add(EDateFields field, int32_t amount, UErrorCode &status)
UDate Arithmetic function.
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...
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 def...
static const Locale * getAvailableLocales(int32_t &count)
Returns a list of the locales for which Calendars are installed.
UBool fAreFieldsVirtuallySet
True if all fields have been virtually set, but have not yet been computed.
UBool fAreFieldsSet
True if the fields are in sync with the currently set time of this Calendar.
virtual int32_t getDefaultDayInMonth(int32_t eyear, int32_t month)
Called by computeJulianDay.
Calendar(const TimeZone &zone, const Locale &aLocale, UErrorCode &success)
Constructs a Calendar with the given time zone and locale.
UCalendarWeekdayType
Weekday types, as returned by ucal_getDayOfWeekType().
int32_t get(UCalendarDateFields field, UErrorCode &status) const
Gets the value for a given time field.
int32_t computeJulianDay()
Compute the Julian day from fields.
virtual void computeTime(UErrorCode &status)
Converts Calendar's time field values to GMT as milliseconds.
void setRepeatedWallTimeOption(UCalendarWallTimeOption option)
Sets the behavior for handling wall time repeating multiple times at negative time zone offset transi...
virtual void computeFields(UErrorCode &status)
Converts GMT as milliseconds to time field values.
@ UCAL_FIELD_COUNT
One more than the highest normal UCalendarDateFields value.
int32_t weekNumber(int32_t desiredDay, int32_t dayOfPeriod, int32_t dayOfWeek)
Return the week number of a day, within a period.
virtual int32_t getActualMaximum(UCalendarDateFields field, UErrorCode &status) const
Return the maximum value that this field could have, given the current date.
virtual int32_t getLeastMaximum(EDateFields field) const
Gets the lowest maximum value for the given field if varies.
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.
virtual UClassID getDynamicClassID(void) const =0
Returns a unique class ID POLYMORPHICALLY.
void set(EDateFields field, int32_t value)
Sets the given time field with the given value.
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.
virtual int32_t getLeastMaximum(UCalendarDateFields field) const
Gets the lowest maximum value for the given field if varies.
int32_t getLocalDOW()
returns the local DOW, valid range 0..6
virtual void roll(EDateFields field, int32_t amount, UErrorCode &status)
Time Field Rolling function.
#define ULOC_FULLNAME_CAPACITY
Useful constant for the maximum size of the whole locale ID (including the terminating NULL and all k...
virtual int32_t handleGetExtendedYear()=0
Return the extended year defined by the current fields.
Calendar(UErrorCode &success)
Constructs a Calendar with the default time zone as returned by TimeZone::createInstance(),...
virtual int32_t getGreatestMinimum(EDateFields field) const
Gets the highest minimum value for the given field if varies.
UCalendarWallTimeOption getSkippedWallTimeOption(void) const
Gets the behavior for handling skipped wall time at positive time zone offset transitions.
void adoptTimeZone(TimeZone *value)
Sets the calendar's time zone to be the one passed in.
UCalendarDaysOfWeek
Useful constant for days of week.
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 calend...
void setSkippedWallTimeOption(UCalendarWallTimeOption option)
Sets the behavior for handling skipped wall time at positive time zone offset transitions.
double UDate
Date and Time data type.
virtual int32_t getGreatestMinimum(UCalendarDateFields field) const
Gets the highest minimum value for the given field if varies.
int32_t UFieldResolutionTable[12][8]
static Calendar * makeInstance(const Locale &locale, UErrorCode &status)
Creates a new Calendar from a Locale for the cache.
static UDate getNow(void)
Returns the current UTC (GMT) time measured in milliseconds since 0:00:00 on 1/1/70 (derived from the...
void complete(UErrorCode &status)
Recomputes the current time from currently set fields, and then fills in any unset fields in the time...
Calendar & operator=(const Calendar &right)
Default assignment operator.
UCalendarDateFields
Possible fields in a UCalendar.
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.
void internalSet(EDateFields field, int32_t value)
Sets the value for a given time field.
virtual void roll(UCalendarDateFields field, int32_t amount, UErrorCode &status)
Time Field Rolling function.
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 yea...
EMonths
Useful constants for month.
static uint8_t julianDayToDayOfWeek(double julian)
Convert a quasi Julian date to the day of the week.
virtual int32_t getActualMinimum(UCalendarDateFields field, UErrorCode &status) const
Return the minimum value that this field could have, given the current date.
int32_t getGregorianYear() const
Return the extended year on the Gregorian calendar as computed by computeGregorianFields().
C++ API: Locale ID object.
const TimeZone & getTimeZone(void) const
Returns a reference to the time zone owned by this calendar.
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.
void setTime(UDate date, UErrorCode &status)
Sets this Calendar's current time with the given UDate.
EDaysOfWeek
Useful constant for days of week.
C++ API: Common ICU base class UObject.
void clear(UCalendarDateFields field)
Clears the value in the given time field, both making it unset and assigning it a value of zero.
static void getCalendarTypeFromLocale(const Locale &locale, char *typeBuffer, int32_t typeBufferSize, UErrorCode &status)
Get the calendar type for given locale.
virtual int32_t getMinimum(EDateFields field) const
Gets the minimum value for the given time field.
virtual int32_t handleGetYearLength(int32_t eyear) const
Return the number of days in the given extended year of this calendar system.
virtual const UFieldResolutionTable * getFieldResolutionTable() const
virtual void handleComputeFields(int32_t julianDay, UErrorCode &status)
Subclasses may override this method to compute several fields specific to each calendar system.
int32_t getGregorianDayOfMonth() const
Return the day of month (1-based) on the Gregorian calendar as computed by computeGregorianFields().
EDateFields
Field IDs for date and time.
A Locale object represents a specific geographical, political, or cultural region.
UBool fIsTimeSet
The flag which indicates if the current time is set in the calendar.
void setTimeZone(const TimeZone &zone)
Sets the calendar's time zone to be the same as the one passed in.
void setMinimalDaysInFirstWeek(uint8_t value)
Sets what the minimal days required in the first week of the year are; For example,...
UDate getTime(UErrorCode &status) const
Gets this Calendar's time as milliseconds.
UBool equals(const Calendar &when, UErrorCode &status) const
Compares the Calendar time, whereas Calendar::operator== compares the equality of Calendar objects.
static UBool unregister(URegistryKey key, UErrorCode &status)
Unregister a previously-registered CalendarFactory using the key returned from the register call.
int32_t getGregorianDayOfYear() const
Return the day of year (1-based) on the Gregorian calendar as computed by computeGregorianFields().
static Calendar * createInstance(TimeZone *zoneToAdopt, const Locale &aLocale, UErrorCode &success)
Creates a Calendar using the given timezone and given locale.