Concrete class which provides the standard calendar used by most of the world
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 leastgetMinimalDaysInFirstWeek()
days from that year. It thus depends on the values ofgetMinimalDaysInFirstWeek()
,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()
isMONDAY
andgetMinimalDaysInFirstWeek()
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()
isSUNDAY
, 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 .
GregorianCalendar(UErrorCode& success)
GregorianCalendar(TimeZone* zoneToAdopt, UErrorCode& success)
success - Indicates the status of GregorianCalendar object construction.
Returns U_ZERO_ERROR if constructed successfully. GregorianCalendar(const TimeZone& zone, UErrorCode& success)
success - Indicates the status of GregorianCalendar object construction.
Returns U_ZERO_ERROR if constructed successfully. GregorianCalendar(const Locale& aLocale, UErrorCode& success)
success - Indicates the status of GregorianCalendar object construction.
Returns U_ZERO_ERROR if constructed successfully. GregorianCalendar(TimeZone* zoneToAdopt, const Locale& aLocale, UErrorCode& success)
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)
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)
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)
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)
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()
GregorianCalendar(const GregorianCalendar& source)
GregorianCalendar& operator=(const GregorianCalendar& right)
virtual Calendar* clone(void) const
void setGregorianChange(UDate date, UErrorCode& success)
success - Output param set to success/failure code on exit. UDate getGregorianChange(void) const
bool_t isLeapYear(int32_t year) const
virtual bool_t operator==(const Calendar& that) const
virtual bool_t equivalentTo(const Calendar& other) const
virtual void add(EDateFields field, int32_t amount, UErrorCode& status)
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)
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
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) const
int32_t getActualMaximum(EDateFields field) const
virtual bool_t inDaylightTime(UErrorCode& status) const
virtual UClassID getDynamicClassID(void) const
static UClassID getStaticClassID(void)
virtual void computeFields(UErrorCode& status)
virtual void computeTime(UErrorCode& status)
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