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 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, FIELD_COUNT, DAY_OF_MONTH = DATE } |
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 | |
virtual Calendar * | clone (void) const =0 |
Create and return a polymorphic copy of this calendar. | |
UDate | getTime (UErrorCode &status) const |
Gets this Calendar's time as milliseconds. | |
void | setTime (UDate date, UErrorCode &status) |
Sets this Calendar's current time with the given UDate. | |
virtual UBool | operator== (const Calendar &that) const |
Compares the equality of two Calendar objects. | |
UBool | operator!= (const Calendar &that) const |
Compares the inequality of two Calendar objects. | |
UBool | equals (const Calendar &when, UErrorCode &status) const |
Compares the Calendar time, whereas Calendar::operator== compares the equality of Calendar objects. | |
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 | equivalentTo (const Calendar &other) const |
Return true if another Calendar object is equivalent to this one. | |
virtual void | add (EDateFields field, int32_t amount, UErrorCode &status)=0 |
UDate Arithmetic function. | |
void | roll (EDateFields field, UBool up, UErrorCode &status) |
Time Field Rolling function. | |
virtual void | roll (EDateFields field, int32_t amount, UErrorCode &status)=0 |
Time Field Rolling function. | |
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. | |
void | adoptTimeZone (TimeZone *value) |
Sets the calendar's time zone to be the one passed in. | |
void | setTimeZone (const TimeZone &zone) |
Sets the calendar's time zone to be the same as the one passed in. | |
const TimeZone & | getTimeZone (void) const |
Returns a reference to the time zone owned by this calendar. | |
TimeZone * | orphanTimeZone (void) |
Returns the time zone owned by this calendar. | |
virtual UBool | inDaylightTime (UErrorCode &status) const =0 |
Queries if the current date for this Calendar is in Daylight Savings Time. | |
void | setLenient (UBool lenient) |
Specifies whether or not date/time interpretation is to be lenient. | |
UBool | isLenient (void) const |
Tells whether date/time interpretation is to be lenient. | |
void | setFirstDayOfWeek (EDaysOfWeek value) |
Sets what the first day of the week is; e.g., Sunday in US, Monday in France. | |
EDaysOfWeek | getFirstDayOfWeek (void) const |
Gets what the first day of the week is; e.g., Sunday in US, Monday in France. | |
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. | |
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. | |
virtual int32_t | getMinimum (EDateFields field) const =0 |
Gets the minimum value for the given time field. | |
virtual int32_t | getMaximum (EDateFields field) const =0 |
Gets the maximum value for the given time field. | |
virtual int32_t | getGreatestMinimum (EDateFields field) const =0 |
Gets the highest minimum value for the given field if varies. | |
virtual int32_t | getLeastMaximum (EDateFields field) const =0 |
Gets the lowest maximum value for the given field if varies. | |
int32_t | getActualMinimum (EDateFields field, UErrorCode &status) const |
Return the minimum value that this field could have, given the current date. | |
int32_t | getActualMaximum (EDateFields field, UErrorCode &status) const |
Return the maximum value that this field could have, given the current date. | |
int32_t | get (EDateFields field, UErrorCode &status) const |
Gets the value for a given time field. | |
UBool | isSet (EDateFields field) const |
Determines if the given time field has a value set. | |
void | set (EDateFields field, int32_t value) |
Sets the given time field with the given value. | |
void | set (int32_t year, int32_t month, int32_t date) |
Sets the values for the fields YEAR, MONTH, and DATE. | |
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 | 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. | |
void | clear (void) |
Clears the values of all the time fields, making them both unset and assigning them a value of zero. | |
void | clear (EDateFields field) |
Clears the value in the given time field, both making it unset and assigning it a value of zero. | |
virtual UClassID | getDynamicClassID (void) const =0 |
Returns a unique class ID POLYMORPHICALLY. | |
Static Public Member Functions | |
Calendar * | createInstance (UErrorCode &success) |
Creates a Calendar using the default timezone and locale. | |
Calendar * | createInstance (TimeZone *zoneToAdopt, UErrorCode &success) |
Creates a Calendar using the given timezone and the default locale. | |
Calendar * | createInstance (const TimeZone &zone, UErrorCode &success) |
Creates a Calendar using the given timezone and the default locale. | |
Calendar * | createInstance (const Locale &aLocale, UErrorCode &success) |
Creates a Calendar using the default timezone and the given locale. | |
Calendar * | createInstance (TimeZone *zoneToAdopt, const Locale &aLocale, UErrorCode &success) |
Creates a Calendar using the given timezone and given locale. | |
Calendar * | createInstance (const TimeZone &zoneToAdopt, const Locale &aLocale, UErrorCode &success) |
Gets a Calendar using the given timezone and given locale. | |
const Locale * | getAvailableLocales (int32_t &count) |
Returns a list of the locales for which Calendars are installed. | |
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). | |
Protected Types | |
enum | { kUnset = 0, kInternallySet, kMinimumUserStamp } |
Special values of stamp[] . | |
Protected Member Functions | |
Calendar (UErrorCode &success) | |
Constructs a Calendar with the default time zone as returned by TimeZone::createInstance(), and the default locale. | |
Calendar (const Calendar &source) | |
Copy constructor . | |
Calendar & | operator= (const Calendar &right) |
Default assignment operator . | |
Calendar (TimeZone *zone, const Locale &aLocale, UErrorCode &success) | |
Constructs a Calendar with the given time zone and locale. | |
Calendar (const TimeZone &zone, const Locale &aLocale, UErrorCode &success) | |
Constructs a Calendar with the given time zone and locale. | |
virtual void | computeTime (UErrorCode &status)=0 |
Converts Calendar's time field values to GMT as milliseconds. | |
virtual void | computeFields (UErrorCode &status)=0 |
Converts GMT as milliseconds to time field values. | |
double | getTimeInMillis (UErrorCode &status) const |
Gets this Calendar's current time as a long. | |
void | setTimeInMillis (double millis, UErrorCode &status) |
Sets this Calendar's current time from the given long value. | |
void | complete (UErrorCode &status) |
Recomputes the current time from currently set fields, and then fills in any unset fields in the time field list. | |
int32_t | internalGet (EDateFields field) const |
Gets the value for a given time field. | |
void | internalSet (EDateFields field, int32_t value) |
Sets the value for a given time field. | |
UDate | internalGetTime (void) const |
Get the current time without recomputing. | |
void | internalSetTime (UDate time) |
Set the current time without affecting flags or fields. | |
Protected Attributes | |
UBool | fIsTimeSet |
The flag which indicates if the current time is set in the calendar. | |
UBool | fAreFieldsSet |
True if the fields are in sync with the currently set time of this Calendar. | |
UBool | fAreAllFieldsSet |
True if all of the fields have been set. | |
int32_t | fFields [FIELD_COUNT] |
The time fields containing values into which the millis is computed. | |
UBool | fIsSet [FIELD_COUNT] |
The flags which tell if a specified time field for the calendar is set. | |
int32_t | fStamp [FIELD_COUNT] |
Pseudo-time-stamps which specify when each field was set. |
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 JDK provides one concrete subclass of Calendar
: GregorianCalendar
. Future subclasses could represent the various types of lunar calendars in use in many parts of the world.
Like other locale-sensitive classes, Calendar
provides a class method, getInstance
, for getting a generally useful object of this type. Calendar
's getInstance
method returns a GregorianCalendar
object whose time fields have been initialized with the current date and time:
Calendar rightNow = Calendar.getInstance();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, two special circumstances may arise: there may be insufficient information to compute theUDate
(such as only year and month but no day in the month), or there may be inconsistent information (such as "Tuesday, July 15, 1996" -- July 15, 1996 is actually a Monday).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_YEARFor the time of day:
HOUR_OF_DAY AM_PM + HOURNote: for some non-Gregorian calendars, different fields may be necessary for complete disambiguation. For example, a full specification of the historial 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:
- 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
- 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 dateDecember 12, 1996
results inJanuary 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 dateSeptember 12, 1996
results inSeptember 7, 1996
.
Member Enumeration Documentation
|
Useful constants for hour in 12-hour clock. Used in GregorianCalendar. |
|
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. |
|
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. |
|
Useful constants for month. Note: Calendar month is 0-based. |
|
Constructs a Calendar with the default time zone as returned by TimeZone::createInstance(), and the default locale.
|
|
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.
|
|
Constructs a Calendar with the given time zone and locale.
|
|
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.
Implemented in GregorianCalendar. |
|
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 NULL, this function has no effect.
|
|
Returns true if this Calendar's current time is after "when"'s current time.
|
|
Returns true if this Calendar's current time is before "when"'s current time.
|
|
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.
|
|
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. |
|
Create and return a polymorphic copy of this calendar.
Implemented in GregorianCalendar. |
|
Recomputes the current time from currently set fields, and then fills in any unset fields in the time field list.
|
|
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(). Implemented in GregorianCalendar. |
|
Converts Calendar's time field values to GMT as milliseconds.
Implemented in GregorianCalendar. |
|
Gets a Calendar using the given timezone and given locale. The TimeZone is _not_ adopted; the client is still responsible for deleting it.
|
|
Creates a Calendar using the given timezone and given locale. The Calendar takes ownership of zoneToAdopt; the client must not delete it.
|
|
Creates a Calendar using the default timezone and the given locale.
|
|
Creates a Calendar using the given timezone and the default locale. The TimeZone is _not_ adopted; the client is still responsible for deleting it.
|
|
Creates a Calendar using the given timezone and the default locale. The Calendar takes ownership of zoneToAdopt; the client must not delete it.
|
|
Creates a Calendar using the default timezone and locale. Clients are responsible for deleting the object returned.
|
|
Compares the Calendar time, whereas Calendar::operator== compares the equality of Calendar objects.
|
|
Return true if another Calendar object is equivalent to this one. An equivalent Calendar will behave exactly as this one does, but may be set to a different time.
Reimplemented in GregorianCalendar. |
|
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
As a side effect of this call, this calendar is advanced toward Usage: To use this method, call it first with the largest field of interest, then with progressively smaller fields. For example:
|
|
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.
|
|
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.
|
|
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.
|
|
Returns a list of the locales for which Calendars are installed.
|
|
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) } static char fgClassID;
Implemented in GregorianCalendar. |
|
Gets what the first day of the week is; e.g., Sunday in US, Monday in France.
|
|
Gets the highest minimum value for the given field if varies. Otherwise same as getMinimum(). For Gregorian, no difference.
Implemented in GregorianCalendar. |
|
Gets the lowest maximum value for the given field if varies. Otherwise same as getMaximum(). e.g., for Gregorian DAY_OF_MONTH, 28.
Implemented in GregorianCalendar. |
|
Gets the maximum value for the given time field. e.g. for Gregorian DAY_OF_MONTH, 31.
Implemented in GregorianCalendar. |
|
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.
|
|
Gets the minimum value for the given time field. e.g., for Gregorian DAY_OF_MONTH, 1.
Implemented in GregorianCalendar. |
|
Returns the current UTC (GMT) time measured in milliseconds since 0:00:00 on 1/1/70 (derived from the system time).
|
|
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).
|
|
Gets this Calendar's current time as a long.
|
|
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.
|
|
Queries if the current date for this Calendar is in Daylight Savings Time.
Implemented in GregorianCalendar. |
|
Gets the value for a given time field. Subclasses can use this function to get field values without forcing recomputation of time.
|
|
Get the current time without recomputing.
|
|
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. |
|
Set the current time without affecting flags or fields.
|
|
Tells whether date/time interpretation is to be lenient.
|
|
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.
|
|
Compares the inequality of two Calendar objects.
|
|
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.
Reimplemented in GregorianCalendar. |
|
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().
|
|
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; e.g., rolling the year by +1 on "100 BC" will result in "99 BC", for Gregorian calendar. 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.
Implemented in GregorianCalendar. |
|
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; e.g., rolling the year up on "100 BC" will result in "99 BC", for Gregorian calendar. 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.
|
|
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.
|
|
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.
|
|
Sets the values for the fields YEAR, MONTH, and DATE. Other field values are retained; call clear() first if this is not desired.
|
|
Sets the given time field with the given value.
|
|
Sets what the first day of the week is; e.g., Sunday in US, Monday in France.
|
|
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.
|
|
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.
|
|
Sets this Calendar's current time with the given UDate. The time specified should be in non-local UTC (GMT) time.
|
|
Sets this Calendar's current time from the given long value.
|
|
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.
|
|
True if all of the fields have been set. This is initially false, and set to true by computeFields(). |
|
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. |
|
The time fields containing values into which the millis is computed.
|
|
The flags which tell if a specified time field for the calendar is set.
|
|
The flag which indicates if the current time is set in the calendar.
|
|
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. |