• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 * Copyright (C) 1997-2013, International Business Machines Corporation and others.
5 * All Rights Reserved.
6 ********************************************************************************
7 *
8 * File GREGOCAL.H
9 *
10 * Modification History:
11 *
12 *   Date        Name        Description
13 *   04/22/97    aliu        Overhauled header.
14 *    07/28/98    stephen        Sync with JDK 1.2
15 *    09/04/98    stephen        Re-sync with JDK 8/31 putback
16 *    09/14/98    stephen        Changed type of kOneDay, kOneWeek to double.
17 *                            Fixed bug in roll()
18 *   10/15/99    aliu        Fixed j31, incorrect WEEK_OF_YEAR computation.
19 *                           Added documentation of WEEK_OF_YEAR computation.
20 *   10/15/99    aliu        Fixed j32, cannot set date to Feb 29 2000 AD.
21 *                           {JDK bug 4210209 4209272}
22 *   11/07/2003  srl         Update, clean up documentation.
23 ********************************************************************************
24 */
25 
26 #ifndef GREGOCAL_H
27 #define GREGOCAL_H
28 
29 #include "unicode/utypes.h"
30 
31 #if U_SHOW_CPLUSPLUS_API
32 
33 #if !UCONFIG_NO_FORMATTING
34 
35 #include "unicode/calendar.h"
36 
37 /**
38  * \file
39  * \brief C++ API: Concrete class which provides the standard calendar.
40  */
41 
42 U_NAMESPACE_BEGIN
43 
44 /**
45  * Concrete class which provides the standard calendar used by most of the world.
46  * <P>
47  * The standard (Gregorian) calendar has 2 eras, BC and AD.
48  * <P>
49  * This implementation handles a single discontinuity, which corresponds by default to
50  * the date the Gregorian calendar was originally instituted (October 15, 1582). Not all
51  * countries adopted the Gregorian calendar then, so this cutover date may be changed by
52  * the caller.
53  * <P>
54  * Prior to the institution of the Gregorian Calendar, New Year's Day was March 25. To
55  * avoid confusion, this Calendar always uses January 1. A manual adjustment may be made
56  * if desired for dates that are prior to the Gregorian changeover and which fall
57  * between January 1 and March 24.
58  *
59  * <p>Values calculated for the <code>WEEK_OF_YEAR</code> field range from 1 to
60  * 53.  Week 1 for a year is the first week that contains at least
61  * <code>getMinimalDaysInFirstWeek()</code> days from that year.  It thus
62  * depends on the values of <code>getMinimalDaysInFirstWeek()</code>,
63  * <code>getFirstDayOfWeek()</code>, and the day of the week of January 1.
64  * Weeks between week 1 of one year and week 1 of the following year are
65  * numbered sequentially from 2 to 52 or 53 (as needed).
66  *
67  * <p>For example, January 1, 1998 was a Thursday.  If
68  * <code>getFirstDayOfWeek()</code> is <code>MONDAY</code> and
69  * <code>getMinimalDaysInFirstWeek()</code> is 4 (these are the values
70  * reflecting ISO 8601 and many national standards), then week 1 of 1998 starts
71  * on December 29, 1997, and ends on January 4, 1998.  If, however,
72  * <code>getFirstDayOfWeek()</code> is <code>SUNDAY</code>, then week 1 of 1998
73  * starts on January 4, 1998, and ends on January 10, 1998; the first three days
74  * of 1998 then are part of week 53 of 1997.
75  *
76  * <p>Example for using GregorianCalendar:
77  * <pre>
78  * \code
79  *     // get the supported ids for GMT-08:00 (Pacific Standard Time)
80  *     UErrorCode success = U_ZERO_ERROR;
81  *     const StringEnumeration *ids = TimeZone::createEnumeration(-8 * 60 * 60 * 1000, success);
82  *     // if no ids were returned, something is wrong. get out.
83  *     if (U_FAILURE(success)) {
84  *         return;
85  *     }
86  *
87  *     // begin output
88  *     cout << "Current Time" << endl;
89  *
90  *     // create a Pacific Standard Time time zone
91  *     SimpleTimeZone* pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids->unext(NULL, success)));
92  *
93  *     // set up rules for daylight savings time
94  *     pdt->setStartRule(UCAL_MARCH, 1, UCAL_SUNDAY, 2 * 60 * 60 * 1000);
95  *     pdt->setEndRule(UCAL_NOVEMBER, 2, UCAL_SUNDAY, 2 * 60 * 60 * 1000);
96  *
97  *     // create a GregorianCalendar with the Pacific Daylight time zone
98  *     // and the current date and time
99  *     Calendar* calendar = new GregorianCalendar( pdt, success );
100  *
101  *     // print out a bunch of interesting things
102  *     cout << "ERA: " << calendar->get( UCAL_ERA, success ) << endl;
103  *     cout << "YEAR: " << calendar->get( UCAL_YEAR, success ) << endl;
104  *     cout << "MONTH: " << calendar->get( UCAL_MONTH, success ) << endl;
105  *     cout << "WEEK_OF_YEAR: " << calendar->get( UCAL_WEEK_OF_YEAR, success ) << endl;
106  *     cout << "WEEK_OF_MONTH: " << calendar->get( UCAL_WEEK_OF_MONTH, success ) << endl;
107  *     cout << "DATE: " << calendar->get( UCAL_DATE, success ) << endl;
108  *     cout << "DAY_OF_MONTH: " << calendar->get( UCAL_DAY_OF_MONTH, success ) << endl;
109  *     cout << "DAY_OF_YEAR: " << calendar->get( UCAL_DAY_OF_YEAR, success ) << endl;
110  *     cout << "DAY_OF_WEEK: " << calendar->get( UCAL_DAY_OF_WEEK, success ) << endl;
111  *     cout << "DAY_OF_WEEK_IN_MONTH: " << calendar->get( UCAL_DAY_OF_WEEK_IN_MONTH, success ) << endl;
112  *     cout << "AM_PM: " << calendar->get( UCAL_AM_PM, success ) << endl;
113  *     cout << "HOUR: " << calendar->get( UCAL_HOUR, success ) << endl;
114  *     cout << "HOUR_OF_DAY: " << calendar->get( UCAL_HOUR_OF_DAY, success ) << endl;
115  *     cout << "MINUTE: " << calendar->get( UCAL_MINUTE, success ) << endl;
116  *     cout << "SECOND: " << calendar->get( UCAL_SECOND, success ) << endl;
117  *     cout << "MILLISECOND: " << calendar->get( UCAL_MILLISECOND, success ) << endl;
118  *     cout << "ZONE_OFFSET: " << (calendar->get( UCAL_ZONE_OFFSET, success )/(60*60*1000)) << endl;
119  *     cout << "DST_OFFSET: " << (calendar->get( UCAL_DST_OFFSET, success )/(60*60*1000)) << endl;
120  *
121  *     cout << "Current Time, with hour reset to 3" << endl;
122  *     calendar->clear(UCAL_HOUR_OF_DAY); // so doesn't override
123  *     calendar->set(UCAL_HOUR, 3);
124  *     cout << "ERA: " << calendar->get( UCAL_ERA, success ) << endl;
125  *     cout << "YEAR: " << calendar->get( UCAL_YEAR, success ) << endl;
126  *     cout << "MONTH: " << calendar->get( UCAL_MONTH, success ) << endl;
127  *     cout << "WEEK_OF_YEAR: " << calendar->get( UCAL_WEEK_OF_YEAR, success ) << endl;
128  *     cout << "WEEK_OF_MONTH: " << calendar->get( UCAL_WEEK_OF_MONTH, success ) << endl;
129  *     cout << "DATE: " << calendar->get( UCAL_DATE, success ) << endl;
130  *     cout << "DAY_OF_MONTH: " << calendar->get( UCAL_DAY_OF_MONTH, success ) << endl;
131  *     cout << "DAY_OF_YEAR: " << calendar->get( UCAL_DAY_OF_YEAR, success ) << endl;
132  *     cout << "DAY_OF_WEEK: " << calendar->get( UCAL_DAY_OF_WEEK, success ) << endl;
133  *     cout << "DAY_OF_WEEK_IN_MONTH: " << calendar->get( UCAL_DAY_OF_WEEK_IN_MONTH, success ) << endl;
134  *     cout << "AM_PM: " << calendar->get( UCAL_AM_PM, success ) << endl;
135  *     cout << "HOUR: " << calendar->get( UCAL_HOUR, success ) << endl;
136  *     cout << "HOUR_OF_DAY: " << calendar->get( UCAL_HOUR_OF_DAY, success ) << endl;
137  *     cout << "MINUTE: " << calendar->get( UCAL_MINUTE, success ) << endl;
138  *     cout << "SECOND: " << calendar->get( UCAL_SECOND, success ) << endl;
139  *     cout << "MILLISECOND: " << calendar->get( UCAL_MILLISECOND, success ) << endl;
140  *     cout << "ZONE_OFFSET: " << (calendar->get( UCAL_ZONE_OFFSET, success )/(60*60*1000)) << endl; // in hours
141  *     cout << "DST_OFFSET: " << (calendar->get( UCAL_DST_OFFSET, success )/(60*60*1000)) << endl; // in hours
142  *
143  *     if (U_FAILURE(success)) {
144  *         cout << "An error occurred. success=" << u_errorName(success) << endl;
145  *     }
146  *
147  *     delete ids;
148  *     delete calendar; // also deletes pdt
149  * \endcode
150  * </pre>
151  * @stable ICU 2.0
152  */
153 class U_I18N_API GregorianCalendar: public Calendar {
154 public:
155 
156     /**
157      * Useful constants for GregorianCalendar and TimeZone.
158      * @stable ICU 2.0
159      */
160     enum EEras {
161         BC,
162         AD
163     };
164 
165     /**
166      * Constructs a default GregorianCalendar using the current time in the default time
167      * zone with the default locale.
168      *
169      * @param success  Indicates the status of GregorianCalendar object construction.
170      *                 Returns U_ZERO_ERROR if constructed successfully.
171      * @stable ICU 2.0
172      */
173     GregorianCalendar(UErrorCode& success);
174 
175     /**
176      * Constructs a GregorianCalendar based on the current time in the given time zone
177      * with the default locale. Clients are no longer responsible for deleting the given
178      * time zone object after it's adopted.
179      *
180      * @param zoneToAdopt     The given timezone.
181      * @param success  Indicates the status of GregorianCalendar object construction.
182      *                 Returns U_ZERO_ERROR if constructed successfully.
183      * @stable ICU 2.0
184      */
185     GregorianCalendar(TimeZone* zoneToAdopt, UErrorCode& success);
186 
187     /**
188      * Constructs a GregorianCalendar based on the current time in the given time zone
189      * with the default locale.
190      *
191      * @param zone     The given timezone.
192      * @param success  Indicates the status of GregorianCalendar object construction.
193      *                 Returns U_ZERO_ERROR if constructed successfully.
194      * @stable ICU 2.0
195      */
196     GregorianCalendar(const TimeZone& zone, UErrorCode& success);
197 
198     /**
199      * Constructs a GregorianCalendar based on the current time in the default time zone
200      * with the given locale.
201      *
202      * @param aLocale  The given locale.
203      * @param success  Indicates the status of GregorianCalendar object construction.
204      *                 Returns U_ZERO_ERROR if constructed successfully.
205      * @stable ICU 2.0
206      */
207     GregorianCalendar(const Locale& aLocale, UErrorCode& success);
208 
209     /**
210      * Constructs a GregorianCalendar based on the current time in the given time zone
211      * with the given locale. Clients are no longer responsible for deleting the given
212      * time zone object after it's adopted.
213      *
214      * @param zoneToAdopt     The given timezone.
215      * @param aLocale  The given locale.
216      * @param success  Indicates the status of GregorianCalendar object construction.
217      *                 Returns U_ZERO_ERROR if constructed successfully.
218      * @stable ICU 2.0
219      */
220     GregorianCalendar(TimeZone* zoneToAdopt, const Locale& aLocale, UErrorCode& success);
221 
222     /**
223      * Constructs a GregorianCalendar based on the current time in the given time zone
224      * with the given locale.
225      *
226      * @param zone     The given timezone.
227      * @param aLocale  The given locale.
228      * @param success  Indicates the status of GregorianCalendar object construction.
229      *                 Returns U_ZERO_ERROR if constructed successfully.
230      * @stable ICU 2.0
231      */
232     GregorianCalendar(const TimeZone& zone, const Locale& aLocale, UErrorCode& success);
233 
234     /**
235      * Constructs a GregorianCalendar with the given AD date set in the default time
236      * zone with the default locale.
237      *
238      * @param year     The value used to set the YEAR time field in the calendar.
239      * @param month    The value used to set the MONTH time field in the calendar. Month
240      *                 value is 0-based. e.g., 0 for January.
241      * @param date     The value used to set the DATE time field in the calendar.
242      * @param success  Indicates the status of GregorianCalendar object construction.
243      *                 Returns U_ZERO_ERROR if constructed successfully.
244      * @stable ICU 2.0
245      */
246     GregorianCalendar(int32_t year, int32_t month, int32_t date, UErrorCode& success);
247 
248     /**
249      * Constructs a GregorianCalendar with the given AD date and time set for the
250      * default time zone with the default locale.
251      *
252      * @param year     The value used to set the YEAR time field in the calendar.
253      * @param month    The value used to set the MONTH time field in the calendar. Month
254      *                 value is 0-based. e.g., 0 for January.
255      * @param date     The value used to set the DATE time field in the calendar.
256      * @param hour     The value used to set the HOUR_OF_DAY time field in the calendar.
257      * @param minute   The value used to set the MINUTE time field in the calendar.
258      * @param success  Indicates the status of GregorianCalendar object construction.
259      *                 Returns U_ZERO_ERROR if constructed successfully.
260      * @stable ICU 2.0
261      */
262     GregorianCalendar(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, UErrorCode& success);
263 
264     /**
265      * Constructs a GregorianCalendar with the given AD date and time set for the
266      * default time zone with the default locale.
267      *
268      * @param year     The value used to set the YEAR time field in the calendar.
269      * @param month    The value used to set the MONTH time field in the calendar. Month
270      *                 value is 0-based. e.g., 0 for January.
271      * @param date     The value used to set the DATE time field in the calendar.
272      * @param hour     The value used to set the HOUR_OF_DAY time field in the calendar.
273      * @param minute   The value used to set the MINUTE time field in the calendar.
274      * @param second   The value used to set the SECOND time field in the calendar.
275      * @param success  Indicates the status of GregorianCalendar object construction.
276      *                 Returns U_ZERO_ERROR if constructed successfully.
277      * @stable ICU 2.0
278      */
279     GregorianCalendar(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, int32_t second, UErrorCode& success);
280 
281     /**
282      * Destructor
283      * @stable ICU 2.0
284      */
285     virtual ~GregorianCalendar();
286 
287     /**
288      * Copy constructor
289      * @param source    the object to be copied.
290      * @stable ICU 2.0
291      */
292     GregorianCalendar(const GregorianCalendar& source);
293 
294     /**
295      * Default assignment operator
296      * @param right    the object to be copied.
297      * @stable ICU 2.0
298      */
299     GregorianCalendar& operator=(const GregorianCalendar& right);
300 
301     /**
302      * Create and return a polymorphic copy of this calendar.
303      * @return    return a polymorphic copy of this calendar.
304      * @stable ICU 2.0
305      */
306     virtual GregorianCalendar* clone() const override;
307 
308     /**
309      * Sets the GregorianCalendar change date. This is the point when the switch from
310      * Julian dates to Gregorian dates occurred. Default is 00:00:00 local time, October
311      * 15, 1582. Previous to this time and date will be Julian dates.
312      *
313      * @param date     The given Gregorian cutover date.
314      * @param success  Output param set to success/failure code on exit.
315      * @stable ICU 2.0
316      */
317     void setGregorianChange(UDate date, UErrorCode& success);
318 
319     /**
320      * Gets the Gregorian Calendar change date. This is the point when the switch from
321      * Julian dates to Gregorian dates occurred. Default is 00:00:00 local time, October
322      * 15, 1582. Previous to this time and date will be Julian dates.
323      *
324      * @return   The Gregorian cutover time for this calendar.
325      * @stable ICU 2.0
326      */
327     UDate getGregorianChange(void) const;
328 
329     /**
330      * Return true if the given year is a leap year. Determination of whether a year is
331      * a leap year is actually very complicated. We do something crude and mostly
332      * correct here, but for a real determination you need a lot of contextual
333      * information. For example, in Sweden, the change from Julian to Gregorian happened
334      * in a complex way resulting in missed leap years and double leap years between
335      * 1700 and 1753. Another example is that after the start of the Julian calendar in
336      * 45 B.C., the leap years did not regularize until 8 A.D. This method ignores these
337      * quirks, and pays attention only to the Julian onset date and the Gregorian
338      * cutover (which can be changed).
339      *
340      * @param year  The given year.
341      * @return      True if the given year is a leap year; false otherwise.
342      * @stable ICU 2.0
343      */
344     UBool isLeapYear(int32_t year) const;
345 
346     /**
347      * Returns true if the given Calendar object is equivalent to this
348      * one.  Calendar override.
349      *
350      * @param other the Calendar to be compared with this Calendar
351      * @stable ICU 2.4
352      */
353     virtual UBool isEquivalentTo(const Calendar& other) const override;
354 
355 #ifndef U_FORCE_HIDE_DEPRECATED_API
356     /**
357      * (Overrides Calendar) Rolls up or down by the given amount in the specified field.
358      * For more information, see the documentation for Calendar::roll().
359      *
360      * @param field   The time field.
361      * @param amount  Indicates amount to roll.
362      * @param status  Output param set to success/failure code on exit. If any value
363      *                previously set in the time field is invalid, this will be set to
364      *                an error status.
365      * @deprecated ICU 2.6. Use roll(UCalendarDateFields field, int32_t amount, UErrorCode& status) instead.
366      */
367     virtual void roll(EDateFields field, int32_t amount, UErrorCode& status) override;
368 #endif  // U_FORCE_HIDE_DEPRECATED_API
369 
370     /**
371      * (Overrides Calendar) Rolls up or down by the given amount in the specified field.
372      * For more information, see the documentation for Calendar::roll().
373      *
374      * @param field   The time field.
375      * @param amount  Indicates amount to roll.
376      * @param status  Output param set to success/failure code on exit. If any value
377      *                previously set in the time field is invalid, this will be set to
378      *                an error status.
379      * @stable ICU 2.6.
380      */
381     virtual void roll(UCalendarDateFields field, int32_t amount, UErrorCode& status) override;
382 
383 #ifndef U_HIDE_DEPRECATED_API
384     /**
385      * Return the minimum value that this field could have, given the current date.
386      * For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum().
387      * @param field    the time field.
388      * @return         the minimum value that this field could have, given the current date.
389      * @deprecated ICU 2.6. Use getActualMinimum(UCalendarDateFields field) instead.
390      */
391     int32_t getActualMinimum(EDateFields field) const;
392 
393     /**
394      * Return the minimum value that this field could have, given the current date.
395      * For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum().
396      * @param field    the time field.
397      * @param status
398      * @return         the minimum value that this field could have, given the current date.
399      * @deprecated ICU 2.6. Use getActualMinimum(UCalendarDateFields field) instead. (Added to ICU 3.0 for signature consistency)
400      */
401     int32_t getActualMinimum(EDateFields field, UErrorCode& status) const;
402 #endif  /* U_HIDE_DEPRECATED_API */
403 
404     /**
405      * Return the minimum value that this field could have, given the current date.
406      * For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum().
407      * @param field    the time field.
408      * @param status   error result.
409      * @return         the minimum value that this field could have, given the current date.
410      * @stable ICU 3.0
411      */
412     int32_t getActualMinimum(UCalendarDateFields field, UErrorCode &status) const override;
413 
414 #ifndef U_HIDE_DEPRECATED_API
415     /**
416      * Return the maximum value that this field could have, given the current date.
417      * For example, with the date "Feb 3, 1997" and the DAY_OF_MONTH field, the actual
418      * maximum would be 28; for "Feb 3, 1996" it s 29.  Similarly for a Hebrew calendar,
419      * for some years the actual maximum for MONTH is 12, and for others 13.
420      * @param field    the time field.
421      * @return         the maximum value that this field could have, given the current date.
422      * @deprecated ICU 2.6. Use getActualMaximum(UCalendarDateFields field) instead.
423      */
424     int32_t getActualMaximum(EDateFields field) const;
425 #endif  /* U_HIDE_DEPRECATED_API */
426 
427     /**
428      * Return the maximum value that this field could have, given the current date.
429      * For example, with the date "Feb 3, 1997" and the DAY_OF_MONTH field, the actual
430      * maximum would be 28; for "Feb 3, 1996" it s 29.  Similarly for a Hebrew calendar,
431      * for some years the actual maximum for MONTH is 12, and for others 13.
432      * @param field    the time field.
433      * @param status   returns any errors that may result from this function call.
434      * @return         the maximum value that this field could have, given the current date.
435      * @stable ICU 2.6
436      */
437     virtual int32_t getActualMaximum(UCalendarDateFields field, UErrorCode& status) const override;
438 
439     /**
440      * (Overrides Calendar) Return true if the current date for this Calendar is in
441      * Daylight Savings Time. Recognizes DST_OFFSET, if it is set.
442      *
443      * @param status Fill-in parameter which receives the status of this operation.
444      * @return   True if the current date for this Calendar is in Daylight Savings Time,
445      *           false, otherwise.
446      * @stable ICU 2.0
447      */
448     virtual UBool inDaylightTime(UErrorCode& status) const override;
449 
450 public:
451 
452     /**
453      * Override Calendar Returns a unique class ID POLYMORPHICALLY. Pure virtual
454      * override. This method is to implement a simple version of RTTI, since not all C++
455      * compilers support genuine RTTI. Polymorphic operator==() and clone() methods call
456      * this method.
457      *
458      * @return   The class ID for this object. All objects of a given class have the
459      *           same class ID. Objects of other classes have different class IDs.
460      * @stable ICU 2.0
461      */
462     virtual UClassID getDynamicClassID(void) const override;
463 
464     /**
465      * Return the class ID for this class. This is useful only for comparing to a return
466      * value from getDynamicClassID(). For example:
467      *
468      *      Base* polymorphic_pointer = createPolymorphicObject();
469      *      if (polymorphic_pointer->getDynamicClassID() ==
470      *          Derived::getStaticClassID()) ...
471      *
472      * @return   The class ID for all objects of this class.
473      * @stable ICU 2.0
474      */
475     static UClassID U_EXPORT2 getStaticClassID(void);
476 
477     /**
478      * Returns the calendar type name string for this Calendar object.
479      * The returned string is the legacy ICU calendar attribute value,
480      * for example, "gregorian" or "japanese".
481      *
482      * For more details see the Calendar::getType() documentation.
483      *
484      * @return legacy calendar type name string
485      * @stable ICU 49
486      */
487     virtual const char * getType() const override;
488 
489  private:
490     GregorianCalendar(); // default constructor not implemented
491 
492  protected:
493     /**
494      * Return the ERA.  We need a special method for this because the
495      * default ERA is AD, but a zero (unset) ERA is BC.
496      * @return    the ERA.
497      * @internal
498      */
499     virtual int32_t internalGetEra() const;
500 
501     /**
502      * Return the Julian day number of day before the first day of the
503      * given month in the given extended year.  Subclasses should override
504      * this method to implement their calendar system.
505      * @param eyear the extended year
506      * @param month the zero-based month, or 0 if useMonth is false
507      * @param useMonth if false, compute the day before the first day of
508      * the given year, otherwise, compute the day before the first day of
509      * the given month
510      * @return the Julian day number of the day before the first
511      * day of the given month and year
512      * @internal
513      */
514     virtual int32_t handleComputeMonthStart(int32_t eyear, int32_t month,
515                                                    UBool useMonth) const override;
516 
517     /**
518      * Subclasses may override this.  This method calls
519      * handleGetMonthLength() to obtain the calendar-specific month
520      * length.
521      * @param bestField which field to use to calculate the date
522      * @return julian day specified by calendar fields.
523      * @internal
524      */
525     virtual int32_t handleComputeJulianDay(UCalendarDateFields bestField) override;
526 
527     /**
528      * Return the number of days in the given month of the given extended
529      * year of this calendar system.  Subclasses should override this
530      * method if they can provide a more correct or more efficient
531      * implementation than the default implementation in Calendar.
532      * @internal
533      */
534     virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month) const override;
535 
536     /**
537      * Return the number of days in the given extended year of this
538      * calendar system.  Subclasses should override this method if they can
539      * provide a more correct or more efficient implementation than the
540      * default implementation in Calendar.
541      * @stable ICU 2.0
542      */
543     virtual int32_t handleGetYearLength(int32_t eyear) const override;
544 
545     /**
546      * return the length of the given month.
547      * @param month    the given month.
548      * @return    the length of the given month.
549      * @internal
550      */
551     virtual int32_t monthLength(int32_t month) const;
552 
553     /**
554      * return the length of the month according to the given year.
555      * @param month    the given month.
556      * @param year     the given year.
557      * @return         the length of the month
558      * @internal
559      */
560     virtual int32_t monthLength(int32_t month, int32_t year) const;
561 
562 #ifndef U_HIDE_INTERNAL_API
563     /**
564      * return the length of the given year.
565      * @param year    the given year.
566      * @return        the length of the given year.
567      * @internal
568      */
569     int32_t yearLength(int32_t year) const;
570 
571     /**
572      * return the length of the year field.
573      * @return    the length of the year field
574      * @internal
575      */
576     int32_t yearLength(void) const;
577 
578     /**
579      * After adjustments such as add(MONTH), add(YEAR), we don't want the
580      * month to jump around.  E.g., we don't want Jan 31 + 1 month to go to Mar
581      * 3, we want it to go to Feb 28.  Adjustments which might run into this
582      * problem call this method to retain the proper month.
583      * @internal
584      */
585     void pinDayOfMonth(void);
586 #endif  /* U_HIDE_INTERNAL_API */
587 
588     /**
589      * Return the day number with respect to the epoch.  January 1, 1970 (Gregorian)
590      * is day zero.
591      * @param status Fill-in parameter which receives the status of this operation.
592      * @return       the day number with respect to the epoch.
593      * @internal
594      */
595     virtual UDate getEpochDay(UErrorCode& status);
596 
597     /**
598      * Subclass API for defining limits of different types.
599      * Subclasses must implement this method to return limits for the
600      * following fields:
601      *
602      * <pre>UCAL_ERA
603      * UCAL_YEAR
604      * UCAL_MONTH
605      * UCAL_WEEK_OF_YEAR
606      * UCAL_WEEK_OF_MONTH
607      * UCAL_DATE (DAY_OF_MONTH on Java)
608      * UCAL_DAY_OF_YEAR
609      * UCAL_DAY_OF_WEEK_IN_MONTH
610      * UCAL_YEAR_WOY
611      * UCAL_EXTENDED_YEAR</pre>
612      *
613      * @param field one of the above field numbers
614      * @param limitType one of <code>MINIMUM</code>, <code>GREATEST_MINIMUM</code>,
615      * <code>LEAST_MAXIMUM</code>, or <code>MAXIMUM</code>
616      * @internal
617      */
618     virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const override;
619 
620     /**
621      * Return the extended year defined by the current fields.  This will
622      * use the UCAL_EXTENDED_YEAR field or the UCAL_YEAR and supra-year fields (such
623      * as UCAL_ERA) specific to the calendar system, depending on which set of
624      * fields is newer.
625      * @return the extended year
626      * @internal
627      */
628     virtual int32_t handleGetExtendedYear() override;
629 
630     /**
631      * Subclasses may override this to convert from week fields
632      * (YEAR_WOY and WEEK_OF_YEAR) to an extended year in the case
633      * where YEAR, EXTENDED_YEAR are not set.
634      * The Gregorian implementation assumes a yearWoy in gregorian format, according to the current era.
635      * @return the extended year, UCAL_EXTENDED_YEAR
636      * @internal
637      */
638     virtual int32_t handleGetExtendedYearFromWeekFields(int32_t yearWoy, int32_t woy) override;
639 
640 
641     /**
642      * Subclasses may override this method to compute several fields
643      * specific to each calendar system.  These are:
644      *
645      * <ul><li>ERA
646      * <li>YEAR
647      * <li>MONTH
648      * <li>DAY_OF_MONTH
649      * <li>DAY_OF_YEAR
650      * <li>EXTENDED_YEAR</ul>
651      *
652      * <p>The GregorianCalendar implementation implements
653      * a calendar with the specified Julian/Gregorian cutover date.
654      * @internal
655      */
656     virtual void handleComputeFields(int32_t julianDay, UErrorCode &status) override;
657 
658  private:
659     /**
660      * Compute the julian day number of the given year.
661      * @param isGregorian    if true, using Gregorian calendar, otherwise using Julian calendar
662      * @param year           the given year.
663      * @param isLeap         true if the year is a leap year.
664      * @return
665      */
666     static double computeJulianDayOfYear(UBool isGregorian, int32_t year,
667                                          UBool& isLeap);
668 
669     /**
670      * Validates the values of the set time fields.  True if they're all valid.
671      * @return    True if the set time fields are all valid.
672      */
673     UBool validateFields(void) const;
674 
675     /**
676      * Validates the value of the given time field.  True if it's valid.
677      */
678     UBool boundsCheck(int32_t value, UCalendarDateFields field) const;
679 
680     /**
681      * Return the pseudo-time-stamp for two fields, given their
682      * individual pseudo-time-stamps.  If either of the fields
683      * is unset, then the aggregate is unset.  Otherwise, the
684      * aggregate is the later of the two stamps.
685      * @param stamp_a    One given field.
686      * @param stamp_b    Another given field.
687      * @return the pseudo-time-stamp for two fields
688      */
689     int32_t aggregateStamp(int32_t stamp_a, int32_t stamp_b);
690 
691     /**
692      * The point at which the Gregorian calendar rules are used, measured in
693      * milliseconds from the standard epoch.  Default is October 15, 1582
694      * (Gregorian) 00:00:00 UTC, that is, October 4, 1582 (Julian) is followed
695      * by October 15, 1582 (Gregorian).  This corresponds to Julian day number
696      * 2299161. This is measured from the standard epoch, not in Julian Days.
697      */
698     UDate                fGregorianCutover;
699 
700     /**
701      * Julian day number of the Gregorian cutover
702      */
703     int32_t             fCutoverJulianDay;
704 
705     /**
706      * Midnight, local time (using this Calendar's TimeZone) at or before the
707      * gregorianCutover. This is a pure date value with no time of day or
708      * timezone component.
709      */
710     UDate                 fNormalizedGregorianCutover;// = gregorianCutover;
711 
712     /**
713      * The year of the gregorianCutover, with 0 representing
714      * 1 BC, -1 representing 2 BC, etc.
715      */
716     int32_t fGregorianCutoverYear;// = 1582;
717 
718     /**
719      * The year of the gregorianCutover, with 0 representing
720      * 1 BC, -1 representing 2 BC, etc.
721      */
722     int32_t fGregorianCutoverJulianDay;// = 2299161;
723 
724     /**
725      * Converts time as milliseconds to Julian date. The Julian date used here is not a
726      * true Julian date, since it is measured from midnight, not noon.
727      *
728      * @param millis  The given milliseconds.
729      * @return        The Julian date number.
730      */
731     static double millisToJulianDay(UDate millis);
732 
733     /**
734      * Converts Julian date to time as milliseconds. The Julian date used here is not a
735      * true Julian date, since it is measured from midnight, not noon.
736      *
737      * @param julian  The given Julian date number.
738      * @return        Time as milliseconds.
739      */
740     static UDate julianDayToMillis(double julian);
741 
742     /**
743      * Used by handleComputeJulianDay() and handleComputeMonthStart().
744      * Temporary field indicating whether the calendar is currently Gregorian as opposed to Julian.
745      */
746     UBool fIsGregorian;
747 
748     /**
749      * Used by handleComputeJulianDay() and handleComputeMonthStart().
750      * Temporary field indicating that the sense of the gregorian cutover should be inverted
751      * to handle certain calculations on and around the cutover date.
752      */
753     UBool fInvertGregorian;
754 
755 
756  public: // internal implementation
757 
758     /**
759      * @return true if this calendar has the notion of a default century
760      * @internal
761      */
762     virtual UBool haveDefaultCentury() const override;
763 
764     /**
765      * @return the start of the default century
766      * @internal
767      */
768     virtual UDate defaultCenturyStart() const override;
769 
770     /**
771      * @return the beginning year of the default century
772      * @internal
773      */
774     virtual int32_t defaultCenturyStartYear() const override;
775 };
776 
777 U_NAMESPACE_END
778 
779 #endif /* #if !UCONFIG_NO_FORMATTING */
780 
781 #endif /* U_SHOW_CPLUSPLUS_API */
782 
783 #endif // _GREGOCAL
784 //eof
785 
786