class U_I18N_API GregorianCalendar : public Calendar

Concrete class which provides the standard calendar used by most of the world

Inheritance:


Public Classes

enum EEras
Useful constants for GregorianCalendar and TimeZone

Public Methods

GregorianCalendar(UErrorCode& success)
Constructs a default GregorianCalendar using the current time in the default time zone with the default locale
GregorianCalendar(TimeZone* zoneToAdopt, UErrorCode& success)
Constructs a GregorianCalendar based on the current time in the given time zone with the default locale
GregorianCalendar(const TimeZone& zone, UErrorCode& success)
Constructs a GregorianCalendar based on the current time in the given time zone with the default locale
GregorianCalendar(const Locale& aLocale, UErrorCode& success)
Constructs a GregorianCalendar based on the current time in the default time zone with the given locale
GregorianCalendar(TimeZone* zoneToAdopt, const Locale& aLocale, UErrorCode& success)
Constructs a GregorianCalendar based on the current time in the given time zone with the given locale
GregorianCalendar(const TimeZone& zone, const Locale& aLocale, UErrorCode& success)
Constructs a GregorianCalendar based on the current time in the given time zone with the given locale
GregorianCalendar(int32_t year, int32_t month, int32_t date, UErrorCode& success)
Constructs a GregorianCalendar with the given AD date set in the default time zone with the default locale
GregorianCalendar(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, UErrorCode& success)
Constructs a GregorianCalendar with the given AD date and time set for the default time zone with the default locale
GregorianCalendar(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, int32_t second, UErrorCode& success)
Constructs a GregorianCalendar with the given AD date and time set for the default time zone with the default locale
virtual ~GregorianCalendar()
Destructor
GregorianCalendar(const GregorianCalendar& source)
Copy constructor
GregorianCalendar& operator=(const GregorianCalendar& right)
Default assignment operator
virtual Calendar* clone(void) const
Create and return a polymorphic copy of this calendar
void setGregorianChange(UDate date, UErrorCode& success)
Sets the GregorianCalendar change date
UDate getGregorianChange(void) const
Gets the Gregorian Calendar change date
bool_t isLeapYear(int32_t year) const
Return true if the given year is a leap year
virtual bool_t operator==(const Calendar& that) const
Compares the equality of two GregorianCalendar objects
virtual bool_t equivalentTo(const Calendar& other) const
Calendar override
virtual void add(EDateFields field, int32_t amount, UErrorCode& status)
(Overrides Calendar) UDate Arithmetic function
virtual void roll(EDateFields field, int32_t amount, UErrorCode& status)
(Overrides Calendar) Rolls up or down by the given amount in the specified field
virtual int32_t getMinimum(EDateFields field) const
(Overrides Calendar) Returns minimum value for the given field
virtual int32_t getMaximum(EDateFields field) const
(Overrides Calendar) Returns maximum value for the given field
virtual int32_t getGreatestMinimum(EDateFields field) const
(Overrides Calendar) Returns highest minimum value for the given field if varies
virtual int32_t getLeastMaximum(EDateFields field) const
(Overrides Calendar) Returns lowest maximum value for the given field if varies
int32_t getActualMinimum(EDateFields field) const
Return the minimum value that this field could have, given the current date
int32_t getActualMaximum(EDateFields field) const
Return the maximum value that this field could have, given the current date
virtual bool_t inDaylightTime(UErrorCode& status) const
(Overrides Calendar) Return true if the current date for this Calendar is in Daylight Savings Time
virtual UClassID getDynamicClassID(void) const
Override Calendar Returns a unique class ID POLYMORPHICALLY
static UClassID getStaticClassID(void)
Return the class ID for this class

Protected Methods

virtual void computeFields(UErrorCode& status)
(Overrides Calendar) Converts GMT as milliseconds to time field values
virtual void computeTime(UErrorCode& status)
(Overrides Calendar) Converts Calendar's time field values to GMT as milliseconds

Inherited from Calendar:

Public Classes

enum EDateFields
enum EDaysOfWeek
enum EMonths
enum EAmpm

Public Methods

static Calendar* createInstance(UErrorCode& success)
static Calendar* createInstance(TimeZone* zoneToAdopt, UErrorCode& success)
static Calendar* createInstance(const TimeZone& zone, UErrorCode& success)
static Calendar* createInstance(const Locale& aLocale, UErrorCode& success)
static Calendar* createInstance(TimeZone* zoneToAdopt, const Locale& aLocale, UErrorCode& success)
static Calendar* createInstance(const TimeZone& zoneToAdopt, const Locale& aLocale, UErrorCode& success)
static const Locale* getAvailableLocales(int32_t& count)
static UDate getNow(void)
inline UDate getTime(UErrorCode& status) const
inline void setTime(UDate date, UErrorCode& status)
bool_t operator!=(const Calendar& that) const
bool_t equals(const Calendar& when, UErrorCode& status) const
bool_t before(const Calendar& when, UErrorCode& status) const
bool_t after(const Calendar& when, UErrorCode& status) const
void adoptTimeZone(TimeZone* value)
void setTimeZone(const TimeZone& zone)
const TimeZone& getTimeZone(void) const
TimeZone* orphanTimeZone(void)
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
int32_t get(EDateFields field, UErrorCode& status) const
bool_t isSet(EDateFields field) const
void set(EDateFields field, int32_t value)
void set(int32_t year, int32_t month, int32_t date)
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, int32_t hour, int32_t minute, int32_t second)
void clear(void)
void clear(EDateFields field)
inline void Calendar::internalSet(EDateFields field, int32_t value)

Protected Fields

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

Protected Methods

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)
UDate internalGetTime(void) const
void internalSetTime(UDate time)

Documentation

Concrete class which provides the standard calendar used by most of the world.

The standard (Gregorian) calendar has 2 eras, BC and AD.

This implementation handles a single discontinuity, which corresponds by default to the date the Gregorian calendar was originally instituted (October 15, 1582). Not all countries adopted the Gregorian calendar then, so this cutover date may be changed by the caller.

Prior to the institution of the Gregorian Calendar, New Year's Day was March 25. To avoid confusion, this Calendar always uses January 1. A manual adjustment may be made if desired for dates that are prior to the Gregorian changeover and which fall between January 1 and March 24.

Values calculated for the WEEK_OF_YEAR field range from 1 to 53. Week 1 for a year is the first week that contains at least getMinimalDaysInFirstWeek() days from that year. It thus depends on the values of getMinimalDaysInFirstWeek(), getFirstDayOfWeek(), and the day of the week of January 1. Weeks between week 1 of one year and week 1 of the following year are numbered sequentially from 2 to 52 or 53 (as needed).

For example, January 1, 1998 was a Thursday. If getFirstDayOfWeek() is MONDAY and getMinimalDaysInFirstWeek() is 4 (these are the values reflecting ISO 8601 and many national standards), then week 1 of 1998 starts on December 29, 1997, and ends on January 4, 1998. If, however, getFirstDayOfWeek() is SUNDAY, then week 1 of 1998 starts on January 4, 1998, and ends on January 10, 1998; the first three days of 1998 then are part of week 53 of 1997.

Example for using GregorianCalendar:

.    // get the supported ids for GMT-08:00 (Pacific Standard Time)
.    int32_t idsCount;
.    const UnicodeString** ids = TimeZone::createAvailableIDs(-8 * 60 * 60 * 1000, idsCount);
.    // if no ids were returned, something is wrong. get out.
.    if (idsCount == 0) {
.        return;
.    }
.
.    // begin output
.    cout << "Current Time" << endl;
.
.    // create a Pacific Standard Time time zone
.    SimpleTimeZone* pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, *(ids[0]));
.    
.    // set up rules for daylight savings time
.    pdt->setStartRule(Calendar::APRIL, 1, Calendar::SUNDAY, 2 * 60 * 60 * 1000);
.    pdt->setEndRule(Calendar::OCTOBER, -1, Calendar::SUNDAY, 2 * 60 * 60 * 1000);
.    
.    // create a GregorianCalendar with the Pacific Daylight time zone
.    // and the current date and time
.    UErrorCode success = U_ZERO_ERROR;
.    Calendar* calendar = new GregorianCalendar( pdt, success );
.    
.    // print out a bunch of interesting things
.    cout << "ERA: " << calendar->get( Calendar::ERA, success ) << endl;
.    cout << "YEAR: " << calendar->get( Calendar::YEAR, success ) << endl;
.    cout << "MONTH: " << calendar->get( Calendar::MONTH, success ) << endl;
.    cout << "WEEK_OF_YEAR: " << calendar->get( Calendar::WEEK_OF_YEAR, success ) << endl;
.    cout << "WEEK_OF_MONTH: " << calendar->get( Calendar::WEEK_OF_MONTH, success ) << endl;
.    cout << "DATE: " << calendar->get( Calendar::DATE, success ) << endl;
.    cout << "DAY_OF_MONTH: " << calendar->get( Calendar::DAY_OF_MONTH, success ) << endl;
.    cout << "DAY_OF_YEAR: " << calendar->get( Calendar::DAY_OF_YEAR, success ) << endl;
.    cout << "DAY_OF_WEEK: " << calendar->get( Calendar::DAY_OF_WEEK, success ) << endl;
.    cout << "DAY_OF_WEEK_IN_MONTH: " << calendar->get( Calendar::DAY_OF_WEEK_IN_MONTH, success ) << endl;
.    cout << "AM_PM: " << calendar->get( Calendar::AM_PM, success ) << endl;
.    cout << "HOUR: " << calendar->get( Calendar::HOUR, success ) << endl;
.    cout << "HOUR_OF_DAY: " << calendar->get( Calendar::HOUR_OF_DAY, success ) << endl;
.    cout << "MINUTE: " << calendar->get( Calendar::MINUTE, success ) << endl;
.    cout << "SECOND: " << calendar->get( Calendar::SECOND, success ) << endl;
.    cout << "MILLISECOND: " << calendar->get( Calendar::MILLISECOND, success ) << endl;
.    cout << "ZONE_OFFSET: " << (calendar->get( Calendar::ZONE_OFFSET, success )/(60*60*1000)) << endl;
.    cout << "DST_OFFSET: " << (calendar->get( Calendar::DST_OFFSET, success )/(60*60*1000)) << endl;
.
.    cout << "Current Time, with hour reset to 3" << endl;
.    calendar->clear(Calendar::HOUR_OF_DAY); // so doesn't override
.    calendar->set(Calendar::HOUR, 3);
.    cout << "ERA: " << calendar->get( Calendar::ERA, success ) << endl;
.    cout << "YEAR: " << calendar->get( Calendar::YEAR, success ) << endl;
.    cout << "MONTH: " << calendar->get( Calendar::MONTH, success ) << endl;
.    cout << "WEEK_OF_YEAR: " << calendar->get( Calendar::WEEK_OF_YEAR, success ) << endl;
.    cout << "WEEK_OF_MONTH: " << calendar->get( Calendar::WEEK_OF_MONTH, success ) << endl;
.    cout << "DATE: " << calendar->get( Calendar::DATE, success ) << endl;
.    cout << "DAY_OF_MONTH: " << calendar->get( Calendar::DAY_OF_MONTH, success ) << endl;
.    cout << "DAY_OF_YEAR: " << calendar->get( Calendar::DAY_OF_YEAR, success ) << endl;
.    cout << "DAY_OF_WEEK: " << calendar->get( Calendar::DAY_OF_WEEK, success ) << endl;
.    cout << "DAY_OF_WEEK_IN_MONTH: " << calendar->get( Calendar::DAY_OF_WEEK_IN_MONTH, success ) << endl;
.    cout << "AM_PM: " << calendar->get( Calendar::AM_PM, success ) << endl;
.    cout << "HOUR: " << calendar->get( Calendar::HOUR, success ) << endl;
.    cout << "HOUR_OF_DAY: " << calendar->get( Calendar::HOUR_OF_DAY, success ) << endl;
.    cout << "MINUTE: " << calendar->get( Calendar::MINUTE, success ) << endl;
.    cout << "SECOND: " << calendar->get( Calendar::SECOND, success ) << endl;
.    cout << "MILLISECOND: " << calendar->get( Calendar::MILLISECOND, success ) << endl;
.    cout << "ZONE_OFFSET: " << (calendar->get( Calendar::ZONE_OFFSET, success )/(60*60*1000)) << endl; // in hours
.    cout << "DST_OFFSET: " << (calendar->get( Calendar::DST_OFFSET, success )/(60*60*1000)) << endl; // in hours
.
.    delete[] ids;
.    delete calendar; // also deletes pdt
.
enum EEras
Useful constants for GregorianCalendar and TimeZone

GregorianCalendar(UErrorCode& success)
Constructs a default GregorianCalendar using the current time in the default time zone with the default locale.
Parameters:
success - Indicates the status of GregorianCalendar object construction. Returns U_ZERO_ERROR if constructed successfully.

GregorianCalendar(TimeZone* zoneToAdopt, UErrorCode& success)
Constructs a GregorianCalendar based on the current time in the given time zone with the default locale. Clients are no longer responsible for deleting the given time zone object after it's adopted.
Parameters:
zoneToAdopt - The given timezone.
success - Indicates the status of GregorianCalendar object construction. Returns U_ZERO_ERROR if constructed successfully.

GregorianCalendar(const TimeZone& zone, UErrorCode& success)
Constructs a GregorianCalendar based on the current time in the given time zone with the default locale.
Parameters:
zone - The given timezone.
success - Indicates the status of GregorianCalendar object construction. Returns U_ZERO_ERROR if constructed successfully.

GregorianCalendar(const Locale& aLocale, UErrorCode& success)
Constructs a GregorianCalendar based on the current time in the default time zone with the given locale.
Parameters:
aLocale - The given locale.
success - Indicates the status of GregorianCalendar object construction. Returns U_ZERO_ERROR if constructed successfully.

GregorianCalendar(TimeZone* zoneToAdopt, const Locale& aLocale, UErrorCode& success)
Constructs a GregorianCalendar based on the current time in the given time zone with the given locale. Clients are no longer responsible for deleting the given time zone object after it's adopted.
Parameters:
zoneToAdopt - The given timezone.
aLocale - The given locale.
success - Indicates the status of GregorianCalendar object construction. Returns U_ZERO_ERROR if constructed successfully.

GregorianCalendar(const TimeZone& zone, const Locale& aLocale, UErrorCode& success)
Constructs a GregorianCalendar based on the current time in the given time zone with the given locale.
Parameters:
zone - The given timezone.
aLocale - The given locale.
success - Indicates the status of GregorianCalendar object construction. Returns U_ZERO_ERROR if constructed successfully.

GregorianCalendar(int32_t year, int32_t month, int32_t date, UErrorCode& success)
Constructs a GregorianCalendar with the given AD date set in the default time zone with the default locale.
Parameters:
year - The value used to set the YEAR time field in the calendar.
month - The value used to set the MONTH time field in the calendar. Month value is 0-based. e.g., 0 for January.
date - The value used to set the DATE time field in the calendar.
success - Indicates the status of GregorianCalendar object construction. Returns U_ZERO_ERROR if constructed successfully.

GregorianCalendar(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, UErrorCode& success)
Constructs a GregorianCalendar with the given AD date and time set for the default time zone with the default locale.
Parameters:
year - The value used to set the YEAR time field in the calendar.
month - The value used to set the MONTH time field in the calendar. Month value is 0-based. e.g., 0 for January.
date - The value used to set the DATE time field in the calendar.
hour - The value used to set the HOUR_OF_DAY time field in the calendar.
minute - The value used to set the MINUTE time field in the calendar.
success - Indicates the status of GregorianCalendar object construction. Returns U_ZERO_ERROR if constructed successfully.

GregorianCalendar(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, int32_t second, UErrorCode& success)
Constructs a GregorianCalendar with the given AD date and time set for the default time zone with the default locale.
Parameters:
year - The value used to set the YEAR time field in the calendar.
month - The value used to set the MONTH time field in the calendar. Month value is 0-based. e.g., 0 for January.
date - The value used to set the DATE time field in the calendar.
hour - The value used to set the HOUR_OF_DAY time field in the calendar.
minute - The value used to set the MINUTE time field in the calendar.
second - The value used to set the SECOND time field in the calendar.
success - Indicates the status of GregorianCalendar object construction. Returns U_ZERO_ERROR if constructed successfully.

virtual ~GregorianCalendar()
Destructor

GregorianCalendar(const GregorianCalendar& source)
Copy constructor

GregorianCalendar& operator=(const GregorianCalendar& right)
Default assignment operator

virtual Calendar* clone(void) const
Create and return a polymorphic copy of this calendar

void setGregorianChange(UDate date, UErrorCode& success)
Sets the GregorianCalendar change date. This is the point when the switch from Julian dates to Gregorian dates occurred. Default is 00:00:00 local time, October 15, 1582. Previous to this time and date will be Julian dates.
Parameters:
date - The given Gregorian cutover date.
success - Output param set to success/failure code on exit.

UDate getGregorianChange(void) const
Gets the Gregorian Calendar change date. This is the point when the switch from Julian dates to Gregorian dates occurred. Default is 00:00:00 local time, October 15, 1582. Previous to this time and date will be Julian dates.
Returns:
The Gregorian cutover time for this calendar.

bool_t isLeapYear(int32_t year) const
Return true if the given year is a leap year. Determination of whether a year is a leap year is actually very complicated. We do something crude and mostly correct here, but for a real determination you need a lot of contextual information. For example, in Sweden, the change from Julian to Gregorian happened in a complex way resulting in missed leap years and double leap years between 1700 and 1753. Another example is that after the start of the Julian calendar in 45 B.C., the leap years did not regularize until 8 A.D. This method ignores these quirks, and pays attention only to the Julian onset date and the Gregorian cutover (which can be changed).
Returns:
True if the given year is a leap year; false otherwise.
Parameters:
year - The given year.

virtual bool_t operator==(const Calendar& that) const
Compares the equality of two GregorianCalendar objects. Objects of different subclasses are considered unequal. This is a strict equality test; see the documentation for Calendar::operator==().
Returns:
True if the given GregorianCalendar is the same as this GregorianCalendar; false otherwise.
Parameters:
that - The GregorianCalendar object to be compared with.

virtual bool_t equivalentTo(const Calendar& other) const
Calendar override. 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.

virtual void add(EDateFields field, int32_t amount, UErrorCode& status)
(Overrides Calendar) UDate Arithmetic function. Adds the specified (signed) amount of time to the given time field, based on the calendar's rules. For more information, see the documentation for Calendar::add().
Parameters:
field - The time field.
amount - The amount of date or time to be added to the field.
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.

virtual void roll(EDateFields field, int32_t amount, UErrorCode& status)
(Overrides Calendar) Rolls up or down by the given amount in the specified field. For more information, see the documentation for Calendar::roll().
Parameters:
field - The time field.
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.

virtual int32_t getMinimum(EDateFields field) const
(Overrides Calendar) Returns minimum value for the given field. e.g. for Gregorian DAY_OF_MONTH, 1.

virtual int32_t getMaximum(EDateFields field) const
(Overrides Calendar) Returns maximum value for the given field. e.g. for Gregorian DAY_OF_MONTH, 31.

virtual int32_t getGreatestMinimum(EDateFields field) const
(Overrides Calendar) Returns highest minimum value for the given field if varies. Otherwise same as getMinimum(). For Gregorian, no difference.

virtual int32_t getLeastMaximum(EDateFields field) const
(Overrides Calendar) Returns lowest maximum value for the given field if varies. Otherwise same as getMaximum(). For Gregorian DAY_OF_MONTH, 28.

int32_t getActualMinimum(EDateFields field) const
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().

int32_t getActualMaximum(EDateFields field) const
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.

virtual bool_t inDaylightTime(UErrorCode& status) const
(Overrides Calendar) Return true if the current date for this Calendar is in Daylight Savings Time. Recognizes DST_OFFSET, if it is set.
Returns:
True if the current date for this Calendar is in Daylight Savings Time, false, otherwise.
Parameters:
status - Fill-in parameter which receives the status of this operation.

virtual UClassID getDynamicClassID(void) const
Override Calendar Returns a unique class ID POLYMORPHICALLY. Pure virtual override. 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.
Returns:
The class ID for this object. All objects of a given class have the same class ID. Objects of other classes have different class IDs.

static UClassID getStaticClassID(void)
Return the class ID for this class. This is useful only for comparing to a return value from getDynamicClassID(). For example: Base* polymorphic_pointer = createPolymorphicObject(); if (polymorphic_pointer->getDynamicClassID() == Derived::getStaticClassID()) ...
Returns:
The class ID for all objects of this class.

virtual void computeFields(UErrorCode& status)
(Overrides Calendar) Converts GMT as milliseconds to time field values

virtual void computeTime(UErrorCode& status)
(Overrides Calendar) Converts Calendar's time field values to GMT as milliseconds.
Parameters:
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.


This class has no child classes.

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