Calendar
is an abstract base class for converting between aUDate
object and a set of integer fields such asYEAR
,MONTH
,DAY
,HOUR
, and so on
Calendar
is an abstract base class for converting between aUDate
object and a set of integer fields such asYEAR
,MONTH
,DAY
,HOUR
, and so on. (AUDate
object represents a specific instant in time with millisecond precision. See {@link UDate} for information about theUDate
class.)Subclasses of
Calendar
interpret aUDate
according to the rules of a specific calendar system. The JDK provides one concrete subclass ofCalendar
: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
'sgetInstance
method returns aGregorianCalendar
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.
For the time of day: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_YEARHOUR_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 {@link 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
.
NOTE: Do not use this method -- use roll(EDateFields, int, UErrorCode&) instead.
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.
Concrete subclasses of Calendar must implement getDynamicClassID() and also a
static method and data member:
static UClassID getStaticClassID() { return (UClassID)&fgClassID; }
static char fgClassID;
This should really be named areFieldsInSync, but the old name is retained
for backward compatibility.
enum EDaysOfWeek
enum EMonths
enum EAmpm
virtual ~Calendar()
virtual Calendar* clone(void) const
static Calendar* createInstance(UErrorCode& success)
static Calendar* createInstance(TimeZone* zoneToAdopt, UErrorCode& success)
success - Indicates the success/failure of Calendar creation. Filled in
with U_ZERO_ERROR if created successfully, set to a failure result
otherwise.
static Calendar* createInstance(const TimeZone& zone, UErrorCode& success)
success - Indicates the success/failure of Calendar creation. Filled in
with U_ZERO_ERROR if created successfully, set to a failure result
otherwise.
static Calendar* createInstance(const Locale& aLocale, UErrorCode& success)
success - Indicates the success/failure of Calendar creation. Filled in
with U_ZERO_ERROR if created successfully, set to a failure result
otherwise.
static Calendar* createInstance(TimeZone* zoneToAdopt, const Locale& aLocale, UErrorCode& success)
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.
static Calendar* createInstance(const TimeZone& zoneToAdopt, const Locale& aLocale, UErrorCode& success)
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.
static const Locale* getAvailableLocales(int32_t& count)
static UDate getNow(void)
inline UDate getTime(UErrorCode& status) const
inline void setTime(UDate date, UErrorCode& status)
virtual bool_t operator==(const Calendar& that) const
bool_t operator!=(const Calendar& that) const
bool_t equals(const Calendar& when, UErrorCode& status) 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.
bool_t before(const Calendar& when, UErrorCode& status) 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.
bool_t after(const Calendar& when, UErrorCode& status) 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.
virtual bool_t equivalentTo(const Calendar& other) const
virtual void add(EDateFields field, int32_t amount, UErrorCode& status)
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. void roll(EDateFields field, bool_t up, UErrorCode& status)
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. virtual void roll(EDateFields field, int32_t amount, UErrorCode& status)
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. void adoptTimeZone(TimeZone* value)
void setTimeZone(const TimeZone& zone)
const TimeZone& getTimeZone(void) const
TimeZone* orphanTimeZone(void)
virtual bool_t inDaylightTime(UErrorCode& status) const
void setLenient(bool_t lenient)
bool_t isLenient(void) const
void setFirstDayOfWeek(EDaysOfWeek value)
EDaysOfWeek getFirstDayOfWeek(void) const
void setMinimalDaysInFirstWeek(uint8_t value)
uint8_t getMinimalDaysInFirstWeek(void) const
virtual int32_t getMinimum(EDateFields field) const
virtual int32_t getMaximum(EDateFields field) const
virtual int32_t getGreatestMinimum(EDateFields field) const
virtual int32_t getLeastMaximum(EDateFields field) const
int32_t getActualMinimum(EDateFields field, UErrorCode& status) const
int32_t getActualMaximum(EDateFields field, UErrorCode& status) const
int32_t get(EDateFields field, UErrorCode& status) const
status - Fill-in parameter which receives the status of the operation.
bool_t isSet(EDateFields field) const
void set(EDateFields field, int32_t value)
value - The value to be set for the given time field. void set(int32_t year, int32_t month, int32_t date)
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. void set(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute)
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. void set(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, int32_t second)
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. void clear(void)
void clear(EDateFields field)
virtual UClassID getDynamicClassID(void) const
Calendar(UErrorCode& success)
Calendar(const Calendar& source)
Calendar& operator=(const Calendar& right)
Calendar(TimeZone* zone, const Locale& aLocale, UErrorCode& success)
aLocale - The given locale.
success - Indicates the status of Calendar object construction. Returns
U_ZERO_ERROR if constructed successfully. Calendar(const TimeZone& zone, const Locale& aLocale, UErrorCode& success)
aLocale - The given locale.
success - Indicates the status of Calendar object construction. Returns
U_ZERO_ERROR if constructed successfully. virtual void computeTime(UErrorCode& status)
virtual void computeFields(UErrorCode& status)
double getTimeInMillis(UErrorCode& status) const
void setTimeInMillis( double millis, UErrorCode& status )
void complete(UErrorCode& status)
int32_t internalGet(EDateFields field) const
void internalSet(EDateFields field, int32_t value)
bool_t fIsTimeSet
bool_t fAreFieldsSet
bool_t fAreAllFieldsSet
UDate internalGetTime(void) const
void internalSetTime(UDate time)
int32_t fFields[FIELD_COUNT]
bool_t fIsSet[FIELD_COUNT]
int32_t fStamp[FIELD_COUNT]
inline void Calendar::internalSet(EDateFields field, int32_t value)
alphabetic index hierarchy of classes
this page has been generated automatically by doc++
(c)opyright by Malte Zöckler, Roland Wunderling
contact: doc++@zib.de