Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-14 09:25:36

0001 // © 2016 and later: Unicode, Inc. and others.
0002 // License & terms of use: http://www.unicode.org/copyright.html
0003 /*
0004 * Copyright (C) 1997-2013, International Business Machines Corporation and others.
0005 * All Rights Reserved.
0006 ********************************************************************************
0007 *
0008 * File GREGOCAL.H
0009 *
0010 * Modification History:
0011 *
0012 *   Date        Name        Description
0013 *   04/22/97    aliu        Overhauled header.
0014 *    07/28/98    stephen        Sync with JDK 1.2
0015 *    09/04/98    stephen        Re-sync with JDK 8/31 putback
0016 *    09/14/98    stephen        Changed type of kOneDay, kOneWeek to double.
0017 *                            Fixed bug in roll()
0018 *   10/15/99    aliu        Fixed j31, incorrect WEEK_OF_YEAR computation.
0019 *                           Added documentation of WEEK_OF_YEAR computation.
0020 *   10/15/99    aliu        Fixed j32, cannot set date to Feb 29 2000 AD.
0021 *                           {JDK bug 4210209 4209272}
0022 *   11/07/2003  srl         Update, clean up documentation.
0023 ********************************************************************************
0024 */
0025 
0026 #ifndef GREGOCAL_H
0027 #define GREGOCAL_H
0028 
0029 #include "unicode/utypes.h"
0030 
0031 #if U_SHOW_CPLUSPLUS_API
0032 
0033 #if !UCONFIG_NO_FORMATTING
0034 
0035 #include "unicode/calendar.h"
0036 
0037 /**
0038  * \file 
0039  * \brief C++ API: Concrete class which provides the standard calendar.
0040  */
0041 
0042 U_NAMESPACE_BEGIN
0043 
0044 /** 
0045  * Concrete class which provides the standard calendar used by most of the world.
0046  * <P>
0047  * The standard (Gregorian) calendar has 2 eras, BC and AD.
0048  * <P>
0049  * This implementation handles a single discontinuity, which corresponds by default to
0050  * the date the Gregorian calendar was originally instituted (October 15, 1582). Not all
0051  * countries adopted the Gregorian calendar then, so this cutover date may be changed by
0052  * the caller.
0053  * <P>
0054  * Prior to the institution of the Gregorian Calendar, New Year's Day was March 25. To
0055  * avoid confusion, this Calendar always uses January 1. A manual adjustment may be made
0056  * if desired for dates that are prior to the Gregorian changeover and which fall
0057  * between January 1 and March 24.
0058  *
0059  * <p>Values calculated for the <code>WEEK_OF_YEAR</code> field range from 1 to
0060  * 53.  Week 1 for a year is the first week that contains at least
0061  * <code>getMinimalDaysInFirstWeek()</code> days from that year.  It thus
0062  * depends on the values of <code>getMinimalDaysInFirstWeek()</code>,
0063  * <code>getFirstDayOfWeek()</code>, and the day of the week of January 1.
0064  * Weeks between week 1 of one year and week 1 of the following year are
0065  * numbered sequentially from 2 to 52 or 53 (as needed).
0066  *
0067  * <p>For example, January 1, 1998 was a Thursday.  If
0068  * <code>getFirstDayOfWeek()</code> is <code>MONDAY</code> and
0069  * <code>getMinimalDaysInFirstWeek()</code> is 4 (these are the values
0070  * reflecting ISO 8601 and many national standards), then week 1 of 1998 starts
0071  * on December 29, 1997, and ends on January 4, 1998.  If, however,
0072  * <code>getFirstDayOfWeek()</code> is <code>SUNDAY</code>, then week 1 of 1998
0073  * starts on January 4, 1998, and ends on January 10, 1998; the first three days
0074  * of 1998 then are part of week 53 of 1997.
0075  *
0076  * <p>Example for using GregorianCalendar:
0077  * <pre>
0078  * \code
0079  *     // get the supported ids for GMT-08:00 (Pacific Standard Time)
0080  *     UErrorCode success = U_ZERO_ERROR;
0081  *     const StringEnumeration *ids = TimeZone::createEnumeration(-8 * 60 * 60 * 1000, success);
0082  *     // if no ids were returned, something is wrong. get out.
0083  *     if (U_FAILURE(success)) {
0084  *         return;
0085  *     }
0086  *
0087  *     // begin output
0088  *     cout << "Current Time" << endl;
0089  *
0090  *     // create a Pacific Standard Time time zone
0091  *     SimpleTimeZone* pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids->unext(nullptr, success)));
0092  *
0093  *     // set up rules for daylight savings time
0094  *     pdt->setStartRule(UCAL_MARCH, 1, UCAL_SUNDAY, 2 * 60 * 60 * 1000);
0095  *     pdt->setEndRule(UCAL_NOVEMBER, 2, UCAL_SUNDAY, 2 * 60 * 60 * 1000);
0096  *
0097  *     // create a GregorianCalendar with the Pacific Daylight time zone
0098  *     // and the current date and time
0099  *     Calendar* calendar = new GregorianCalendar( pdt, success );
0100  *
0101  *     // print out a bunch of interesting things
0102  *     cout << "ERA: " << calendar->get( UCAL_ERA, success ) << endl;
0103  *     cout << "YEAR: " << calendar->get( UCAL_YEAR, success ) << endl;
0104  *     cout << "MONTH: " << calendar->get( UCAL_MONTH, success ) << endl;
0105  *     cout << "WEEK_OF_YEAR: " << calendar->get( UCAL_WEEK_OF_YEAR, success ) << endl;
0106  *     cout << "WEEK_OF_MONTH: " << calendar->get( UCAL_WEEK_OF_MONTH, success ) << endl;
0107  *     cout << "DATE: " << calendar->get( UCAL_DATE, success ) << endl;
0108  *     cout << "DAY_OF_MONTH: " << calendar->get( UCAL_DAY_OF_MONTH, success ) << endl;
0109  *     cout << "DAY_OF_YEAR: " << calendar->get( UCAL_DAY_OF_YEAR, success ) << endl;
0110  *     cout << "DAY_OF_WEEK: " << calendar->get( UCAL_DAY_OF_WEEK, success ) << endl;
0111  *     cout << "DAY_OF_WEEK_IN_MONTH: " << calendar->get( UCAL_DAY_OF_WEEK_IN_MONTH, success ) << endl;
0112  *     cout << "AM_PM: " << calendar->get( UCAL_AM_PM, success ) << endl;
0113  *     cout << "HOUR: " << calendar->get( UCAL_HOUR, success ) << endl;
0114  *     cout << "HOUR_OF_DAY: " << calendar->get( UCAL_HOUR_OF_DAY, success ) << endl;
0115  *     cout << "MINUTE: " << calendar->get( UCAL_MINUTE, success ) << endl;
0116  *     cout << "SECOND: " << calendar->get( UCAL_SECOND, success ) << endl;
0117  *     cout << "MILLISECOND: " << calendar->get( UCAL_MILLISECOND, success ) << endl;
0118  *     cout << "ZONE_OFFSET: " << (calendar->get( UCAL_ZONE_OFFSET, success )/(60*60*1000)) << endl;
0119  *     cout << "DST_OFFSET: " << (calendar->get( UCAL_DST_OFFSET, success )/(60*60*1000)) << endl;
0120  *
0121  *     cout << "Current Time, with hour reset to 3" << endl;
0122  *     calendar->clear(UCAL_HOUR_OF_DAY); // so doesn't override
0123  *     calendar->set(UCAL_HOUR, 3);
0124  *     cout << "ERA: " << calendar->get( UCAL_ERA, success ) << endl;
0125  *     cout << "YEAR: " << calendar->get( UCAL_YEAR, success ) << endl;
0126  *     cout << "MONTH: " << calendar->get( UCAL_MONTH, success ) << endl;
0127  *     cout << "WEEK_OF_YEAR: " << calendar->get( UCAL_WEEK_OF_YEAR, success ) << endl;
0128  *     cout << "WEEK_OF_MONTH: " << calendar->get( UCAL_WEEK_OF_MONTH, success ) << endl;
0129  *     cout << "DATE: " << calendar->get( UCAL_DATE, success ) << endl;
0130  *     cout << "DAY_OF_MONTH: " << calendar->get( UCAL_DAY_OF_MONTH, success ) << endl;
0131  *     cout << "DAY_OF_YEAR: " << calendar->get( UCAL_DAY_OF_YEAR, success ) << endl;
0132  *     cout << "DAY_OF_WEEK: " << calendar->get( UCAL_DAY_OF_WEEK, success ) << endl;
0133  *     cout << "DAY_OF_WEEK_IN_MONTH: " << calendar->get( UCAL_DAY_OF_WEEK_IN_MONTH, success ) << endl;
0134  *     cout << "AM_PM: " << calendar->get( UCAL_AM_PM, success ) << endl;
0135  *     cout << "HOUR: " << calendar->get( UCAL_HOUR, success ) << endl;
0136  *     cout << "HOUR_OF_DAY: " << calendar->get( UCAL_HOUR_OF_DAY, success ) << endl;
0137  *     cout << "MINUTE: " << calendar->get( UCAL_MINUTE, success ) << endl;
0138  *     cout << "SECOND: " << calendar->get( UCAL_SECOND, success ) << endl;
0139  *     cout << "MILLISECOND: " << calendar->get( UCAL_MILLISECOND, success ) << endl;
0140  *     cout << "ZONE_OFFSET: " << (calendar->get( UCAL_ZONE_OFFSET, success )/(60*60*1000)) << endl; // in hours
0141  *     cout << "DST_OFFSET: " << (calendar->get( UCAL_DST_OFFSET, success )/(60*60*1000)) << endl; // in hours
0142  *
0143  *     if (U_FAILURE(success)) {
0144  *         cout << "An error occurred. success=" << u_errorName(success) << endl;
0145  *     }
0146  *
0147  *     delete ids;
0148  *     delete calendar; // also deletes pdt
0149  * \endcode
0150  * </pre>
0151  * @stable ICU 2.0
0152  */
0153 class U_I18N_API GregorianCalendar: public Calendar {
0154 public:
0155 
0156     /**
0157      * Useful constants for GregorianCalendar and TimeZone.
0158      * @stable ICU 2.0
0159      */
0160     enum EEras {
0161         BC,
0162         AD
0163     };
0164 
0165     /**
0166      * Constructs a default GregorianCalendar using the current time in the default time
0167      * zone with the default locale.
0168      *
0169      * @param success  Indicates the status of GregorianCalendar object construction.
0170      *                 Returns U_ZERO_ERROR if constructed successfully.
0171      * @stable ICU 2.0
0172      */
0173     GregorianCalendar(UErrorCode& success);
0174 
0175     /**
0176      * Constructs a GregorianCalendar based on the current time in the given time zone
0177      * with the default locale. Clients are no longer responsible for deleting the given
0178      * time zone object after it's adopted.
0179      *
0180      * @param zoneToAdopt     The given timezone.
0181      * @param success  Indicates the status of GregorianCalendar object construction.
0182      *                 Returns U_ZERO_ERROR if constructed successfully.
0183      * @stable ICU 2.0
0184      */
0185     GregorianCalendar(TimeZone* zoneToAdopt, UErrorCode& success);
0186 
0187     /**
0188      * Constructs a GregorianCalendar based on the current time in the given time zone
0189      * with the default locale.
0190      *
0191      * @param zone     The given timezone.
0192      * @param success  Indicates the status of GregorianCalendar object construction.
0193      *                 Returns U_ZERO_ERROR if constructed successfully.
0194      * @stable ICU 2.0
0195      */
0196     GregorianCalendar(const TimeZone& zone, UErrorCode& success);
0197 
0198     /**
0199      * Constructs a GregorianCalendar based on the current time in the default time zone
0200      * with the given locale.
0201      *
0202      * @param aLocale  The given locale.
0203      * @param success  Indicates the status of GregorianCalendar object construction.
0204      *                 Returns U_ZERO_ERROR if constructed successfully.
0205      * @stable ICU 2.0
0206      */
0207     GregorianCalendar(const Locale& aLocale, UErrorCode& success);
0208 
0209     /**
0210      * Constructs a GregorianCalendar based on the current time in the given time zone
0211      * with the given locale. Clients are no longer responsible for deleting the given
0212      * time zone object after it's adopted.
0213      *
0214      * @param zoneToAdopt     The given timezone.
0215      * @param aLocale  The given locale.
0216      * @param success  Indicates the status of GregorianCalendar object construction.
0217      *                 Returns U_ZERO_ERROR if constructed successfully.
0218      * @stable ICU 2.0
0219      */
0220     GregorianCalendar(TimeZone* zoneToAdopt, const Locale& aLocale, UErrorCode& success);
0221 
0222     /**
0223      * Constructs a GregorianCalendar based on the current time in the given time zone
0224      * with the given locale.
0225      *
0226      * @param zone     The given timezone.
0227      * @param aLocale  The given locale.
0228      * @param success  Indicates the status of GregorianCalendar object construction.
0229      *                 Returns U_ZERO_ERROR if constructed successfully.
0230      * @stable ICU 2.0
0231      */
0232     GregorianCalendar(const TimeZone& zone, const Locale& aLocale, UErrorCode& success);
0233 
0234     /**
0235      * Constructs a GregorianCalendar with the given AD date set in the default time
0236      * zone with the default locale.
0237      *
0238      * @param year     The value used to set the YEAR time field in the calendar.
0239      * @param month    The value used to set the MONTH time field in the calendar. Month
0240      *                 value is 0-based. e.g., 0 for January.
0241      * @param date     The value used to set the DATE time field in the calendar.
0242      * @param success  Indicates the status of GregorianCalendar object construction.
0243      *                 Returns U_ZERO_ERROR if constructed successfully.
0244      * @stable ICU 2.0
0245      */
0246     GregorianCalendar(int32_t year, int32_t month, int32_t date, UErrorCode& success);
0247 
0248     /**
0249      * Constructs a GregorianCalendar with the given AD date and time set for the
0250      * default time zone with the default locale.
0251      *
0252      * @param year     The value used to set the YEAR time field in the calendar.
0253      * @param month    The value used to set the MONTH time field in the calendar. Month
0254      *                 value is 0-based. e.g., 0 for January.
0255      * @param date     The value used to set the DATE time field in the calendar.
0256      * @param hour     The value used to set the HOUR_OF_DAY time field in the calendar.
0257      * @param minute   The value used to set the MINUTE time field in the calendar.
0258      * @param success  Indicates the status of GregorianCalendar object construction.
0259      *                 Returns U_ZERO_ERROR if constructed successfully.
0260      * @stable ICU 2.0
0261      */
0262     GregorianCalendar(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, UErrorCode& success);
0263 
0264     /**
0265      * Constructs a GregorianCalendar with the given AD date and time set for the
0266      * default time zone with the default locale.
0267      *
0268      * @param year     The value used to set the YEAR time field in the calendar.
0269      * @param month    The value used to set the MONTH time field in the calendar. Month
0270      *                 value is 0-based. e.g., 0 for January.
0271      * @param date     The value used to set the DATE time field in the calendar.
0272      * @param hour     The value used to set the HOUR_OF_DAY time field in the calendar.
0273      * @param minute   The value used to set the MINUTE time field in the calendar.
0274      * @param second   The value used to set the SECOND time field in the calendar.
0275      * @param success  Indicates the status of GregorianCalendar object construction.
0276      *                 Returns U_ZERO_ERROR if constructed successfully.
0277      * @stable ICU 2.0
0278      */
0279     GregorianCalendar(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, int32_t second, UErrorCode& success);
0280 
0281     /**
0282      * Destructor
0283      * @stable ICU 2.0
0284      */
0285     virtual ~GregorianCalendar();
0286 
0287     /**
0288      * Copy constructor
0289      * @param source    the object to be copied.
0290      * @stable ICU 2.0
0291      */
0292     GregorianCalendar(const GregorianCalendar& source);
0293 
0294     /**
0295      * Default assignment operator
0296      * @param right    the object to be copied.
0297      * @stable ICU 2.0
0298      */
0299     GregorianCalendar& operator=(const GregorianCalendar& right);
0300 
0301     /**
0302      * Create and return a polymorphic copy of this calendar.
0303      * @return    return a polymorphic copy of this calendar.
0304      * @stable ICU 2.0
0305      */
0306     virtual GregorianCalendar* clone() const override;
0307 
0308     /**
0309      * Sets the GregorianCalendar change date. This is the point when the switch from
0310      * Julian dates to Gregorian dates occurred. Default is 00:00:00 local time, October
0311      * 15, 1582. Previous to this time and date will be Julian dates.
0312      *
0313      * @param date     The given Gregorian cutover date.
0314      * @param success  Output param set to success/failure code on exit.
0315      * @stable ICU 2.0
0316      */
0317     void setGregorianChange(UDate date, UErrorCode& success);
0318 
0319     /**
0320      * Gets the Gregorian Calendar change date. This is the point when the switch from
0321      * Julian dates to Gregorian dates occurred. Default is 00:00:00 local time, October
0322      * 15, 1582. Previous to this time and date will be Julian dates.
0323      *
0324      * @return   The Gregorian cutover time for this calendar.
0325      * @stable ICU 2.0
0326      */
0327     UDate getGregorianChange() const;
0328 
0329     /**
0330      * Return true if the given year is a leap year. Determination of whether a year is
0331      * a leap year is actually very complicated. We do something crude and mostly
0332      * correct here, but for a real determination you need a lot of contextual
0333      * information. For example, in Sweden, the change from Julian to Gregorian happened
0334      * in a complex way resulting in missed leap years and double leap years between
0335      * 1700 and 1753. Another example is that after the start of the Julian calendar in
0336      * 45 B.C., the leap years did not regularize until 8 A.D. This method ignores these
0337      * quirks, and pays attention only to the Julian onset date and the Gregorian
0338      * cutover (which can be changed).
0339      *
0340      * @param year  The given year.
0341      * @return      True if the given year is a leap year; false otherwise.
0342      * @stable ICU 2.0
0343      */
0344     UBool isLeapYear(int32_t year) const;
0345 
0346     /**
0347      * Returns true if the given Calendar object is equivalent to this
0348      * one.  Calendar override.
0349      *
0350      * @param other the Calendar to be compared with this Calendar   
0351      * @stable ICU 2.4
0352      */
0353     virtual UBool isEquivalentTo(const Calendar& other) const override;
0354 
0355 #ifndef U_FORCE_HIDE_DEPRECATED_API
0356     /**
0357      * (Overrides Calendar) Rolls up or down by the given amount in the specified field.
0358      * For more information, see the documentation for Calendar::roll().
0359      *
0360      * @param field   The time field.
0361      * @param amount  Indicates amount to roll.
0362      * @param status  Output param set to success/failure code on exit. If any value
0363      *                previously set in the time field is invalid, this will be set to
0364      *                an error status.
0365      * @deprecated ICU 2.6. Use roll(UCalendarDateFields field, int32_t amount, UErrorCode& status) instead.
0366      */
0367     virtual void roll(EDateFields field, int32_t amount, UErrorCode& status) override;
0368 #endif  // U_FORCE_HIDE_DEPRECATED_API
0369 
0370     /**
0371      * (Overrides Calendar) Rolls up or down by the given amount in the specified field.
0372      * For more information, see the documentation for Calendar::roll().
0373      *
0374      * @param field   The time field.
0375      * @param amount  Indicates amount to roll.
0376      * @param status  Output param set to success/failure code on exit. If any value
0377      *                previously set in the time field is invalid, this will be set to
0378      *                an error status.
0379      * @stable ICU 2.6.
0380      */
0381     virtual void roll(UCalendarDateFields field, int32_t amount, UErrorCode& status) override;
0382 
0383 #ifndef U_HIDE_DEPRECATED_API
0384     /**
0385      * Return the minimum value that this field could have, given the current date.
0386      * For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum().
0387      * @param field    the time field.
0388      * @return         the minimum value that this field could have, given the current date.
0389      * @deprecated ICU 2.6. Use getActualMinimum(UCalendarDateFields field) instead.
0390      */
0391     int32_t getActualMinimum(EDateFields field) const;
0392 
0393     /**
0394      * Return the minimum value that this field could have, given the current date.
0395      * For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum().
0396      * @param field    the time field.
0397      * @param status
0398      * @return         the minimum value that this field could have, given the current date.
0399      * @deprecated ICU 2.6. Use getActualMinimum(UCalendarDateFields field) instead. (Added to ICU 3.0 for signature consistency)
0400      */
0401     int32_t getActualMinimum(EDateFields field, UErrorCode& status) const;
0402 #endif  /* U_HIDE_DEPRECATED_API */
0403 
0404     /**
0405      * Return the minimum value that this field could have, given the current date.
0406      * For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum().
0407      * @param field    the time field.
0408      * @param status   error result.
0409      * @return         the minimum value that this field could have, given the current date.
0410      * @stable ICU 3.0
0411      */
0412     int32_t getActualMinimum(UCalendarDateFields field, UErrorCode &status) const override;
0413 
0414     /**
0415      * Return the maximum value that this field could have, given the current date.
0416      * For example, with the date "Feb 3, 1997" and the DAY_OF_MONTH field, the actual
0417      * maximum would be 28; for "Feb 3, 1996" it s 29.  Similarly for a Hebrew calendar,
0418      * for some years the actual maximum for MONTH is 12, and for others 13.
0419      * @param field    the time field.
0420      * @param status   returns any errors that may result from this function call.
0421      * @return         the maximum value that this field could have, given the current date.
0422      * @stable ICU 2.6
0423      */
0424     virtual int32_t getActualMaximum(UCalendarDateFields field, UErrorCode& status) const override;
0425 
0426 public:
0427 
0428     /**
0429      * Override Calendar Returns a unique class ID POLYMORPHICALLY. Pure virtual
0430      * override. This method is to implement a simple version of RTTI, since not all C++
0431      * compilers support genuine RTTI. Polymorphic operator==() and clone() methods call
0432      * this method.
0433      *
0434      * @return   The class ID for this object. All objects of a given class have the
0435      *           same class ID. Objects of other classes have different class IDs.
0436      * @stable ICU 2.0
0437      */
0438     virtual UClassID getDynamicClassID() const override;
0439 
0440     /**
0441      * Return the class ID for this class. This is useful only for comparing to a return
0442      * value from getDynamicClassID(). For example:
0443      *
0444      *      Base* polymorphic_pointer = createPolymorphicObject();
0445      *      if (polymorphic_pointer->getDynamicClassID() ==
0446      *          Derived::getStaticClassID()) ...
0447      *
0448      * @return   The class ID for all objects of this class.
0449      * @stable ICU 2.0
0450      */
0451     static UClassID U_EXPORT2 getStaticClassID();
0452 
0453     /**
0454      * Returns the calendar type name string for this Calendar object.
0455      * The returned string is the legacy ICU calendar attribute value,
0456      * for example, "gregorian" or "japanese".
0457      *
0458      * For more details see the Calendar::getType() documentation.
0459      *
0460      * @return legacy calendar type name string
0461      * @stable ICU 49
0462      */
0463     virtual const char * getType() const override;
0464 
0465  private:
0466     GregorianCalendar() = delete; // default constructor not implemented
0467 
0468  protected:
0469     /**
0470      * Return the ERA.  We need a special method for this because the
0471      * default ERA is AD, but a zero (unset) ERA is BC.
0472      * @return    the ERA.
0473      * @internal
0474      */
0475     virtual int32_t internalGetEra() const;
0476 
0477     /**
0478      * Return the Julian day number of day before the first day of the
0479      * given month in the given extended year.  Subclasses should override
0480      * this method to implement their calendar system.
0481      * @param eyear the extended year
0482      * @param month the zero-based month, or 0 if useMonth is false
0483      * @param useMonth if false, compute the day before the first day of
0484      * the given year, otherwise, compute the day before the first day of
0485      * the given month
0486      * @param status Fill-in parameter which receives the status of this operation.
0487      * @return the Julian day number of the day before the first
0488      * day of the given month and year
0489      * @internal
0490      */
0491     virtual int64_t handleComputeMonthStart(int32_t eyear, int32_t month,
0492                                             UBool useMonth, UErrorCode& status) const override;
0493 
0494     /**
0495      * Subclasses may override this.  This method calls
0496      * handleGetMonthLength() to obtain the calendar-specific month
0497      * length.
0498      * @param bestField which field to use to calculate the date 
0499      * @param status Fill-in parameter which receives the status of this operation.
0500      * @return julian day specified by calendar fields.
0501      * @internal
0502      */
0503     virtual int32_t handleComputeJulianDay(UCalendarDateFields bestField, UErrorCode& status) override;
0504 
0505     /**
0506      * Return the number of days in the given month of the given extended
0507      * year of this calendar system.  Subclasses should override this
0508      * method if they can provide a more correct or more efficient
0509      * implementation than the default implementation in Calendar.
0510      * @internal
0511      */
0512     virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month, UErrorCode& status) const override;
0513 
0514     /**
0515      * Return the number of days in the given extended year of this
0516      * calendar system.  Subclasses should override this method if they can
0517      * provide a more correct or more efficient implementation than the
0518      * default implementation in Calendar.
0519      * @stable ICU 2.0
0520      */
0521     virtual int32_t handleGetYearLength(int32_t eyear) const override;
0522 
0523     /**
0524      * return the length of the given month.
0525      * @param month    the given month.
0526      * @param status Fill-in parameter which receives the status of this operation.
0527      * @return    the length of the given month.
0528      * @internal
0529      */
0530     virtual int32_t monthLength(int32_t month, UErrorCode& status) const;
0531 
0532     /**
0533      * return the length of the month according to the given year.
0534      * @param month    the given month.
0535      * @param year     the given year.
0536      * @return         the length of the month
0537      * @internal
0538      */
0539     virtual int32_t monthLength(int32_t month, int32_t year) const;
0540 
0541 #ifndef U_HIDE_INTERNAL_API
0542     /**
0543      * return the length of the year field.
0544      * @return    the length of the year field
0545      * @internal
0546      */
0547   int32_t yearLength() const;
0548 
0549 #endif  /* U_HIDE_INTERNAL_API */
0550 
0551     /**
0552      * Return the day number with respect to the epoch.  January 1, 1970 (Gregorian)
0553      * is day zero.
0554      * @param status Fill-in parameter which receives the status of this operation.
0555      * @return       the day number with respect to the epoch.  
0556      * @internal
0557      */
0558     virtual UDate getEpochDay(UErrorCode& status);
0559 
0560     /**
0561      * Subclass API for defining limits of different types.
0562      * Subclasses must implement this method to return limits for the
0563      * following fields:
0564      *
0565      * <pre>UCAL_ERA
0566      * UCAL_YEAR
0567      * UCAL_MONTH
0568      * UCAL_WEEK_OF_YEAR
0569      * UCAL_WEEK_OF_MONTH
0570      * UCAL_DATE (DAY_OF_MONTH on Java)
0571      * UCAL_DAY_OF_YEAR
0572      * UCAL_DAY_OF_WEEK_IN_MONTH
0573      * UCAL_YEAR_WOY
0574      * UCAL_EXTENDED_YEAR</pre>
0575      *
0576      * @param field one of the above field numbers
0577      * @param limitType one of <code>MINIMUM</code>, <code>GREATEST_MINIMUM</code>,
0578      * <code>LEAST_MAXIMUM</code>, or <code>MAXIMUM</code>
0579      * @internal
0580      */
0581     virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const override;
0582 
0583     /**
0584      * Return the extended year defined by the current fields.  This will
0585      * use the UCAL_EXTENDED_YEAR field or the UCAL_YEAR and supra-year fields (such
0586      * as UCAL_ERA) specific to the calendar system, depending on which set of
0587      * fields is newer.
0588      * @param status
0589      * @return the extended year
0590      * @internal
0591      */
0592     virtual int32_t handleGetExtendedYear(UErrorCode& status) override;
0593 
0594     /** 
0595      * Subclasses may override this to convert from week fields 
0596      * (YEAR_WOY and WEEK_OF_YEAR) to an extended year in the case
0597      * where YEAR, EXTENDED_YEAR are not set.
0598      * The Gregorian implementation assumes a yearWoy in gregorian format, according to the current era.
0599      * @return the extended year, UCAL_EXTENDED_YEAR
0600      * @internal
0601      */
0602     virtual int32_t handleGetExtendedYearFromWeekFields(int32_t yearWoy, int32_t woy, UErrorCode& status) override;
0603 
0604 
0605     /**
0606      * Subclasses may override this method to compute several fields
0607      * specific to each calendar system.  These are:
0608      *
0609      * <ul><li>ERA
0610      * <li>YEAR
0611      * <li>MONTH
0612      * <li>DAY_OF_MONTH
0613      * <li>DAY_OF_YEAR
0614      * <li>EXTENDED_YEAR</ul>
0615      *
0616      * <p>The GregorianCalendar implementation implements
0617      * a calendar with the specified Julian/Gregorian cutover date.
0618      * @internal
0619      */
0620     virtual void handleComputeFields(int32_t julianDay, UErrorCode &status) override;
0621 
0622 #ifndef U_HIDE_INTERNAL_API
0623     /**
0624      * The year in this calendar is counting from 1 backward if the era is 0.
0625      * @return The year in era 0 of this calendar is counting backward from 1.
0626      * @internal
0627      */
0628     virtual bool isEra0CountingBackward() const override { return true; }
0629 #endif  // U_HIDE_INTERNAL_API
0630 
0631  private:
0632     /**
0633      * Compute the julian day number of the given year.
0634      * @param isGregorian    if true, using Gregorian calendar, otherwise using Julian calendar
0635      * @param year           the given year.
0636      * @param isLeap         true if the year is a leap year.       
0637      * @return 
0638      */
0639     static double computeJulianDayOfYear(UBool isGregorian, int32_t year,
0640                                          UBool& isLeap);
0641     
0642     /**
0643      * Validates the values of the set time fields.  True if they're all valid.
0644      * @return    True if the set time fields are all valid.
0645      */
0646     UBool validateFields() const;
0647 
0648     /**
0649      * Validates the value of the given time field.  True if it's valid.
0650      */
0651     UBool boundsCheck(int32_t value, UCalendarDateFields field) const;
0652 
0653     /**
0654      * Return the pseudo-time-stamp for two fields, given their
0655      * individual pseudo-time-stamps.  If either of the fields
0656      * is unset, then the aggregate is unset.  Otherwise, the
0657      * aggregate is the later of the two stamps.
0658      * @param stamp_a    One given field.
0659      * @param stamp_b    Another given field.
0660      * @return the pseudo-time-stamp for two fields
0661      */
0662     int32_t aggregateStamp(int32_t stamp_a, int32_t stamp_b);
0663 
0664     /**
0665      * The point at which the Gregorian calendar rules are used, measured in
0666      * milliseconds from the standard epoch.  Default is October 15, 1582
0667      * (Gregorian) 00:00:00 UTC, that is, October 4, 1582 (Julian) is followed
0668      * by October 15, 1582 (Gregorian).  This corresponds to Julian day number
0669      * 2299161. This is measured from the standard epoch, not in Julian Days.
0670      */
0671     UDate                fGregorianCutover;
0672 
0673     /**
0674      * Julian day number of the Gregorian cutover
0675      */
0676     int32_t             fCutoverJulianDay;
0677 
0678     /**
0679      * Midnight, local time (using this Calendar's TimeZone) at or before the
0680      * gregorianCutover. This is a pure date value with no time of day or
0681      * timezone component.
0682      */
0683     UDate                 fNormalizedGregorianCutover;// = gregorianCutover;
0684 
0685     /**
0686      * The year of the gregorianCutover, with 0 representing
0687      * 1 BC, -1 representing 2 BC, etc.
0688      */
0689     int32_t fGregorianCutoverYear;// = 1582;
0690 
0691     /**
0692      * Converts time as milliseconds to Julian date. The Julian date used here is not a
0693      * true Julian date, since it is measured from midnight, not noon.
0694      *
0695      * @param millis  The given milliseconds.
0696      * @return        The Julian date number.
0697      */
0698     static double millisToJulianDay(UDate millis);
0699 
0700     /**
0701      * Converts Julian date to time as milliseconds. The Julian date used here is not a
0702      * true Julian date, since it is measured from midnight, not noon.
0703      *
0704      * @param julian  The given Julian date number.
0705      * @return        Time as milliseconds.
0706      */
0707     static UDate julianDayToMillis(double julian);
0708 
0709     /**
0710      * Used by handleComputeJulianDay() and handleComputeMonthStart().
0711      * Temporary field indicating whether the calendar is currently Gregorian as opposed to Julian.
0712      */
0713     UBool fIsGregorian;
0714 
0715     /**
0716      * Used by handleComputeJulianDay() and handleComputeMonthStart().
0717      * Temporary field indicating that the sense of the gregorian cutover should be inverted
0718      * to handle certain calculations on and around the cutover date.
0719      */
0720     UBool fInvertGregorian;
0721 
0722 
0723  public: // internal implementation
0724 
0725     DECLARE_OVERRIDE_SYSTEM_DEFAULT_CENTURY
0726 
0727 };
0728 
0729 U_NAMESPACE_END
0730 
0731 #endif /* #if !UCONFIG_NO_FORMATTING */
0732 
0733 #endif /* U_SHOW_CPLUSPLUS_API */
0734 
0735 #endif // _GREGOCAL
0736 //eof
0737