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