* 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). * *
WEEK_OF_YEAR
getMinimalDaysInFirstWeek()
getFirstDayOfWeek()
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. * *
MONDAY
SUNDAY
Example for using GregorianCalendar: *
* \code * // 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(UCAL_MARCH, 1, UCAL_SUNDAY, 2 * 60 * 60 * 1000); * pdt->setEndRule(UCAL_NOVEMBER, 2, UCAL_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( UCAL_ERA, success ) << endl; * cout << "YEAR: " << calendar->get( UCAL_YEAR, success ) << endl; * cout << "MONTH: " << calendar->get( UCAL_MONTH, success ) << endl; * cout << "WEEK_OF_YEAR: " << calendar->get( UCAL_WEEK_OF_YEAR, success ) << endl; * cout << "WEEK_OF_MONTH: " << calendar->get( UCAL_WEEK_OF_MONTH, success ) << endl; * cout << "DATE: " << calendar->get( UCAL_DATE, success ) << endl; * cout << "DAY_OF_MONTH: " << calendar->get( UCAL_DAY_OF_MONTH, success ) << endl; * cout << "DAY_OF_YEAR: " << calendar->get( UCAL_DAY_OF_YEAR, success ) << endl; * cout << "DAY_OF_WEEK: " << calendar->get( UCAL_DAY_OF_WEEK, success ) << endl; * cout << "DAY_OF_WEEK_IN_MONTH: " << calendar->get( UCAL_DAY_OF_WEEK_IN_MONTH, success ) << endl; * cout << "AM_PM: " << calendar->get( UCAL_AM_PM, success ) << endl; * cout << "HOUR: " << calendar->get( UCAL_HOUR, success ) << endl; * cout << "HOUR_OF_DAY: " << calendar->get( UCAL_HOUR_OF_DAY, success ) << endl; * cout << "MINUTE: " << calendar->get( UCAL_MINUTE, success ) << endl; * cout << "SECOND: " << calendar->get( UCAL_SECOND, success ) << endl; * cout << "MILLISECOND: " << calendar->get( UCAL_MILLISECOND, success ) << endl; * cout << "ZONE_OFFSET: " << (calendar->get( UCAL_ZONE_OFFSET, success )/(60*60*1000)) << endl; * cout << "DST_OFFSET: " << (calendar->get( UCAL_DST_OFFSET, success )/(60*60*1000)) << endl; * * cout << "Current Time, with hour reset to 3" << endl; * calendar->clear(UCAL_HOUR_OF_DAY); // so doesn't override * calendar->set(UCAL_HOUR, 3); * cout << "ERA: " << calendar->get( UCAL_ERA, success ) << endl; * cout << "YEAR: " << calendar->get( UCAL_YEAR, success ) << endl; * cout << "MONTH: " << calendar->get( UCAL_MONTH, success ) << endl; * cout << "WEEK_OF_YEAR: " << calendar->get( UCAL_WEEK_OF_YEAR, success ) << endl; * cout << "WEEK_OF_MONTH: " << calendar->get( UCAL_WEEK_OF_MONTH, success ) << endl; * cout << "DATE: " << calendar->get( UCAL_DATE, success ) << endl; * cout << "DAY_OF_MONTH: " << calendar->get( UCAL_DAY_OF_MONTH, success ) << endl; * cout << "DAY_OF_YEAR: " << calendar->get( UCAL_DAY_OF_YEAR, success ) << endl; * cout << "DAY_OF_WEEK: " << calendar->get( UCAL_DAY_OF_WEEK, success ) << endl; * cout << "DAY_OF_WEEK_IN_MONTH: " << calendar->get( UCAL_DAY_OF_WEEK_IN_MONTH, success ) << endl; * cout << "AM_PM: " << calendar->get( UCAL_AM_PM, success ) << endl; * cout << "HOUR: " << calendar->get( UCAL_HOUR, success ) << endl; * cout << "HOUR_OF_DAY: " << calendar->get( UCAL_HOUR_OF_DAY, success ) << endl; * cout << "MINUTE: " << calendar->get( UCAL_MINUTE, success ) << endl; * cout << "SECOND: " << calendar->get( UCAL_SECOND, success ) << endl; * cout << "MILLISECOND: " << calendar->get( UCAL_MILLISECOND, success ) << endl; * cout << "ZONE_OFFSET: " << (calendar->get( UCAL_ZONE_OFFSET, success )/(60*60*1000)) << endl; // in hours * cout << "DST_OFFSET: " << (calendar->get( UCAL_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 * \endcode *
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
MINIMUM
GREATEST_MINIMUM
LEAST_MAXIMUM
MAXIMUM
The GregorianCalendar implementation implements * a calendar with the specified Julian/Gregorian cutover date. * @internal */ virtual void handleComputeFields(int32_t julianDay, UErrorCode &status); private: /** * Compute the julian day number of the given year. * @param isGregorian if true, using Gregorian calendar, otherwise using Julian calendar * @param year the given year. * @param isLeap true if the year is a leap year. * @return */ static double computeJulianDayOfYear(UBool isGregorian, int32_t year, UBool& isLeap); /** * Validates the values of the set time fields. True if they're all valid. * @return True if the set time fields are all valid. */ UBool validateFields(void) const; /** * Validates the value of the given time field. True if it's valid. */ UBool boundsCheck(int32_t value, UCalendarDateFields field) const; /** * 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. * @param stamp_a One given field. * @param stamp_b Another given field. * @return the pseudo-time-stamp for two fields */ int32_t aggregateStamp(int32_t stamp_a, int32_t stamp_b); /** * 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. */ UDate fGregorianCutover; /** * Julian day number of the Gregorian cutover */ int32_t fCutoverJulianDay; /** * 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. */ UDate fNormalizedGregorianCutover;// = gregorianCutover; /** * The year of the gregorianCutover, with 0 representing * 1 BC, -1 representing 2 BC, etc. */ int32_t fGregorianCutoverYear;// = 1582; /** * The year of the gregorianCutover, with 0 representing * 1 BC, -1 representing 2 BC, etc. */ int32_t fGregorianCutoverJulianDay;// = 2299161; /** * 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. * * @param millis The given milliseconds. * @return The Julian date number. */ static double millisToJulianDay(UDate millis); /** * 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. * * @param julian The given Julian date number. * @return Time as milliseconds. */ static UDate julianDayToMillis(double julian); /** * Used by handleComputeJulianDay() and handleComputeMonthStart(). * Temporary field indicating whether the calendar is currently Gregorian as opposed to Julian. */ UBool fIsGregorian; /** * 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. */ UBool fInvertGregorian; public: // internal implementation /** * @return TRUE if this calendar has the notion of a default century * @internal */ virtual UBool haveDefaultCentury() const; /** * @return the start of the default century * @internal */ virtual UDate defaultCenturyStart() const; /** * @return the beginning year of the default century * @internal */ virtual int32_t defaultCenturyStartYear() const; }; U_NAMESPACE_END #endif /* #if !UCONFIG_NO_FORMATTING */ #endif /* U_SHOW_CPLUSPLUS_API */ #endif // _GREGOCAL //eof