Logo Search packages:      
Sourcecode: icu version File versions

Calendar Class Reference

#include <calendar.h>

Inheritance diagram for Calendar:

GregorianCalendar

List of all members.


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 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: <blockquote>

 Calendar rightNow = Calendar.getInstance();
 
</blockquote>

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 the UDate (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.

<blockquote>

 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
 
</blockquote>

For the time of day:

<blockquote>

 HOUR_OF_DAY
 AM_PM + HOUR
 
</blockquote>

Note: 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:

  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.

Definition at line 142 of file calendar.h.


Public Types

enum  EAmpm { AM, PM }
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
}
enum  EDaysOfWeek {
  SUNDAY = 1, MONDAY, TUESDAY, WEDNESDAY,
  THURSDAY, FRIDAY, SATURDAY
}
enum  EMonths {
  JANUARY, FEBRUARY, MARCH, APRIL,
  MAY, JUNE, JULY, AUGUST,
  SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER,
  UNDECIMBER
}

Public Member Functions

virtual void add (EDateFields field, int32_t amount, UErrorCode &status)=0
void adoptTimeZone (TimeZone *value)
UBool after (const Calendar &when, UErrorCode &status) const
UBool before (const Calendar &when, UErrorCode &status) const
void clear (EDateFields field)
void clear (void)
virtual Calendarclone (void) const =0
UBool equals (const Calendar &when, UErrorCode &status) const
virtual UBool equivalentTo (const Calendar &other) const
virtual int32_t fieldDifference (UDate when, EDateFields field, UErrorCode &status)
int32_t get (EDateFields field, UErrorCode &status) const
int32_t getActualMaximum (EDateFields field, UErrorCode &status) const
int32_t getActualMinimum (EDateFields field, UErrorCode &status) const
virtual UClassID getDynamicClassID (void) const =0
EDaysOfWeek getFirstDayOfWeek (void) const
virtual int32_t getGreatestMinimum (EDateFields field) const =0
virtual int32_t getLeastMaximum (EDateFields field) const =0
virtual int32_t getMaximum (EDateFields field) const =0
uint8_t getMinimalDaysInFirstWeek (void) const
virtual int32_t getMinimum (EDateFields field) const =0
UDate getTime (UErrorCode &status) const
const TimeZonegetTimeZone (void) const
virtual UBool inDaylightTime (UErrorCode &status) const =0
UBool isLenient (void) const
UBool isSet (EDateFields field) const
UBool operator!= (const Calendar &that) const
virtual UBool operator== (const Calendar &that) const
TimeZoneorphanTimeZone (void)
virtual void roll (EDateFields field, int32_t amount, UErrorCode &status)=0
void roll (EDateFields field, UBool up, UErrorCode &status)
void set (int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, int32_t second)
void set (int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute)
void set (int32_t year, int32_t month, int32_t date)
void set (EDateFields field, int32_t value)
void setFirstDayOfWeek (EDaysOfWeek value)
void setLenient (UBool lenient)
void setMinimalDaysInFirstWeek (uint8_t value)
void setTime (UDate date, UErrorCode &status)
void setTimeZone (const TimeZone &zone)
virtual ~Calendar ()

Static Public Member Functions

static CalendarcreateInstance (const TimeZone &zoneToAdopt, const Locale &aLocale, UErrorCode &success)
static CalendarcreateInstance (TimeZone *zoneToAdopt, const Locale &aLocale, UErrorCode &success)
static CalendarcreateInstance (const Locale &aLocale, UErrorCode &success)
static CalendarcreateInstance (const TimeZone &zone, UErrorCode &success)
static CalendarcreateInstance (TimeZone *zoneToAdopt, UErrorCode &success)
static CalendarcreateInstance (UErrorCode &success)
static const Locale * getAvailableLocales (int32_t &count)
static UDate getNow (void)

Protected Types

enum  { kUnset = 0, kInternallySet, kMinimumUserStamp }

Protected Member Functions

 Calendar (const TimeZone &zone, const Locale &aLocale, UErrorCode &success)
 Calendar (TimeZone *zone, const Locale &aLocale, UErrorCode &success)
 Calendar (const Calendar &source)
 Calendar (UErrorCode &success)
void complete (UErrorCode &status)
virtual void computeFields (UErrorCode &status)=0
virtual void computeTime (UErrorCode &status)=0
double getTimeInMillis (UErrorCode &status) const
int32_t internalGet (EDateFields field) const
UDate internalGetTime (void) const
void internalSet (EDateFields field, int32_t value)
void internalSetTime (UDate time)
Calendaroperator= (const Calendar &right)
void setTimeInMillis (double millis, UErrorCode &status)

Protected Attributes

UBool fAreAllFieldsSet
UBool fAreFieldsSet
int32_t fFields [FIELD_COUNT]
UBool fIsSet [FIELD_COUNT]
UBool fIsTimeSet
int32_t fStamp [FIELD_COUNT]

Private Member Functions

void setWeekCountData (const Locale &desiredLocale, UErrorCode &success)
void updateTime (UErrorCode &status)

Private Attributes

EDaysOfWeek fFirstDayOfWeek
UBool fLenient
uint8_t fMinimalDaysInFirstWeek
int32_t fNextStamp
UDate fTime
TimeZonefZone

Static Private Attributes

static const char kDateTimeElements [] = "DateTimeElements"

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

Generated by  Doxygen 1.6.0   Back to index