Logo Search packages:      
Sourcecode: icu version File versions  Download package

Public Types | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | Private Member Functions | Private Attributes | Friends

Calendar Class Reference

#include <calendar.h>

Inheritance diagram for Calendar:
Inheritance graph
Collaboration diagram for Calendar:
Collaboration graph

List of all members.

Public Types

enum  EAmpm { AM, PM }
enum  EDateFields {
enum  EDaysOfWeek {
enum  EMonths {

Public Member Functions

virtual void add (EDateFields field, int32_t amount, UErrorCode &status)
virtual void add (UCalendarDateFields field, int32_t amount, UErrorCode &status)
void adoptTimeZone (TimeZone *value)
UBool after (const Calendar &when, UErrorCode &status) const
UBool before (const Calendar &when, UErrorCode &status) const
void clear (void)
void clear (EDateFields field)
void clear (UCalendarDateFields field)
virtual Calendarclone (void) const =0
virtual UDate defaultCenturyStart () const =0
virtual int32_t defaultCenturyStartYear () const =0
UBool equals (const Calendar &when, UErrorCode &status) const
virtual int32_t fieldDifference (UDate when, EDateFields field, UErrorCode &status)
virtual int32_t fieldDifference (UDate when, UCalendarDateFields field, UErrorCode &status)
int32_t get (EDateFields field, UErrorCode &status) const
int32_t get (UCalendarDateFields field, UErrorCode &status) const
int32_t getActualMaximum (EDateFields field, UErrorCode &status) const
virtual int32_t getActualMaximum (UCalendarDateFields field, UErrorCode &status) const
virtual int32_t getActualMinimum (UCalendarDateFields field, UErrorCode &status) const
int32_t getActualMinimum (EDateFields field, UErrorCode &status) const
virtual UClassID getDynamicClassID (void) const =0
UCalendarDaysOfWeek getFirstDayOfWeek (UErrorCode &status) const
EDaysOfWeek getFirstDayOfWeek (void) const
virtual int32_t getGreatestMinimum (EDateFields field) const
virtual int32_t getGreatestMinimum (UCalendarDateFields field) const
virtual int32_t getLeastMaximum (EDateFields field) const
virtual int32_t getLeastMaximum (UCalendarDateFields field) const
Locale getLocale (ULocDataLocaleType type, UErrorCode &status) const
const char * getLocaleID (ULocDataLocaleType type, UErrorCode &status) const
virtual int32_t getMaximum (EDateFields field) const
virtual int32_t getMaximum (UCalendarDateFields field) const
uint8_t getMinimalDaysInFirstWeek (void) const
virtual int32_t getMinimum (EDateFields field) const
virtual int32_t getMinimum (UCalendarDateFields field) const
UDate getTime (UErrorCode &status) const
const TimeZonegetTimeZone (void) const
virtual const char * getType () const =0
virtual UBool haveDefaultCentury () const =0
virtual UBool inDaylightTime (UErrorCode &status) const =0
virtual UBool isEquivalentTo (const Calendar &other) const
UBool isLenient (void) const
UBool isSet (EDateFields field) const
UBool isSet (UCalendarDateFields field) const
UBool operator!= (const Calendar &that) const
virtual UBool operator== (const Calendar &that) const
TimeZoneorphanTimeZone (void)
virtual void roll (UCalendarDateFields field, int32_t amount, UErrorCode &status)
virtual void roll (EDateFields field, int32_t amount, UErrorCode &status)
void roll (EDateFields field, UBool up, UErrorCode &status)
void roll (UCalendarDateFields 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)
void set (UCalendarDateFields field, int32_t value)
void set (EDateFields field, int32_t value)
void set (int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute)
void setFirstDayOfWeek (EDaysOfWeek value)
void setFirstDayOfWeek (UCalendarDaysOfWeek 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 Calendar *U_EXPORT2 createInstance (UErrorCode &success)
static Calendar *U_EXPORT2 createInstance (TimeZone *zoneToAdopt, UErrorCode &success)
static Calendar *U_EXPORT2 createInstance (const Locale &aLocale, UErrorCode &success)
static Calendar *U_EXPORT2 createInstance (TimeZone *zoneToAdopt, const Locale &aLocale, UErrorCode &success)
static Calendar *U_EXPORT2 createInstance (const TimeZone &zone, UErrorCode &success)
static Calendar *U_EXPORT2 createInstance (const TimeZone &zoneToAdopt, const Locale &aLocale, UErrorCode &success)
static StringEnumerationgetAvailableLocales (void)
static const Locale *U_EXPORT2 getAvailableLocales (int32_t &count)
static StringEnumeration *U_EXPORT2 getKeywordValuesForLocale (const char *key, const Locale &locale, UBool commonlyUsed, UErrorCode &status)
static UDate U_EXPORT2 getNow (void)
static void U_EXPORT2 operator delete (void *p) U_NO_THROW
static void U_EXPORT2 operator delete (void *, void *) U_NO_THROW
static void U_EXPORT2 operator delete[] (void *p) U_NO_THROW
static void *U_EXPORT2 operator new (size_t, void *ptr) U_NO_THROW
static void *U_EXPORT2 operator new (size_t size) U_NO_THROW
static void *U_EXPORT2 operator new[] (size_t size) U_NO_THROW
static URegistryKey registerFactory (ICUServiceFactory *toAdopt, UErrorCode &status)
static UBool unregister (URegistryKey key, UErrorCode &status)

Protected Types

enum  { kResolveSTOP = -1, kResolveRemap = 32 }
enum  { kUnset = 0, kInternallySet, kMinimumUserStamp }
enum  ELimitType {

Protected Member Functions

 Calendar (UErrorCode &success)
 Calendar (const Calendar &source)
 Calendar (TimeZone *zone, const Locale &aLocale, UErrorCode &success)
 Calendar (const TimeZone &zone, const Locale &aLocale, UErrorCode &success)
void complete (UErrorCode &status)
virtual void computeFields (UErrorCode &status)
void computeGregorianFields (int32_t julianDay, UErrorCode &ec)
int32_t computeJulianDay ()
int32_t computeMillisInDay ()
virtual void computeTime (UErrorCode &status)
int32_t computeZoneOffset (double millis, int32_t millisInDay, UErrorCode &ec)
virtual int32_t getDefaultDayInMonth (int32_t eyear, int32_t month)
virtual int32_t getDefaultMonthInYear (int32_t eyear)
virtual const
UFieldResolutionTable * 
getFieldResolutionTable () const
int32_t getGregorianDayOfMonth () const
int32_t getGregorianDayOfYear () const
int32_t getGregorianMonth () const
int32_t getGregorianYear () const
virtual int32_t getLimit (UCalendarDateFields field, ELimitType limitType) const
int32_t getLocalDOW ()
double getTimeInMillis (UErrorCode &status) const
virtual void handleComputeFields (int32_t julianDay, UErrorCode &status)
virtual int32_t handleComputeJulianDay (UCalendarDateFields bestField)
virtual int32_t handleComputeMonthStart (int32_t eyear, int32_t month, UBool useMonth) const =0
virtual int32_t handleGetExtendedYear ()=0
virtual int32_t handleGetExtendedYearFromWeekFields (int32_t yearWoy, int32_t woy)
virtual int32_t handleGetLimit (UCalendarDateFields field, ELimitType limitType) const =0
virtual int32_t handleGetMonthLength (int32_t extendedYear, int32_t month) const
virtual int32_t handleGetYearLength (int32_t eyear) const
int32_t internalGet (EDateFields field) const
int32_t internalGet (UCalendarDateFields field, int32_t defaultValue) const
int32_t internalGet (UCalendarDateFields field) const
UDate internalGetTime (void) const
void internalSet (UCalendarDateFields field, int32_t value)
void internalSet (EDateFields field, int32_t value)
void internalSetTime (UDate time)
UCalendarDateFields newerField (UCalendarDateFields defaultField, UCalendarDateFields alternateField) const
int32_t newestStamp (UCalendarDateFields start, UCalendarDateFields end, int32_t bestSoFar) const
Calendaroperator= (const Calendar &right)
virtual void pinField (UCalendarDateFields field, UErrorCode &status)
virtual void prepareGetActual (UCalendarDateFields field, UBool isMinimum, UErrorCode &status)
UCalendarDateFields resolveFields (const UFieldResolutionTable *precedenceTable)
void setTimeInMillis (double millis, UErrorCode &status)
int32_t weekNumber (int32_t dayOfPeriod, int32_t dayOfWeek)
int32_t weekNumber (int32_t desiredDay, int32_t dayOfPeriod, int32_t dayOfWeek)

Static Protected Member Functions

static uint8_t julianDayToDayOfWeek (double julian)

Protected Attributes

UBool fAreAllFieldsSet
UBool fAreFieldsSet
UBool fAreFieldsVirtuallySet
int32_t fFields [UCAL_FIELD_COUNT]
UBool fIsTimeSet
int32_t fStamp [UCAL_FIELD_COUNT]

Static Protected Attributes

static const UFieldResolutionTable kDatePrecedence []
static const UFieldResolutionTable kDOWPrecedence []
static const UFieldResolutionTable kYearPrecedence []

Private Member Functions

void computeGregorianAndDOWFields (int32_t julianDay, UErrorCode &ec)
void computeWeekFields (UErrorCode &ec)
int32_t getActualHelper (UCalendarDateFields field, int32_t startValue, int32_t endValue, UErrorCode &status) const
void setWeekCountData (const Locale &desiredLocale, const char *type, UErrorCode &success)
void updateTime (UErrorCode &status)
virtual void validateField (UCalendarDateFields field, UErrorCode &status)
void validateField (UCalendarDateFields field, int32_t min, int32_t max, UErrorCode &status)
void validateFields (UErrorCode &status)

Private Attributes

char actualLocale [ULOC_FULLNAME_CAPACITY]
UCalendarDaysOfWeek fFirstDayOfWeek
int32_t fGregorianDayOfMonth
int32_t fGregorianDayOfYear
int32_t fGregorianMonth
int32_t fGregorianYear
UBool fLenient
uint8_t fMinimalDaysInFirstWeek
int32_t fNextStamp
UDate fTime


class CalendarFactory
class CalendarService
class DefaultCalendarFactory

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

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, 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.


For the time of day:


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.

ICU 2.0

Definition at line 165 of file calendar.h.

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

Generated by  Doxygen 1.6.0   Back to index