Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:13:05

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(void) 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(void) 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(void);
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      * @return the Julian day number of the day before the first
0487      * day of the given month and year
0488      * @internal
0489      */
0490     virtual int32_t handleComputeMonthStart(int32_t eyear, int32_t month,
0491                                                    UBool useMonth) const override;
0492 
0493     /**
0494      * Subclasses may override this.  This method calls
0495      * handleGetMonthLength() to obtain the calendar-specific month
0496      * length.
0497      * @param bestField which field to use to calculate the date 
0498      * @return julian day specified by calendar fields.
0499      * @internal
0500      */
0501     virtual int32_t handleComputeJulianDay(UCalendarDateFields bestField) override;
0502 
0503     /**
0504      * Return the number of days in the given month of the given extended
0505      * year of this calendar system.  Subclasses should override this
0506      * method if they can provide a more correct or more efficient
0507      * implementation than the default implementation in Calendar.
0508      * @internal
0509      */
0510     virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month) const override;
0511 
0512     /**
0513      * Return the number of days in the given extended year of this
0514      * calendar system.  Subclasses should override this method if they can
0515      * provide a more correct or more efficient implementation than the
0516      * default implementation in Calendar.
0517      * @stable ICU 2.0
0518      */
0519     virtual int32_t handleGetYearLength(int32_t eyear) const override;
0520 
0521     /**
0522      * return the length of the given month.
0523      * @param month    the given month.
0524      * @return    the length of the given month.
0525      * @internal
0526      */
0527     virtual int32_t monthLength(int32_t month) const;
0528 
0529     /**
0530      * return the length of the month according to the given year.
0531      * @param month    the given month.
0532      * @param year     the given year.
0533      * @return         the length of the month
0534      * @internal
0535      */
0536     virtual int32_t monthLength(int32_t month, int32_t year) const;
0537 
0538 #ifndef U_HIDE_INTERNAL_API
0539     /**
0540      * return the length of the year field.
0541      * @return    the length of the year field
0542      * @internal
0543      */
0544     int32_t yearLength(void) const;
0545 
0546 #endif  /* U_HIDE_INTERNAL_API */
0547 
0548     /**
0549      * Return the day number with respect to the epoch.  January 1, 1970 (Gregorian)
0550      * is day zero.
0551      * @param status Fill-in parameter which receives the status of this operation.
0552      * @return       the day number with respect to the epoch.  
0553      * @internal
0554      */
0555     virtual UDate getEpochDay(UErrorCode& status);
0556 
0557     /**
0558      * Subclass API for defining limits of different types.
0559      * Subclasses must implement this method to return limits for the
0560      * following fields:
0561      *
0562      * <pre>UCAL_ERA
0563      * UCAL_YEAR
0564      * UCAL_MONTH
0565      * UCAL_WEEK_OF_YEAR
0566      * UCAL_WEEK_OF_MONTH
0567      * UCAL_DATE (DAY_OF_MONTH on Java)
0568      * UCAL_DAY_OF_YEAR
0569      * UCAL_DAY_OF_WEEK_IN_MONTH
0570      * UCAL_YEAR_WOY
0571      * UCAL_EXTENDED_YEAR</pre>
0572      *
0573      * @param field one of the above field numbers
0574      * @param limitType one of <code>MINIMUM</code>, <code>GREATEST_MINIMUM</code>,
0575      * <code>LEAST_MAXIMUM</code>, or <code>MAXIMUM</code>
0576      * @internal
0577      */
0578     virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const override;
0579 
0580     /**
0581      * Return the extended year defined by the current fields.  This will
0582      * use the UCAL_EXTENDED_YEAR field or the UCAL_YEAR and supra-year fields (such
0583      * as UCAL_ERA) specific to the calendar system, depending on which set of
0584      * fields is newer.
0585      * @return the extended year
0586      * @internal
0587      */
0588     virtual int32_t handleGetExtendedYear() override;
0589 
0590     /** 
0591      * Subclasses may override this to convert from week fields 
0592      * (YEAR_WOY and WEEK_OF_YEAR) to an extended year in the case
0593      * where YEAR, EXTENDED_YEAR are not set.
0594      * The Gregorian implementation assumes a yearWoy in gregorian format, according to the current era.
0595      * @return the extended year, UCAL_EXTENDED_YEAR
0596      * @internal
0597      */
0598     virtual int32_t handleGetExtendedYearFromWeekFields(int32_t yearWoy, int32_t woy) override;
0599 
0600 
0601     /**
0602      * Subclasses may override this method to compute several fields
0603      * specific to each calendar system.  These are:
0604      *
0605      * <ul><li>ERA
0606      * <li>YEAR
0607      * <li>MONTH
0608      * <li>DAY_OF_MONTH
0609      * <li>DAY_OF_YEAR
0610      * <li>EXTENDED_YEAR</ul>
0611      *
0612      * <p>The GregorianCalendar implementation implements
0613      * a calendar with the specified Julian/Gregorian cutover date.
0614      * @internal
0615      */
0616     virtual void handleComputeFields(int32_t julianDay, UErrorCode &status) override;
0617 
0618  private:
0619     /**
0620      * Compute the julian day number of the given year.
0621      * @param isGregorian    if true, using Gregorian calendar, otherwise using Julian calendar
0622      * @param year           the given year.
0623      * @param isLeap         true if the year is a leap year.       
0624      * @return 
0625      */
0626     static double computeJulianDayOfYear(UBool isGregorian, int32_t year,
0627                                          UBool& isLeap);
0628     
0629     /**
0630      * Validates the values of the set time fields.  True if they're all valid.
0631      * @return    True if the set time fields are all valid.
0632      */
0633     UBool validateFields(void) const;
0634 
0635     /**
0636      * Validates the value of the given time field.  True if it's valid.
0637      */
0638     UBool boundsCheck(int32_t value, UCalendarDateFields field) const;
0639 
0640     /**
0641      * Return the pseudo-time-stamp for two fields, given their
0642      * individual pseudo-time-stamps.  If either of the fields
0643      * is unset, then the aggregate is unset.  Otherwise, the
0644      * aggregate is the later of the two stamps.
0645      * @param stamp_a    One given field.
0646      * @param stamp_b    Another given field.
0647      * @return the pseudo-time-stamp for two fields
0648      */
0649     int32_t aggregateStamp(int32_t stamp_a, int32_t stamp_b);
0650 
0651     /**
0652      * The point at which the Gregorian calendar rules are used, measured in
0653      * milliseconds from the standard epoch.  Default is October 15, 1582
0654      * (Gregorian) 00:00:00 UTC, that is, October 4, 1582 (Julian) is followed
0655      * by October 15, 1582 (Gregorian).  This corresponds to Julian day number
0656      * 2299161. This is measured from the standard epoch, not in Julian Days.
0657      */
0658     UDate                fGregorianCutover;
0659 
0660     /**
0661      * Julian day number of the Gregorian cutover
0662      */
0663     int32_t             fCutoverJulianDay;
0664 
0665     /**
0666      * Midnight, local time (using this Calendar's TimeZone) at or before the
0667      * gregorianCutover. This is a pure date value with no time of day or
0668      * timezone component.
0669      */
0670     UDate                 fNormalizedGregorianCutover;// = gregorianCutover;
0671 
0672     /**
0673      * The year of the gregorianCutover, with 0 representing
0674      * 1 BC, -1 representing 2 BC, etc.
0675      */
0676     int32_t fGregorianCutoverYear;// = 1582;
0677 
0678     /**
0679      * Converts time as milliseconds to Julian date. The Julian date used here is not a
0680      * true Julian date, since it is measured from midnight, not noon.
0681      *
0682      * @param millis  The given milliseconds.
0683      * @return        The Julian date number.
0684      */
0685     static double millisToJulianDay(UDate millis);
0686 
0687     /**
0688      * Converts Julian date to time as milliseconds. The Julian date used here is not a
0689      * true Julian date, since it is measured from midnight, not noon.
0690      *
0691      * @param julian  The given Julian date number.
0692      * @return        Time as milliseconds.
0693      */
0694     static UDate julianDayToMillis(double julian);
0695 
0696     /**
0697      * Used by handleComputeJulianDay() and handleComputeMonthStart().
0698      * Temporary field indicating whether the calendar is currently Gregorian as opposed to Julian.
0699      */
0700     UBool fIsGregorian;
0701 
0702     /**
0703      * Used by handleComputeJulianDay() and handleComputeMonthStart().
0704      * Temporary field indicating that the sense of the gregorian cutover should be inverted
0705      * to handle certain calculations on and around the cutover date.
0706      */
0707     UBool fInvertGregorian;
0708 
0709 
0710  public: // internal implementation
0711 
0712     /**
0713      * @return true if this calendar has the notion of a default century
0714      * @internal 
0715      */
0716     virtual UBool haveDefaultCentury() const override;
0717 
0718     /**
0719      * @return the start of the default century
0720      * @internal
0721      */
0722     virtual UDate defaultCenturyStart() const override;
0723 
0724     /**
0725      * @return the beginning year of the default century
0726      * @internal 
0727      */
0728     virtual int32_t defaultCenturyStartYear() const override;
0729 };
0730 
0731 U_NAMESPACE_END
0732 
0733 #endif /* #if !UCONFIG_NO_FORMATTING */
0734 
0735 #endif /* U_SHOW_CPLUSPLUS_API */
0736 
0737 #endif // _GREGOCAL
0738 //eof
0739