#include <gregocal.h>
Inheritance diagram for GregorianCalendar::
Public Types | |
enum | EEras { BC, AD } |
Useful constants for GregorianCalendar and TimeZone. More... | |
Public Methods | |
GregorianCalendar (UErrorCode &success) | |
Constructs a default GregorianCalendar using the current time in the default time zone with the default locale. More... | |
GregorianCalendar (TimeZone *zoneToAdopt, UErrorCode &success) | |
Constructs a GregorianCalendar based on the current time in the given time zone with the default locale. More... | |
GregorianCalendar (const TimeZone &zone, UErrorCode &success) | |
Constructs a GregorianCalendar based on the current time in the given time zone with the default locale. More... | |
GregorianCalendar (const Locale &aLocale, UErrorCode &success) | |
Constructs a GregorianCalendar based on the current time in the default time zone with the given locale. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
virtual | ~GregorianCalendar () |
Destructor. More... | |
GregorianCalendar (const GregorianCalendar &source) | |
Copy constructor. More... | |
GregorianCalendar & | operator= (const GregorianCalendar &right) |
Default assignment operator. More... | |
virtual Calendar * | clone (void) const |
Create and return a polymorphic copy of this calendar. More... | |
void | setGregorianChange (UDate date, UErrorCode &success) |
Sets the GregorianCalendar change date. More... | |
UDate | getGregorianChange (void) const |
Gets the Gregorian Calendar change date. More... | |
UBool | isLeapYear (int32_t year) const |
Return true if the given year is a leap year. More... | |
virtual UBool | isEquivalentTo (const Calendar &other) const |
Returns TRUE if the given Calendar object is equivalent to this one. More... | |
virtual void | roll (EDateFields field, int32_t amount, UErrorCode &status) |
(Overrides Calendar) Rolls up or down by the given amount in the specified field. More... | |
virtual void | roll (UCalendarDateFields field, int32_t amount, UErrorCode &status) |
(Overrides Calendar) Rolls up or down by the given amount in the specified field. More... | |
int32_t | getActualMinimum (EDateFields field) const |
Return the minimum value that this field could have, given the current date. More... | |
int32_t | getActualMinimum (UCalendarDateFields field) const |
Return the minimum value that this field could have, given the current date. More... | |
int32_t | getActualMaximum (EDateFields field) const |
Return the maximum value that this field could have, given the current date. More... | |
virtual int32_t | getActualMaximum (UCalendarDateFields field, UErrorCode &status) const |
Return the maximum value that this field could have, given the current date. More... | |
virtual UBool | inDaylightTime (UErrorCode &status) const |
(Overrides Calendar) Return true if the current date for this Calendar is in Daylight Savings Time. More... | |
virtual UClassID | getDynamicClassID (void) const |
Override Calendar Returns a unique class ID POLYMORPHICALLY. More... | |
virtual const char * | getType () const |
Get the calendar type, "gregorian", for use in DateFormatSymbols. More... | |
virtual UBool | haveDefaultCentury () const |
virtual UDate | defaultCenturyStart () const |
virtual int32_t | defaultCenturyStartYear () const |
Static Public Methods | |
UClassID | getStaticClassID (void) |
Return the class ID for this class. More... | |
Protected Methods | |
virtual int32_t | internalGetEra () const |
Return the ERA. More... | |
virtual int32_t | handleComputeMonthStart (int32_t eyear, int32_t month, UBool useMonth) const |
Return the Julian day number of day before the first day of the given month in the given extended year. More... | |
virtual int32_t | handleComputeJulianDay (UCalendarDateFields bestField) |
Subclasses may override this. More... | |
virtual int32_t | handleGetMonthLength (int32_t extendedYear, int32_t month) const |
Return the number of days in the given month of the given extended year of this calendar system. More... | |
virtual int32_t | handleGetYearLength (int32_t eyear) const |
Return the number of days in the given extended year of this calendar system. More... | |
virtual int32_t | monthLength (int32_t month) const |
return the length of the given month. More... | |
virtual int32_t | monthLength (int32_t month, int32_t year) const |
return the length of the month according to the given year. More... | |
int32_t | yearLength (int32_t year) const |
return the length of the given year. More... | |
int32_t | yearLength (void) const |
return the length of the year field. More... | |
void | pinDayOfMonth (void) |
After adjustments such as add(MONTH), add(YEAR), we don't want the month to jump around. More... | |
virtual UDate | getEpochDay (UErrorCode &status) |
Return the day number with respect to the epoch. More... | |
virtual int32_t | handleGetLimit (UCalendarDateFields field, ELimitType limitType) const |
Subclass API for defining limits of different types. More... | |
virtual int32_t | handleGetExtendedYear () |
Return the extended year defined by the current fields. More... | |
virtual int32_t | handleGetExtendedYearFromWeekFields (int32_t yearWoy, int32_t woy) |
Subclasses may override this to convert from week fields (YEAR_WOY and WEEK_OF_YEAR) to an extended year in the case where YEAR, EXTENDED_YEAR are not set. More... | |
virtual void | handleComputeFields (int32_t julianDay, UErrorCode &status) |
Subclasses may override this method to compute several fields specific to each calendar system. More... | |
Private Methods | |
GregorianCalendar () | |
(Overrides Calendar) Converts GMT as milliseconds to time field values. More... | |
UBool | validateFields (void) const |
Validates the values of the set time fields. More... | |
UBool | boundsCheck (int32_t value, UCalendarDateFields field) const |
Validates the value of the given time field. More... | |
int32_t | aggregateStamp (int32_t stamp_a, int32_t stamp_b) |
Return the pseudo-time-stamp for two fields, given their individual pseudo-time-stamps. More... | |
UDate | internalGetDefaultCenturyStart (void) const |
Returns the beginning date of the 100-year window that dates with 2-digit years are considered to fall within. More... | |
int32_t | internalGetDefaultCenturyStartYear (void) const |
Returns the first year of the 100-year window that dates with 2-digit years are considered to fall within. More... | |
Static Private Methods | |
double | computeJulianDayOfYear (UBool isGregorian, int32_t year, UBool &isLeap) |
Compute the julian day number of the given year. More... | |
double | millisToJulianDay (UDate millis) |
Converts time as milliseconds to Julian date. More... | |
UDate | julianDayToMillis (double julian) |
Converts Julian date to time as milliseconds. More... | |
void | initializeSystemDefaultCentury (void) |
Initializes the 100-year window that dates with 2-digit years are considered to fall within so that its start date is 80 years before the current time. More... | |
Private Attributes | |
UDate | fGregorianCutover |
The point at which the Gregorian calendar rules are used, measured in milliseconds from the standard epoch. More... | |
int32_t | fCutoverJulianDay |
Julian day number of the Gregorian cutover. More... | |
UDate | fNormalizedGregorianCutover |
Midnight, local time (using this Calendar's TimeZone) at or before the gregorianCutover. More... | |
int32_t | fGregorianCutoverYear |
The year of the gregorianCutover, with 0 representing 1 BC, -1 representing 2 BC, etc. More... | |
int32_t | fGregorianCutoverJulianDay |
The year of the gregorianCutover, with 0 representing 1 BC, -1 representing 2 BC, etc. More... | |
UBool | fIsGregorian |
Used by handleComputeJulianDay() and handleComputeMonthStart(). More... | |
UBool | fInvertGregorian |
Used by handleComputeJulianDay() and handleComputeMonthStart(). More... | |
Static Private Attributes | |
UDate | fgSystemDefaultCenturyStart |
The system maintains a static default century start date. More... | |
int32_t | fgSystemDefaultCenturyStartYear |
See documentation for systemDefaultCenturyStart. More... | |
const int32_t | fgSystemDefaultCenturyYear |
Default value that indicates the defaultCenturyStartYear is unitialized. More... | |
const UDate | fgSystemDefaultCentury |
Default value that indicates the UDate of the beginning of the system default century. More... |
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) UErrorCode success = U_ZERO_ERROR; const StringEnumeration *ids = TimeZone::createEnumeration(-8 * 60 * 60 * 1000); // if no ids were returned, something is wrong. get out. if (ids == 0 || ids->count(success) == 0) { return; } // begin output cout << "Current Time" << endl; // create a Pacific Standard Time time zone SimpleTimeZone* pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids->unext(NULL, success))); // 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 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 if (U_FAILURE(success)) { cout << "An error occured. success=" << u_errorName(success) << endl; } delete ids; delete calendar; // also deletes pdt
Definition at line 143 of file gregocal.h.
|
Useful constants for GregorianCalendar and TimeZone.
Definition at line 150 of file gregocal.h. |
|
Constructs a default GregorianCalendar using the current time in the default time zone with the default locale.
|
|
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.
|
|
Constructs a GregorianCalendar based on the current time in the given time zone with the default locale.
|
|
Constructs a GregorianCalendar based on the current time in the default time zone with the given locale.
|
|
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.
|
|
Constructs a GregorianCalendar based on the current time in the given time zone with the given locale.
|
|
Constructs a GregorianCalendar with the given AD date set in the default time zone with the default locale.
|
|
Constructs a GregorianCalendar with the given AD date and time set for the default time zone with the default locale.
|
|
Constructs a GregorianCalendar with the given AD date and time set for the default time zone with the default locale.
|
|
Destructor.
|
|
Copy constructor.
|
|
(Overrides Calendar) Converts GMT as milliseconds to time field values.
|
|
Return the pseudo-time-stamp for two fields, given their individual pseudo-time-stamps. If either of the fields is unset, then the aggregate is unset. Otherwise, the aggregate is the later of the two stamps.
|
|
Validates the value of the given time field. True if it's valid. |
|
Create and return a polymorphic copy of this calendar.
Reimplemented from Calendar. |
|
Compute the julian day number of the given year.
|
|
Reimplemented from Calendar. |
|
Reimplemented from Calendar. |
|
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.
Reimplemented from Calendar. |
|
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.
|
|
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().
|
|
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().
|
|
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.
Reimplemented from Calendar. |
|
Return the day number with respect to the epoch. January 1, 1970 (Gregorian) is day zero.
|
|
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.
|
|
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()) ...
|
|
Get the calendar type, "gregorian", for use in DateFormatSymbols.
|
|
Subclasses may override this method to compute several fields specific to each calendar system. These are:
The GregorianCalendar implementation implements a calendar with the specified Julian/Gregorian cutover date.
|
|
Subclasses may override this. This method calls handleGetMonthLength() to obtain the calendar-specific month length.
|
|
Return the Julian day number of day before the first day of the given month in the given extended year. Subclasses should override this method to implement their calendar system.
|
|
Return the extended year defined by the current fields. This will use the UCAL_EXTENDED_YEAR field or the UCAL_YEAR and supra-year fields (such as UCAL_ERA) specific to the calendar system, depending on which set of fields is newer.
|
|
Subclasses may override this to convert from week fields (YEAR_WOY and WEEK_OF_YEAR) to an extended year in the case where YEAR, EXTENDED_YEAR are not set. The Gregorian implementation assumes a yearWoy in gregorian format, according to the current era.
Reimplemented from Calendar. |
|
Subclass API for defining limits of different types. Subclasses must implement this method to return limits for the following fields:
UCAL_ERA UCAL_YEAR UCAL_MONTH UCAL_WEEK_OF_YEAR UCAL_WEEK_OF_MONTH UCAL_DATE (DAY_OF_MONTH on Java) UCAL_DAY_OF_YEAR UCAL_DAY_OF_WEEK_IN_MONTH UCAL_YEAR_WOY UCAL_EXTENDED_YEAR
|
|
Return the number of days in the given month of the given extended year of this calendar system. Subclasses should override this method if they can provide a more correct or more efficient implementation than the default implementation in Calendar.
|
|
Return the number of days in the given extended year of this calendar system. Subclasses should override this method if they can provide a more correct or more efficient implementation than the default implementation in Calendar.
Reimplemented from Calendar. |
|
Reimplemented from Calendar. |
|
(Overrides Calendar) Return true if the current date for this Calendar is in Daylight Savings Time. Recognizes DST_OFFSET, if it is set.
Reimplemented from Calendar. |
|
Initializes the 100-year window that dates with 2-digit years are considered to fall within so that its start date is 80 years before the current time.
|
|
Returns the beginning date of the 100-year window that dates with 2-digit years are considered to fall within.
|
|
Returns the first year of the 100-year window that dates with 2-digit years are considered to fall within.
|
|
Return the ERA. We need a special method for this because the default ERA is AD, but a zero (unset) ERA is BC.
|
|
Returns TRUE if the given Calendar object is equivalent to this one. Calendar override.
Reimplemented from Calendar. |
|
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).
|
|
Converts Julian date to time as milliseconds. The Julian date used here is not a true Julian date, since it is measured from midnight, not noon.
|
|
Converts time as milliseconds to Julian date. The Julian date used here is not a true Julian date, since it is measured from midnight, not noon.
|
|
return the length of the month according to the given year.
|
|
return the length of the given month.
|
|
Default assignment operator.
|
|
After adjustments such as add(MONTH), add(YEAR), we don't want the month to jump around. E.g., we don't want Jan 31 + 1 month to go to Mar 3, we want it to go to Feb 28. Adjustments which might run into this problem call this method to retain the proper month.
|
|
(Overrides Calendar) Rolls up or down by the given amount in the specified field. For more information, see the documentation for Calendar::roll().
Reimplemented from Calendar. |
|
(Overrides Calendar) Rolls up or down by the given amount in the specified field. For more information, see the documentation for Calendar::roll().
Reimplemented from Calendar. |
|
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.
|
|
Validates the values of the set time fields. True if they're all valid.
|
|
return the length of the year field.
|
|
return the length of the given year.
|
|
Julian day number of the Gregorian cutover.
Definition at line 677 of file gregocal.h. |
|
The point at which the Gregorian calendar rules are used, measured in milliseconds from the standard epoch. Default is October 15, 1582 (Gregorian) 00:00:00 UTC, that is, October 4, 1582 (Julian) is followed by October 15, 1582 (Gregorian). This corresponds to Julian day number 2299161. This is measured from the standard epoch, not in Julian Days.
|
|
The year of the gregorianCutover, with 0 representing 1 BC, -1 representing 2 BC, etc.
Definition at line 696 of file gregocal.h. |
|
The year of the gregorianCutover, with 0 representing 1 BC, -1 representing 2 BC, etc.
Definition at line 690 of file gregocal.h. |
|
Used by handleComputeJulianDay() and handleComputeMonthStart(). Temporary field indicating that the sense of the gregorian cutover should be inverted to handle certain calculations on and around the cutover date. Definition at line 727 of file gregocal.h. |
|
Used by handleComputeJulianDay() and handleComputeMonthStart(). Temporary field indicating whether the calendar is currently Gregorian as opposed to Julian. Definition at line 720 of file gregocal.h. |
|
Midnight, local time (using this Calendar's TimeZone) at or before the gregorianCutover. This is a pure date value with no time of day or timezone component. Definition at line 684 of file gregocal.h. |
|
Default value that indicates the UDate of the beginning of the system default century.
Definition at line 772 of file gregocal.h. |
|
The system maintains a static default century start date. This is initialized the first time it is used. Before then, it is set to SYSTEM_DEFAULT_CENTURY to indicate an uninitialized state. Once the system default century date and year are set, they do not change. Definition at line 757 of file gregocal.h. |
|
See documentation for systemDefaultCenturyStart.
Definition at line 762 of file gregocal.h. |
|
Default value that indicates the defaultCenturyStartYear is unitialized.
Definition at line 767 of file gregocal.h. |