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 ********************************************************************************
5*0e209d39SAndroid Build Coastguard Worker * Copyright (C) 1997-2014, International Business Machines
6*0e209d39SAndroid Build Coastguard Worker * Corporation and others. All Rights Reserved.
7*0e209d39SAndroid Build Coastguard Worker ********************************************************************************
8*0e209d39SAndroid Build Coastguard Worker *
9*0e209d39SAndroid Build Coastguard Worker * File CALENDAR.H
10*0e209d39SAndroid Build Coastguard Worker *
11*0e209d39SAndroid Build Coastguard Worker * Modification History:
12*0e209d39SAndroid Build Coastguard Worker *
13*0e209d39SAndroid Build Coastguard Worker * Date Name Description
14*0e209d39SAndroid Build Coastguard Worker * 04/22/97 aliu Expanded and corrected comments and other header
15*0e209d39SAndroid Build Coastguard Worker * contents.
16*0e209d39SAndroid Build Coastguard Worker * 05/01/97 aliu Made equals(), before(), after() arguments const.
17*0e209d39SAndroid Build Coastguard Worker * 05/20/97 aliu Replaced fAreFieldsSet with fAreFieldsInSync and
18*0e209d39SAndroid Build Coastguard Worker * fAreAllFieldsSet.
19*0e209d39SAndroid Build Coastguard Worker * 07/27/98 stephen Sync up with JDK 1.2
20*0e209d39SAndroid Build Coastguard Worker * 11/15/99 weiv added YEAR_WOY and DOW_LOCAL
21*0e209d39SAndroid Build Coastguard Worker * to EDateFields
22*0e209d39SAndroid Build Coastguard Worker * 8/19/2002 srl Removed Javaisms
23*0e209d39SAndroid Build Coastguard Worker * 11/07/2003 srl Update, clean up documentation.
24*0e209d39SAndroid Build Coastguard Worker ********************************************************************************
25*0e209d39SAndroid Build Coastguard Worker */
26*0e209d39SAndroid Build Coastguard Worker
27*0e209d39SAndroid Build Coastguard Worker #ifndef CALENDAR_H
28*0e209d39SAndroid Build Coastguard Worker #define CALENDAR_H
29*0e209d39SAndroid Build Coastguard Worker
30*0e209d39SAndroid Build Coastguard Worker #include "unicode/utypes.h"
31*0e209d39SAndroid Build Coastguard Worker
32*0e209d39SAndroid Build Coastguard Worker #if U_SHOW_CPLUSPLUS_API
33*0e209d39SAndroid Build Coastguard Worker
34*0e209d39SAndroid Build Coastguard Worker /**
35*0e209d39SAndroid Build Coastguard Worker * \file
36*0e209d39SAndroid Build Coastguard Worker * \brief C++ API: Calendar object
37*0e209d39SAndroid Build Coastguard Worker */
38*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_FORMATTING
39*0e209d39SAndroid Build Coastguard Worker
40*0e209d39SAndroid Build Coastguard Worker #include "unicode/uobject.h"
41*0e209d39SAndroid Build Coastguard Worker #include "unicode/locid.h"
42*0e209d39SAndroid Build Coastguard Worker #include "unicode/timezone.h"
43*0e209d39SAndroid Build Coastguard Worker #include "unicode/ucal.h"
44*0e209d39SAndroid Build Coastguard Worker #include "unicode/umisc.h"
45*0e209d39SAndroid Build Coastguard Worker
46*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_BEGIN
47*0e209d39SAndroid Build Coastguard Worker
48*0e209d39SAndroid Build Coastguard Worker class ICUServiceFactory;
49*0e209d39SAndroid Build Coastguard Worker
50*0e209d39SAndroid Build Coastguard Worker // Do not conditionalize the following with #ifndef U_HIDE_INTERNAL_API,
51*0e209d39SAndroid Build Coastguard Worker // it is a return type for a virtual method (@internal)
52*0e209d39SAndroid Build Coastguard Worker /**
53*0e209d39SAndroid Build Coastguard Worker * @internal
54*0e209d39SAndroid Build Coastguard Worker */
55*0e209d39SAndroid Build Coastguard Worker typedef int32_t UFieldResolutionTable[12][8];
56*0e209d39SAndroid Build Coastguard Worker
57*0e209d39SAndroid Build Coastguard Worker class BasicTimeZone;
58*0e209d39SAndroid Build Coastguard Worker /**
59*0e209d39SAndroid Build Coastguard Worker * `Calendar` is an abstract base class for converting between
60*0e209d39SAndroid Build Coastguard Worker * a `UDate` object and a set of integer fields such as
61*0e209d39SAndroid Build Coastguard Worker * `YEAR`, `MONTH`, `DAY`, `HOUR`, and so on.
62*0e209d39SAndroid Build Coastguard Worker * (A `UDate` object represents a specific instant in
63*0e209d39SAndroid Build Coastguard Worker * time with millisecond precision. See UDate
64*0e209d39SAndroid Build Coastguard Worker * for information about the `UDate` class.)
65*0e209d39SAndroid Build Coastguard Worker *
66*0e209d39SAndroid Build Coastguard Worker * Subclasses of `Calendar` interpret a `UDate`
67*0e209d39SAndroid Build Coastguard Worker * according to the rules of a specific calendar system.
68*0e209d39SAndroid Build Coastguard Worker * The most commonly used subclass of `Calendar` is
69*0e209d39SAndroid Build Coastguard Worker * `GregorianCalendar`. Other subclasses could represent
70*0e209d39SAndroid Build Coastguard Worker * the various types of lunar calendars in use in many parts of the world.
71*0e209d39SAndroid Build Coastguard Worker *
72*0e209d39SAndroid Build Coastguard Worker * **NOTE**: (ICU 2.6) The subclass interface should be considered unstable -
73*0e209d39SAndroid Build Coastguard Worker * it WILL change.
74*0e209d39SAndroid Build Coastguard Worker *
75*0e209d39SAndroid Build Coastguard Worker * Like other locale-sensitive classes, `Calendar` provides a
76*0e209d39SAndroid Build Coastguard Worker * static method, `createInstance`, for getting a generally useful
77*0e209d39SAndroid Build Coastguard Worker * object of this type. `Calendar`'s `createInstance` method
78*0e209d39SAndroid Build Coastguard Worker * returns the appropriate `Calendar` subclass whose
79*0e209d39SAndroid Build Coastguard Worker * time fields have been initialized with the current date and time:
80*0e209d39SAndroid Build Coastguard Worker *
81*0e209d39SAndroid Build Coastguard Worker * Calendar *rightNow = Calendar::createInstance(errCode);
82*0e209d39SAndroid Build Coastguard Worker *
83*0e209d39SAndroid Build Coastguard Worker * A `Calendar` object can produce all the time field values
84*0e209d39SAndroid Build Coastguard Worker * needed to implement the date-time formatting for a particular language
85*0e209d39SAndroid Build Coastguard Worker * and calendar style (for example, Japanese-Gregorian, Japanese-Traditional).
86*0e209d39SAndroid Build Coastguard Worker *
87*0e209d39SAndroid Build Coastguard Worker * When computing a `UDate` from time fields, some special circumstances
88*0e209d39SAndroid Build Coastguard Worker * may arise: there may be insufficient information to compute the
89*0e209d39SAndroid Build Coastguard Worker * `UDate` (such as only year and month but no day in the month),
90*0e209d39SAndroid Build Coastguard Worker * there may be inconsistent information (such as "Tuesday, July 15, 1996"
91*0e209d39SAndroid Build Coastguard Worker * -- July 15, 1996 is actually a Monday), or the input time might be ambiguous
92*0e209d39SAndroid Build Coastguard Worker * because of time zone transition.
93*0e209d39SAndroid Build Coastguard Worker *
94*0e209d39SAndroid Build Coastguard Worker * **Insufficient information.** The calendar will use default
95*0e209d39SAndroid Build Coastguard Worker * information to specify the missing fields. This may vary by calendar; for
96*0e209d39SAndroid Build Coastguard Worker * the Gregorian calendar, the default for a field is the same as that of the
97*0e209d39SAndroid Build Coastguard Worker * start of the epoch: i.e., YEAR = 1970, MONTH = JANUARY, DATE = 1, etc.
98*0e209d39SAndroid Build Coastguard Worker *
99*0e209d39SAndroid Build Coastguard Worker * **Inconsistent information.** If fields conflict, the calendar
100*0e209d39SAndroid Build Coastguard Worker * will give preference to fields set more recently. For example, when
101*0e209d39SAndroid Build Coastguard Worker * determining the day, the calendar will look for one of the following
102*0e209d39SAndroid Build Coastguard Worker * combinations of fields. The most recent combination, as determined by the
103*0e209d39SAndroid Build Coastguard Worker * most recently set single field, will be used.
104*0e209d39SAndroid Build Coastguard Worker *
105*0e209d39SAndroid Build Coastguard Worker * MONTH + DAY_OF_MONTH
106*0e209d39SAndroid Build Coastguard Worker * MONTH + WEEK_OF_MONTH + DAY_OF_WEEK
107*0e209d39SAndroid Build Coastguard Worker * MONTH + DAY_OF_WEEK_IN_MONTH + DAY_OF_WEEK
108*0e209d39SAndroid Build Coastguard Worker * DAY_OF_YEAR
109*0e209d39SAndroid Build Coastguard Worker * DAY_OF_WEEK + WEEK_OF_YEAR
110*0e209d39SAndroid Build Coastguard Worker *
111*0e209d39SAndroid Build Coastguard Worker * For the time of day:
112*0e209d39SAndroid Build Coastguard Worker *
113*0e209d39SAndroid Build Coastguard Worker * HOUR_OF_DAY
114*0e209d39SAndroid Build Coastguard Worker * AM_PM + HOUR
115*0e209d39SAndroid Build Coastguard Worker *
116*0e209d39SAndroid Build Coastguard Worker * **Ambiguous Wall Clock Time.** When time offset from UTC has
117*0e209d39SAndroid Build Coastguard Worker * changed, it produces an ambiguous time slot around the transition. For example,
118*0e209d39SAndroid Build Coastguard Worker * many US locations observe daylight saving time. On the date switching to daylight
119*0e209d39SAndroid Build Coastguard Worker * saving time in US, wall clock time jumps from 12:59 AM (standard) to 2:00 AM
120*0e209d39SAndroid Build Coastguard Worker * (daylight). Therefore, wall clock time from 1:00 AM to 1:59 AM do not exist on
121*0e209d39SAndroid Build Coastguard Worker * the date. When the input wall time fall into this missing time slot, the ICU
122*0e209d39SAndroid Build Coastguard Worker * Calendar resolves the time using the UTC offset before the transition by default.
123*0e209d39SAndroid Build Coastguard Worker * In this example, 1:30 AM is interpreted as 1:30 AM standard time (non-exist),
124*0e209d39SAndroid Build Coastguard Worker * so the final result will be 2:30 AM daylight time.
125*0e209d39SAndroid Build Coastguard Worker *
126*0e209d39SAndroid Build Coastguard Worker * On the date switching back to standard time, wall clock time is moved back one
127*0e209d39SAndroid Build Coastguard Worker * hour at 2:00 AM. So wall clock time from 1:00 AM to 1:59 AM occur twice. In this
128*0e209d39SAndroid Build Coastguard Worker * case, the ICU Calendar resolves the time using the UTC offset after the transition
129*0e209d39SAndroid Build Coastguard Worker * by default. For example, 1:30 AM on the date is resolved as 1:30 AM standard time.
130*0e209d39SAndroid Build Coastguard Worker *
131*0e209d39SAndroid Build Coastguard Worker * Ambiguous wall clock time resolution behaviors can be customized by Calendar APIs
132*0e209d39SAndroid Build Coastguard Worker * {@link #setRepeatedWallTimeOption} and {@link #setSkippedWallTimeOption}.
133*0e209d39SAndroid Build Coastguard Worker * These methods are available in ICU 49 or later versions.
134*0e209d39SAndroid Build Coastguard Worker *
135*0e209d39SAndroid Build Coastguard Worker * **Note:** for some non-Gregorian calendars, different
136*0e209d39SAndroid Build Coastguard Worker * fields may be necessary for complete disambiguation. For example, a full
137*0e209d39SAndroid Build Coastguard Worker * specification of the historical Arabic astronomical calendar requires year,
138*0e209d39SAndroid Build Coastguard Worker * month, day-of-month *and* day-of-week in some cases.
139*0e209d39SAndroid Build Coastguard Worker *
140*0e209d39SAndroid Build Coastguard Worker * **Note:** There are certain possible ambiguities in
141*0e209d39SAndroid Build Coastguard Worker * interpretation of certain singular times, which are resolved in the
142*0e209d39SAndroid Build Coastguard Worker * following ways:
143*0e209d39SAndroid Build Coastguard Worker *
144*0e209d39SAndroid Build Coastguard Worker * 1. 24:00:00 "belongs" to the following day. That is,
145*0e209d39SAndroid Build Coastguard Worker * 23:59 on Dec 31, 1969 < 24:00 on Jan 1, 1970 < 24:01:00 on Jan 1, 1970
146*0e209d39SAndroid Build Coastguard Worker * 2. Although historically not precise, midnight also belongs to "am",
147*0e209d39SAndroid Build Coastguard Worker * and noon belongs to "pm", so on the same day,
148*0e209d39SAndroid Build Coastguard Worker * 12:00 am (midnight) < 12:01 am, and 12:00 pm (noon) < 12:01 pm
149*0e209d39SAndroid Build Coastguard Worker *
150*0e209d39SAndroid Build Coastguard Worker * The date or time format strings are not part of the definition of a
151*0e209d39SAndroid Build Coastguard Worker * calendar, as those must be modifiable or overridable by the user at
152*0e209d39SAndroid Build Coastguard Worker * runtime. Use `DateFormat` to format dates.
153*0e209d39SAndroid Build Coastguard Worker *
154*0e209d39SAndroid Build Coastguard Worker * `Calendar` provides an API for field "rolling", where fields
155*0e209d39SAndroid Build Coastguard Worker * can be incremented or decremented, but wrap around. For example, rolling the
156*0e209d39SAndroid Build Coastguard Worker * month up in the date December 12, **1996** results in
157*0e209d39SAndroid Build Coastguard Worker * January 12, **1996**.
158*0e209d39SAndroid Build Coastguard Worker *
159*0e209d39SAndroid Build Coastguard Worker * `Calendar` also provides a date arithmetic function for
160*0e209d39SAndroid Build Coastguard Worker * adding the specified (signed) amount of time to a particular time field.
161*0e209d39SAndroid Build Coastguard Worker * For example, subtracting 5 days from the date `September 12, 1996`
162*0e209d39SAndroid Build Coastguard Worker * results in `September 7, 1996`.
163*0e209d39SAndroid Build Coastguard Worker *
164*0e209d39SAndroid Build Coastguard Worker * ***Supported range***
165*0e209d39SAndroid Build Coastguard Worker *
166*0e209d39SAndroid Build Coastguard Worker * The allowable range of `Calendar` has been narrowed. `GregorianCalendar` used
167*0e209d39SAndroid Build Coastguard Worker * to attempt to support the range of dates with millisecond values from
168*0e209d39SAndroid Build Coastguard Worker * `Long.MIN_VALUE` to `Long.MAX_VALUE`. The new `Calendar` protocol specifies the
169*0e209d39SAndroid Build Coastguard Worker * maximum range of supportable dates as those having Julian day numbers
170*0e209d39SAndroid Build Coastguard Worker * of `-0x7F000000` to `+0x7F000000`. This corresponds to years from ~5,800,000 BCE
171*0e209d39SAndroid Build Coastguard Worker * to ~5,800,000 CE. Programmers should use the protected constants in `Calendar` to
172*0e209d39SAndroid Build Coastguard Worker * specify an extremely early or extremely late date.
173*0e209d39SAndroid Build Coastguard Worker *
174*0e209d39SAndroid Build Coastguard Worker * <p>
175*0e209d39SAndroid Build Coastguard Worker * The Japanese calendar uses a combination of era name and year number.
176*0e209d39SAndroid Build Coastguard Worker * When an emperor of Japan abdicates and a new emperor ascends the throne,
177*0e209d39SAndroid Build Coastguard Worker * a new era is declared and year number is reset to 1. Even if the date of
178*0e209d39SAndroid Build Coastguard Worker * abdication is scheduled ahead of time, the new era name might not be
179*0e209d39SAndroid Build Coastguard Worker * announced until just before the date. In such case, ICU4C may include
180*0e209d39SAndroid Build Coastguard Worker * a start date of future era without actual era name, but not enabled
181*0e209d39SAndroid Build Coastguard Worker * by default. ICU4C users who want to test the behavior of the future era
182*0e209d39SAndroid Build Coastguard Worker * can enable the tentative era by:
183*0e209d39SAndroid Build Coastguard Worker * <ul>
184*0e209d39SAndroid Build Coastguard Worker * <li>Environment variable <code>ICU_ENABLE_TENTATIVE_ERA=true</code>.</li>
185*0e209d39SAndroid Build Coastguard Worker * </ul>
186*0e209d39SAndroid Build Coastguard Worker *
187*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
188*0e209d39SAndroid Build Coastguard Worker */
189*0e209d39SAndroid Build Coastguard Worker class U_I18N_API Calendar : public UObject {
190*0e209d39SAndroid Build Coastguard Worker public:
191*0e209d39SAndroid Build Coastguard Worker #ifndef U_FORCE_HIDE_DEPRECATED_API
192*0e209d39SAndroid Build Coastguard Worker /**
193*0e209d39SAndroid Build Coastguard Worker * Field IDs for date and time. Used to specify date/time fields. ERA is calendar
194*0e209d39SAndroid Build Coastguard Worker * specific. Example ranges given are for illustration only; see specific Calendar
195*0e209d39SAndroid Build Coastguard Worker * subclasses for actual ranges.
196*0e209d39SAndroid Build Coastguard Worker * @deprecated ICU 2.6. Use C enum UCalendarDateFields defined in ucal.h
197*0e209d39SAndroid Build Coastguard Worker */
198*0e209d39SAndroid Build Coastguard Worker enum EDateFields {
199*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_DEPRECATED_API
200*0e209d39SAndroid Build Coastguard Worker /*
201*0e209d39SAndroid Build Coastguard Worker * ERA may be defined on other platforms. To avoid any potential problems undefined it here.
202*0e209d39SAndroid Build Coastguard Worker */
203*0e209d39SAndroid Build Coastguard Worker #ifdef ERA
204*0e209d39SAndroid Build Coastguard Worker #undef ERA
205*0e209d39SAndroid Build Coastguard Worker #endif
206*0e209d39SAndroid Build Coastguard Worker ERA, // Example: 0..1
207*0e209d39SAndroid Build Coastguard Worker YEAR, // Example: 1..big number
208*0e209d39SAndroid Build Coastguard Worker MONTH, // Example: 0..11
209*0e209d39SAndroid Build Coastguard Worker WEEK_OF_YEAR, // Example: 1..53
210*0e209d39SAndroid Build Coastguard Worker WEEK_OF_MONTH, // Example: 1..4
211*0e209d39SAndroid Build Coastguard Worker DATE, // Example: 1..31
212*0e209d39SAndroid Build Coastguard Worker DAY_OF_YEAR, // Example: 1..365
213*0e209d39SAndroid Build Coastguard Worker DAY_OF_WEEK, // Example: 1..7
214*0e209d39SAndroid Build Coastguard Worker DAY_OF_WEEK_IN_MONTH, // Example: 1..4, may be specified as -1
215*0e209d39SAndroid Build Coastguard Worker AM_PM, // Example: 0..1
216*0e209d39SAndroid Build Coastguard Worker HOUR, // Example: 0..11
217*0e209d39SAndroid Build Coastguard Worker HOUR_OF_DAY, // Example: 0..23
218*0e209d39SAndroid Build Coastguard Worker MINUTE, // Example: 0..59
219*0e209d39SAndroid Build Coastguard Worker SECOND, // Example: 0..59
220*0e209d39SAndroid Build Coastguard Worker MILLISECOND, // Example: 0..999
221*0e209d39SAndroid Build Coastguard Worker ZONE_OFFSET, // Example: -12*U_MILLIS_PER_HOUR..12*U_MILLIS_PER_HOUR
222*0e209d39SAndroid Build Coastguard Worker DST_OFFSET, // Example: 0 or U_MILLIS_PER_HOUR
223*0e209d39SAndroid Build Coastguard Worker YEAR_WOY, // 'Y' Example: 1..big number - Year of Week of Year
224*0e209d39SAndroid Build Coastguard Worker DOW_LOCAL, // 'e' Example: 1..7 - Day of Week / Localized
225*0e209d39SAndroid Build Coastguard Worker
226*0e209d39SAndroid Build Coastguard Worker EXTENDED_YEAR,
227*0e209d39SAndroid Build Coastguard Worker JULIAN_DAY,
228*0e209d39SAndroid Build Coastguard Worker MILLISECONDS_IN_DAY,
229*0e209d39SAndroid Build Coastguard Worker IS_LEAP_MONTH,
230*0e209d39SAndroid Build Coastguard Worker
231*0e209d39SAndroid Build Coastguard Worker FIELD_COUNT = UCAL_FIELD_COUNT // See ucal.h for other fields.
232*0e209d39SAndroid Build Coastguard Worker #endif /* U_HIDE_DEPRECATED_API */
233*0e209d39SAndroid Build Coastguard Worker };
234*0e209d39SAndroid Build Coastguard Worker #endif // U_FORCE_HIDE_DEPRECATED_API
235*0e209d39SAndroid Build Coastguard Worker
236*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_DEPRECATED_API
237*0e209d39SAndroid Build Coastguard Worker /**
238*0e209d39SAndroid Build Coastguard Worker * Useful constant for days of week. Note: Calendar day-of-week is 1-based. Clients
239*0e209d39SAndroid Build Coastguard Worker * who create locale resources for the field of first-day-of-week should be aware of
240*0e209d39SAndroid Build Coastguard Worker * this. For instance, in US locale, first-day-of-week is set to 1, i.e., SUNDAY.
241*0e209d39SAndroid Build Coastguard Worker * @deprecated ICU 2.6. Use C enum UCalendarDaysOfWeek defined in ucal.h
242*0e209d39SAndroid Build Coastguard Worker */
243*0e209d39SAndroid Build Coastguard Worker enum EDaysOfWeek {
244*0e209d39SAndroid Build Coastguard Worker SUNDAY = 1,
245*0e209d39SAndroid Build Coastguard Worker MONDAY,
246*0e209d39SAndroid Build Coastguard Worker TUESDAY,
247*0e209d39SAndroid Build Coastguard Worker WEDNESDAY,
248*0e209d39SAndroid Build Coastguard Worker THURSDAY,
249*0e209d39SAndroid Build Coastguard Worker FRIDAY,
250*0e209d39SAndroid Build Coastguard Worker SATURDAY
251*0e209d39SAndroid Build Coastguard Worker };
252*0e209d39SAndroid Build Coastguard Worker
253*0e209d39SAndroid Build Coastguard Worker /**
254*0e209d39SAndroid Build Coastguard Worker * Useful constants for month. Note: Calendar month is 0-based.
255*0e209d39SAndroid Build Coastguard Worker * @deprecated ICU 2.6. Use C enum UCalendarMonths defined in ucal.h
256*0e209d39SAndroid Build Coastguard Worker */
257*0e209d39SAndroid Build Coastguard Worker enum EMonths {
258*0e209d39SAndroid Build Coastguard Worker JANUARY,
259*0e209d39SAndroid Build Coastguard Worker FEBRUARY,
260*0e209d39SAndroid Build Coastguard Worker MARCH,
261*0e209d39SAndroid Build Coastguard Worker APRIL,
262*0e209d39SAndroid Build Coastguard Worker MAY,
263*0e209d39SAndroid Build Coastguard Worker JUNE,
264*0e209d39SAndroid Build Coastguard Worker JULY,
265*0e209d39SAndroid Build Coastguard Worker AUGUST,
266*0e209d39SAndroid Build Coastguard Worker SEPTEMBER,
267*0e209d39SAndroid Build Coastguard Worker OCTOBER,
268*0e209d39SAndroid Build Coastguard Worker NOVEMBER,
269*0e209d39SAndroid Build Coastguard Worker DECEMBER,
270*0e209d39SAndroid Build Coastguard Worker UNDECIMBER
271*0e209d39SAndroid Build Coastguard Worker };
272*0e209d39SAndroid Build Coastguard Worker
273*0e209d39SAndroid Build Coastguard Worker /**
274*0e209d39SAndroid Build Coastguard Worker * Useful constants for hour in 12-hour clock. Used in GregorianCalendar.
275*0e209d39SAndroid Build Coastguard Worker * @deprecated ICU 2.6. Use C enum UCalendarAMPMs defined in ucal.h
276*0e209d39SAndroid Build Coastguard Worker */
277*0e209d39SAndroid Build Coastguard Worker enum EAmpm {
278*0e209d39SAndroid Build Coastguard Worker AM,
279*0e209d39SAndroid Build Coastguard Worker PM
280*0e209d39SAndroid Build Coastguard Worker };
281*0e209d39SAndroid Build Coastguard Worker #endif /* U_HIDE_DEPRECATED_API */
282*0e209d39SAndroid Build Coastguard Worker
283*0e209d39SAndroid Build Coastguard Worker /**
284*0e209d39SAndroid Build Coastguard Worker * destructor
285*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
286*0e209d39SAndroid Build Coastguard Worker */
287*0e209d39SAndroid Build Coastguard Worker virtual ~Calendar();
288*0e209d39SAndroid Build Coastguard Worker
289*0e209d39SAndroid Build Coastguard Worker /**
290*0e209d39SAndroid Build Coastguard Worker * Create and return a polymorphic copy of this calendar.
291*0e209d39SAndroid Build Coastguard Worker *
292*0e209d39SAndroid Build Coastguard Worker * @return a polymorphic copy of this calendar.
293*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
294*0e209d39SAndroid Build Coastguard Worker */
295*0e209d39SAndroid Build Coastguard Worker virtual Calendar* clone() const = 0;
296*0e209d39SAndroid Build Coastguard Worker
297*0e209d39SAndroid Build Coastguard Worker /**
298*0e209d39SAndroid Build Coastguard Worker * Creates a Calendar using the default timezone and locale. Clients are responsible
299*0e209d39SAndroid Build Coastguard Worker * for deleting the object returned.
300*0e209d39SAndroid Build Coastguard Worker *
301*0e209d39SAndroid Build Coastguard Worker * @param success Indicates the success/failure of Calendar creation. Filled in
302*0e209d39SAndroid Build Coastguard Worker * with U_ZERO_ERROR if created successfully, set to a failure result
303*0e209d39SAndroid Build Coastguard Worker * otherwise. U_MISSING_RESOURCE_ERROR will be returned if the resource data
304*0e209d39SAndroid Build Coastguard Worker * requests a calendar type which has not been installed.
305*0e209d39SAndroid Build Coastguard Worker * @return A Calendar if created successfully. nullptr otherwise.
306*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
307*0e209d39SAndroid Build Coastguard Worker */
308*0e209d39SAndroid Build Coastguard Worker static Calendar* U_EXPORT2 createInstance(UErrorCode& success);
309*0e209d39SAndroid Build Coastguard Worker
310*0e209d39SAndroid Build Coastguard Worker /**
311*0e209d39SAndroid Build Coastguard Worker * Creates a Calendar using the given timezone and the default locale.
312*0e209d39SAndroid Build Coastguard Worker * The Calendar takes ownership of zoneToAdopt; the
313*0e209d39SAndroid Build Coastguard Worker * client must not delete it.
314*0e209d39SAndroid Build Coastguard Worker *
315*0e209d39SAndroid Build Coastguard Worker * @param zoneToAdopt The given timezone to be adopted.
316*0e209d39SAndroid Build Coastguard Worker * @param success Indicates the success/failure of Calendar creation. Filled in
317*0e209d39SAndroid Build Coastguard Worker * with U_ZERO_ERROR if created successfully, set to a failure result
318*0e209d39SAndroid Build Coastguard Worker * otherwise.
319*0e209d39SAndroid Build Coastguard Worker * @return A Calendar if created successfully. nullptr otherwise.
320*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
321*0e209d39SAndroid Build Coastguard Worker */
322*0e209d39SAndroid Build Coastguard Worker static Calendar* U_EXPORT2 createInstance(TimeZone* zoneToAdopt, UErrorCode& success);
323*0e209d39SAndroid Build Coastguard Worker
324*0e209d39SAndroid Build Coastguard Worker /**
325*0e209d39SAndroid Build Coastguard Worker * Creates a Calendar using the given timezone and the default locale. The TimeZone
326*0e209d39SAndroid Build Coastguard Worker * is _not_ adopted; the client is still responsible for deleting it.
327*0e209d39SAndroid Build Coastguard Worker *
328*0e209d39SAndroid Build Coastguard Worker * @param zone The timezone.
329*0e209d39SAndroid Build Coastguard Worker * @param success Indicates the success/failure of Calendar creation. Filled in
330*0e209d39SAndroid Build Coastguard Worker * with U_ZERO_ERROR if created successfully, set to a failure result
331*0e209d39SAndroid Build Coastguard Worker * otherwise.
332*0e209d39SAndroid Build Coastguard Worker * @return A Calendar if created successfully. nullptr otherwise.
333*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
334*0e209d39SAndroid Build Coastguard Worker */
335*0e209d39SAndroid Build Coastguard Worker static Calendar* U_EXPORT2 createInstance(const TimeZone& zone, UErrorCode& success);
336*0e209d39SAndroid Build Coastguard Worker
337*0e209d39SAndroid Build Coastguard Worker /**
338*0e209d39SAndroid Build Coastguard Worker * Creates a Calendar using the default timezone and the given locale.
339*0e209d39SAndroid Build Coastguard Worker *
340*0e209d39SAndroid Build Coastguard Worker * @param aLocale The given locale.
341*0e209d39SAndroid Build Coastguard Worker * @param success Indicates the success/failure of Calendar creation. Filled in
342*0e209d39SAndroid Build Coastguard Worker * with U_ZERO_ERROR if created successfully, set to a failure result
343*0e209d39SAndroid Build Coastguard Worker * otherwise.
344*0e209d39SAndroid Build Coastguard Worker * @return A Calendar if created successfully. nullptr otherwise.
345*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
346*0e209d39SAndroid Build Coastguard Worker */
347*0e209d39SAndroid Build Coastguard Worker static Calendar* U_EXPORT2 createInstance(const Locale& aLocale, UErrorCode& success);
348*0e209d39SAndroid Build Coastguard Worker
349*0e209d39SAndroid Build Coastguard Worker /**
350*0e209d39SAndroid Build Coastguard Worker * Creates a Calendar using the given timezone and given locale.
351*0e209d39SAndroid Build Coastguard Worker * The Calendar takes ownership of zoneToAdopt; the
352*0e209d39SAndroid Build Coastguard Worker * client must not delete it.
353*0e209d39SAndroid Build Coastguard Worker *
354*0e209d39SAndroid Build Coastguard Worker * @param zoneToAdopt The given timezone to be adopted.
355*0e209d39SAndroid Build Coastguard Worker * @param aLocale The given locale.
356*0e209d39SAndroid Build Coastguard Worker * @param success Indicates the success/failure of Calendar creation. Filled in
357*0e209d39SAndroid Build Coastguard Worker * with U_ZERO_ERROR if created successfully, set to a failure result
358*0e209d39SAndroid Build Coastguard Worker * otherwise.
359*0e209d39SAndroid Build Coastguard Worker * @return A Calendar if created successfully. nullptr otherwise.
360*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
361*0e209d39SAndroid Build Coastguard Worker */
362*0e209d39SAndroid Build Coastguard Worker static Calendar* U_EXPORT2 createInstance(TimeZone* zoneToAdopt, const Locale& aLocale, UErrorCode& success);
363*0e209d39SAndroid Build Coastguard Worker
364*0e209d39SAndroid Build Coastguard Worker /**
365*0e209d39SAndroid Build Coastguard Worker * Gets a Calendar using the given timezone and given locale. The TimeZone
366*0e209d39SAndroid Build Coastguard Worker * is _not_ adopted; the client is still responsible for deleting it.
367*0e209d39SAndroid Build Coastguard Worker *
368*0e209d39SAndroid Build Coastguard Worker * @param zone The given timezone.
369*0e209d39SAndroid Build Coastguard Worker * @param aLocale The given locale.
370*0e209d39SAndroid Build Coastguard Worker * @param success Indicates the success/failure of Calendar creation. Filled in
371*0e209d39SAndroid Build Coastguard Worker * with U_ZERO_ERROR if created successfully, set to a failure result
372*0e209d39SAndroid Build Coastguard Worker * otherwise.
373*0e209d39SAndroid Build Coastguard Worker * @return A Calendar if created successfully. nullptr otherwise.
374*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
375*0e209d39SAndroid Build Coastguard Worker */
376*0e209d39SAndroid Build Coastguard Worker static Calendar* U_EXPORT2 createInstance(const TimeZone& zone, const Locale& aLocale, UErrorCode& success);
377*0e209d39SAndroid Build Coastguard Worker
378*0e209d39SAndroid Build Coastguard Worker /**
379*0e209d39SAndroid Build Coastguard Worker * Returns a list of the locales for which Calendars are installed.
380*0e209d39SAndroid Build Coastguard Worker *
381*0e209d39SAndroid Build Coastguard Worker * @param count Number of locales returned.
382*0e209d39SAndroid Build Coastguard Worker * @return An array of Locale objects representing the set of locales for which
383*0e209d39SAndroid Build Coastguard Worker * Calendars are installed. The system retains ownership of this list;
384*0e209d39SAndroid Build Coastguard Worker * the caller must NOT delete it. Does not include user-registered Calendars.
385*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
386*0e209d39SAndroid Build Coastguard Worker */
387*0e209d39SAndroid Build Coastguard Worker static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
388*0e209d39SAndroid Build Coastguard Worker
389*0e209d39SAndroid Build Coastguard Worker
390*0e209d39SAndroid Build Coastguard Worker /**
391*0e209d39SAndroid Build Coastguard Worker * Given a key and a locale, returns an array of string values in a preferred
392*0e209d39SAndroid Build Coastguard Worker * order that would make a difference. These are all and only those values where
393*0e209d39SAndroid Build Coastguard Worker * the open (creation) of the service with the locale formed from the input locale
394*0e209d39SAndroid Build Coastguard Worker * plus input keyword and that value has different behavior than creation with the
395*0e209d39SAndroid Build Coastguard Worker * input locale alone.
396*0e209d39SAndroid Build Coastguard Worker * @param key one of the keys supported by this service. For now, only
397*0e209d39SAndroid Build Coastguard Worker * "calendar" is supported.
398*0e209d39SAndroid Build Coastguard Worker * @param locale the locale
399*0e209d39SAndroid Build Coastguard Worker * @param commonlyUsed if set to true it will return only commonly used values
400*0e209d39SAndroid Build Coastguard Worker * with the given locale in preferred order. Otherwise,
401*0e209d39SAndroid Build Coastguard Worker * it will return all the available values for the locale.
402*0e209d39SAndroid Build Coastguard Worker * @param status ICU Error Code
403*0e209d39SAndroid Build Coastguard Worker * @return a string enumeration over keyword values for the given key and the locale.
404*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.2
405*0e209d39SAndroid Build Coastguard Worker */
406*0e209d39SAndroid Build Coastguard Worker static StringEnumeration* U_EXPORT2 getKeywordValuesForLocale(const char* key,
407*0e209d39SAndroid Build Coastguard Worker const Locale& locale, UBool commonlyUsed, UErrorCode& status);
408*0e209d39SAndroid Build Coastguard Worker
409*0e209d39SAndroid Build Coastguard Worker /**
410*0e209d39SAndroid Build Coastguard Worker * Returns the current UTC (GMT) time measured in milliseconds since 0:00:00 on 1/1/70
411*0e209d39SAndroid Build Coastguard Worker * (derived from the system time).
412*0e209d39SAndroid Build Coastguard Worker *
413*0e209d39SAndroid Build Coastguard Worker * @return The current UTC time in milliseconds.
414*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
415*0e209d39SAndroid Build Coastguard Worker */
416*0e209d39SAndroid Build Coastguard Worker static UDate U_EXPORT2 getNow();
417*0e209d39SAndroid Build Coastguard Worker
418*0e209d39SAndroid Build Coastguard Worker /**
419*0e209d39SAndroid Build Coastguard Worker * Gets this Calendar's time as milliseconds. May involve recalculation of time due
420*0e209d39SAndroid Build Coastguard Worker * to previous calls to set time field values. The time specified is non-local UTC
421*0e209d39SAndroid Build Coastguard Worker * (GMT) time. Although this method is const, this object may actually be changed
422*0e209d39SAndroid Build Coastguard Worker * (semantically const).
423*0e209d39SAndroid Build Coastguard Worker *
424*0e209d39SAndroid Build Coastguard Worker * @param status Output param set to success/failure code on exit. If any value
425*0e209d39SAndroid Build Coastguard Worker * previously set in the time field is invalid or restricted by
426*0e209d39SAndroid Build Coastguard Worker * leniency, this will be set to an error status.
427*0e209d39SAndroid Build Coastguard Worker * @return The current time in UTC (GMT) time, or zero if the operation
428*0e209d39SAndroid Build Coastguard Worker * failed.
429*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
430*0e209d39SAndroid Build Coastguard Worker */
getTime(UErrorCode & status)431*0e209d39SAndroid Build Coastguard Worker inline UDate getTime(UErrorCode& status) const { return getTimeInMillis(status); }
432*0e209d39SAndroid Build Coastguard Worker
433*0e209d39SAndroid Build Coastguard Worker /**
434*0e209d39SAndroid Build Coastguard Worker * Sets this Calendar's current time with the given UDate. The time specified should
435*0e209d39SAndroid Build Coastguard Worker * be in non-local UTC (GMT) time.
436*0e209d39SAndroid Build Coastguard Worker *
437*0e209d39SAndroid Build Coastguard Worker * @param date The given UDate in UTC (GMT) time.
438*0e209d39SAndroid Build Coastguard Worker * @param status Output param set to success/failure code on exit. If any value
439*0e209d39SAndroid Build Coastguard Worker * set in the time field is invalid or restricted by
440*0e209d39SAndroid Build Coastguard Worker * leniency, this will be set to an error status.
441*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
442*0e209d39SAndroid Build Coastguard Worker */
setTime(UDate date,UErrorCode & status)443*0e209d39SAndroid Build Coastguard Worker inline void setTime(UDate date, UErrorCode& status) { setTimeInMillis(date, status); }
444*0e209d39SAndroid Build Coastguard Worker
445*0e209d39SAndroid Build Coastguard Worker /**
446*0e209d39SAndroid Build Coastguard Worker * Compares the equality of two Calendar objects. Objects of different subclasses
447*0e209d39SAndroid Build Coastguard Worker * are considered unequal. This comparison is very exacting; two Calendar objects
448*0e209d39SAndroid Build Coastguard Worker * must be in exactly the same state to be considered equal. To compare based on the
449*0e209d39SAndroid Build Coastguard Worker * represented time, use equals() instead.
450*0e209d39SAndroid Build Coastguard Worker *
451*0e209d39SAndroid Build Coastguard Worker * @param that The Calendar object to be compared with.
452*0e209d39SAndroid Build Coastguard Worker * @return true if the given Calendar is the same as this Calendar; false
453*0e209d39SAndroid Build Coastguard Worker * otherwise.
454*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
455*0e209d39SAndroid Build Coastguard Worker */
456*0e209d39SAndroid Build Coastguard Worker virtual bool operator==(const Calendar& that) const;
457*0e209d39SAndroid Build Coastguard Worker
458*0e209d39SAndroid Build Coastguard Worker /**
459*0e209d39SAndroid Build Coastguard Worker * Compares the inequality of two Calendar objects.
460*0e209d39SAndroid Build Coastguard Worker *
461*0e209d39SAndroid Build Coastguard Worker * @param that The Calendar object to be compared with.
462*0e209d39SAndroid Build Coastguard Worker * @return true if the given Calendar is not the same as this Calendar; false
463*0e209d39SAndroid Build Coastguard Worker * otherwise.
464*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
465*0e209d39SAndroid Build Coastguard Worker */
466*0e209d39SAndroid Build Coastguard Worker bool operator!=(const Calendar& that) const {return !operator==(that);}
467*0e209d39SAndroid Build Coastguard Worker
468*0e209d39SAndroid Build Coastguard Worker /**
469*0e209d39SAndroid Build Coastguard Worker * Returns true if the given Calendar object is equivalent to this
470*0e209d39SAndroid Build Coastguard Worker * one. An equivalent Calendar will behave exactly as this one
471*0e209d39SAndroid Build Coastguard Worker * does, but it may be set to a different time. By contrast, for
472*0e209d39SAndroid Build Coastguard Worker * the operator==() method to return true, the other Calendar must
473*0e209d39SAndroid Build Coastguard Worker * be set to the same time.
474*0e209d39SAndroid Build Coastguard Worker *
475*0e209d39SAndroid Build Coastguard Worker * @param other the Calendar to be compared with this Calendar
476*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.4
477*0e209d39SAndroid Build Coastguard Worker */
478*0e209d39SAndroid Build Coastguard Worker virtual UBool isEquivalentTo(const Calendar& other) const;
479*0e209d39SAndroid Build Coastguard Worker
480*0e209d39SAndroid Build Coastguard Worker /**
481*0e209d39SAndroid Build Coastguard Worker * Compares the Calendar time, whereas Calendar::operator== compares the equality of
482*0e209d39SAndroid Build Coastguard Worker * Calendar objects.
483*0e209d39SAndroid Build Coastguard Worker *
484*0e209d39SAndroid Build Coastguard Worker * @param when The Calendar to be compared with this Calendar. Although this is a
485*0e209d39SAndroid Build Coastguard Worker * const parameter, the object may be modified physically
486*0e209d39SAndroid Build Coastguard Worker * (semantically const).
487*0e209d39SAndroid Build Coastguard Worker * @param status Output param set to success/failure code on exit. If any value
488*0e209d39SAndroid Build Coastguard Worker * previously set in the time field is invalid or restricted by
489*0e209d39SAndroid Build Coastguard Worker * leniency, this will be set to an error status.
490*0e209d39SAndroid Build Coastguard Worker * @return True if the current time of this Calendar is equal to the time of
491*0e209d39SAndroid Build Coastguard Worker * Calendar when; false otherwise.
492*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
493*0e209d39SAndroid Build Coastguard Worker */
494*0e209d39SAndroid Build Coastguard Worker UBool equals(const Calendar& when, UErrorCode& status) const;
495*0e209d39SAndroid Build Coastguard Worker
496*0e209d39SAndroid Build Coastguard Worker /**
497*0e209d39SAndroid Build Coastguard Worker * Returns true if this Calendar's current time is before "when"'s current time.
498*0e209d39SAndroid Build Coastguard Worker *
499*0e209d39SAndroid Build Coastguard Worker * @param when The Calendar to be compared with this Calendar. Although this is a
500*0e209d39SAndroid Build Coastguard Worker * const parameter, the object may be modified physically
501*0e209d39SAndroid Build Coastguard Worker * (semantically const).
502*0e209d39SAndroid Build Coastguard Worker * @param status Output param set to success/failure code on exit. If any value
503*0e209d39SAndroid Build Coastguard Worker * previously set in the time field is invalid or restricted by
504*0e209d39SAndroid Build Coastguard Worker * leniency, this will be set to an error status.
505*0e209d39SAndroid Build Coastguard Worker * @return True if the current time of this Calendar is before the time of
506*0e209d39SAndroid Build Coastguard Worker * Calendar when; false otherwise.
507*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
508*0e209d39SAndroid Build Coastguard Worker */
509*0e209d39SAndroid Build Coastguard Worker UBool before(const Calendar& when, UErrorCode& status) const;
510*0e209d39SAndroid Build Coastguard Worker
511*0e209d39SAndroid Build Coastguard Worker /**
512*0e209d39SAndroid Build Coastguard Worker * Returns true if this Calendar's current time is after "when"'s current time.
513*0e209d39SAndroid Build Coastguard Worker *
514*0e209d39SAndroid Build Coastguard Worker * @param when The Calendar to be compared with this Calendar. Although this is a
515*0e209d39SAndroid Build Coastguard Worker * const parameter, the object may be modified physically
516*0e209d39SAndroid Build Coastguard Worker * (semantically const).
517*0e209d39SAndroid Build Coastguard Worker * @param status Output param set to success/failure code on exit. If any value
518*0e209d39SAndroid Build Coastguard Worker * previously set in the time field is invalid or restricted by
519*0e209d39SAndroid Build Coastguard Worker * leniency, this will be set to an error status.
520*0e209d39SAndroid Build Coastguard Worker * @return True if the current time of this Calendar is after the time of
521*0e209d39SAndroid Build Coastguard Worker * Calendar when; false otherwise.
522*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
523*0e209d39SAndroid Build Coastguard Worker */
524*0e209d39SAndroid Build Coastguard Worker UBool after(const Calendar& when, UErrorCode& status) const;
525*0e209d39SAndroid Build Coastguard Worker
526*0e209d39SAndroid Build Coastguard Worker #ifndef U_FORCE_HIDE_DEPRECATED_API
527*0e209d39SAndroid Build Coastguard Worker /**
528*0e209d39SAndroid Build Coastguard Worker * UDate Arithmetic function. Adds the specified (signed) amount of time to the given
529*0e209d39SAndroid Build Coastguard Worker * time field, based on the calendar's rules. For example, to subtract 5 days from
530*0e209d39SAndroid Build Coastguard Worker * the current time of the calendar, call add(Calendar::DATE, -5). When adding on
531*0e209d39SAndroid Build Coastguard Worker * the month or Calendar::MONTH field, other fields like date might conflict and
532*0e209d39SAndroid Build Coastguard Worker * need to be changed. For instance, adding 1 month on the date 01/31/96 will result
533*0e209d39SAndroid Build Coastguard Worker * in 02/29/96.
534*0e209d39SAndroid Build Coastguard Worker * Adding a positive value always means moving forward in time, so for the Gregorian calendar,
535*0e209d39SAndroid Build Coastguard Worker * starting with 100 BC and adding +1 to year results in 99 BC (even though this actually reduces
536*0e209d39SAndroid Build Coastguard Worker * the numeric value of the field itself).
537*0e209d39SAndroid Build Coastguard Worker *
538*0e209d39SAndroid Build Coastguard Worker * @param field Specifies which date field to modify.
539*0e209d39SAndroid Build Coastguard Worker * @param amount The amount of time to be added to the field, in the natural unit
540*0e209d39SAndroid Build Coastguard Worker * for that field (e.g., days for the day fields, hours for the hour
541*0e209d39SAndroid Build Coastguard Worker * field.)
542*0e209d39SAndroid Build Coastguard Worker * @param status Output param set to success/failure code on exit. If any value
543*0e209d39SAndroid Build Coastguard Worker * previously set in the time field is invalid or restricted by
544*0e209d39SAndroid Build Coastguard Worker * leniency, this will be set to an error status.
545*0e209d39SAndroid Build Coastguard Worker * @deprecated ICU 2.6. use add(UCalendarDateFields field, int32_t amount, UErrorCode& status) instead.
546*0e209d39SAndroid Build Coastguard Worker */
547*0e209d39SAndroid Build Coastguard Worker virtual void add(EDateFields field, int32_t amount, UErrorCode& status);
548*0e209d39SAndroid Build Coastguard Worker #endif // U_FORCE_HIDE_DEPRECATED_API
549*0e209d39SAndroid Build Coastguard Worker
550*0e209d39SAndroid Build Coastguard Worker /**
551*0e209d39SAndroid Build Coastguard Worker * UDate Arithmetic function. Adds the specified (signed) amount of time to the given
552*0e209d39SAndroid Build Coastguard Worker * time field, based on the calendar's rules. For example, to subtract 5 days from
553*0e209d39SAndroid Build Coastguard Worker * the current time of the calendar, call add(Calendar::DATE, -5). When adding on
554*0e209d39SAndroid Build Coastguard Worker * the month or Calendar::MONTH field, other fields like date might conflict and
555*0e209d39SAndroid Build Coastguard Worker * need to be changed. For instance, adding 1 month on the date 01/31/96 will result
556*0e209d39SAndroid Build Coastguard Worker * in 02/29/96.
557*0e209d39SAndroid Build Coastguard Worker * Adding a positive value always means moving forward in time, so for the Gregorian calendar,
558*0e209d39SAndroid Build Coastguard Worker * starting with 100 BC and adding +1 to year results in 99 BC (even though this actually reduces
559*0e209d39SAndroid Build Coastguard Worker * the numeric value of the field itself).
560*0e209d39SAndroid Build Coastguard Worker *
561*0e209d39SAndroid Build Coastguard Worker * @param field Specifies which date field to modify.
562*0e209d39SAndroid Build Coastguard Worker * @param amount The amount of time to be added to the field, in the natural unit
563*0e209d39SAndroid Build Coastguard Worker * for that field (e.g., days for the day fields, hours for the hour
564*0e209d39SAndroid Build Coastguard Worker * field.)
565*0e209d39SAndroid Build Coastguard Worker * @param status Output param set to success/failure code on exit. If any value
566*0e209d39SAndroid Build Coastguard Worker * previously set in the time field is invalid or restricted by
567*0e209d39SAndroid Build Coastguard Worker * leniency, this will be set to an error status.
568*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.6.
569*0e209d39SAndroid Build Coastguard Worker */
570*0e209d39SAndroid Build Coastguard Worker virtual void add(UCalendarDateFields field, int32_t amount, UErrorCode& status);
571*0e209d39SAndroid Build Coastguard Worker
572*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_DEPRECATED_API
573*0e209d39SAndroid Build Coastguard Worker /**
574*0e209d39SAndroid Build Coastguard Worker * Time Field Rolling function. Rolls (up/down) a single unit of time on the given
575*0e209d39SAndroid Build Coastguard Worker * time field. For example, to roll the current date up by one day, call
576*0e209d39SAndroid Build Coastguard Worker * roll(Calendar::DATE, true). When rolling on the year or Calendar::YEAR field, it
577*0e209d39SAndroid Build Coastguard Worker * will roll the year value in the range between getMinimum(Calendar::YEAR) and the
578*0e209d39SAndroid Build Coastguard Worker * value returned by getMaximum(Calendar::YEAR). When rolling on the month or
579*0e209d39SAndroid Build Coastguard Worker * Calendar::MONTH field, other fields like date might conflict and, need to be
580*0e209d39SAndroid Build Coastguard Worker * changed. For instance, rolling the month up on the date 01/31/96 will result in
581*0e209d39SAndroid Build Coastguard Worker * 02/29/96. Rolling up always means rolling forward in time (unless the limit of the
582*0e209d39SAndroid Build Coastguard Worker * field is reached, in which case it may pin or wrap), so for Gregorian calendar,
583*0e209d39SAndroid Build Coastguard Worker * starting with 100 BC and rolling the year up results in 99 BC.
584*0e209d39SAndroid Build Coastguard Worker * When eras have a definite beginning and end (as in the Chinese calendar, or as in
585*0e209d39SAndroid Build Coastguard Worker * most eras in the Japanese calendar) then rolling the year past either limit of the
586*0e209d39SAndroid Build Coastguard Worker * era will cause the year to wrap around. When eras only have a limit at one end,
587*0e209d39SAndroid Build Coastguard Worker * then attempting to roll the year past that limit will result in pinning the year
588*0e209d39SAndroid Build Coastguard Worker * at that limit. Note that for most calendars in which era 0 years move forward in
589*0e209d39SAndroid Build Coastguard Worker * time (such as Buddhist, Hebrew, or Islamic), it is possible for add or roll to
590*0e209d39SAndroid Build Coastguard Worker * result in negative years for era 0 (that is the only way to represent years before
591*0e209d39SAndroid Build Coastguard Worker * the calendar epoch).
592*0e209d39SAndroid Build Coastguard Worker * When rolling on the hour-in-day or Calendar::HOUR_OF_DAY field, it will roll the
593*0e209d39SAndroid Build Coastguard Worker * hour value in the range between 0 and 23, which is zero-based.
594*0e209d39SAndroid Build Coastguard Worker * <P>
595*0e209d39SAndroid Build Coastguard Worker * NOTE: Do not use this method -- use roll(EDateFields, int, UErrorCode&) instead.
596*0e209d39SAndroid Build Coastguard Worker *
597*0e209d39SAndroid Build Coastguard Worker * @param field The time field.
598*0e209d39SAndroid Build Coastguard Worker * @param up Indicates if the value of the specified time field is to be rolled
599*0e209d39SAndroid Build Coastguard Worker * up or rolled down. Use true if rolling up, false otherwise.
600*0e209d39SAndroid Build Coastguard Worker * @param status Output param set to success/failure code on exit. If any value
601*0e209d39SAndroid Build Coastguard Worker * previously set in the time field is invalid or restricted by
602*0e209d39SAndroid Build Coastguard Worker * leniency, this will be set to an error status.
603*0e209d39SAndroid Build Coastguard Worker * @deprecated ICU 2.6. Use roll(UCalendarDateFields field, UBool up, UErrorCode& status) instead.
604*0e209d39SAndroid Build Coastguard Worker */
605*0e209d39SAndroid Build Coastguard Worker inline void roll(EDateFields field, UBool up, UErrorCode& status);
606*0e209d39SAndroid Build Coastguard Worker #endif /* U_HIDE_DEPRECATED_API */
607*0e209d39SAndroid Build Coastguard Worker
608*0e209d39SAndroid Build Coastguard Worker /**
609*0e209d39SAndroid Build Coastguard Worker * Time Field Rolling function. Rolls (up/down) a single unit of time on the given
610*0e209d39SAndroid Build Coastguard Worker * time field. For example, to roll the current date up by one day, call
611*0e209d39SAndroid Build Coastguard Worker * roll(Calendar::DATE, true). When rolling on the year or Calendar::YEAR field, it
612*0e209d39SAndroid Build Coastguard Worker * will roll the year value in the range between getMinimum(Calendar::YEAR) and the
613*0e209d39SAndroid Build Coastguard Worker * value returned by getMaximum(Calendar::YEAR). When rolling on the month or
614*0e209d39SAndroid Build Coastguard Worker * Calendar::MONTH field, other fields like date might conflict and, need to be
615*0e209d39SAndroid Build Coastguard Worker * changed. For instance, rolling the month up on the date 01/31/96 will result in
616*0e209d39SAndroid Build Coastguard Worker * 02/29/96. Rolling up always means rolling forward in time (unless the limit of the
617*0e209d39SAndroid Build Coastguard Worker * field is reached, in which case it may pin or wrap), so for Gregorian calendar,
618*0e209d39SAndroid Build Coastguard Worker * starting with 100 BC and rolling the year up results in 99 BC.
619*0e209d39SAndroid Build Coastguard Worker * When eras have a definite beginning and end (as in the Chinese calendar, or as in
620*0e209d39SAndroid Build Coastguard Worker * most eras in the Japanese calendar) then rolling the year past either limit of the
621*0e209d39SAndroid Build Coastguard Worker * era will cause the year to wrap around. When eras only have a limit at one end,
622*0e209d39SAndroid Build Coastguard Worker * then attempting to roll the year past that limit will result in pinning the year
623*0e209d39SAndroid Build Coastguard Worker * at that limit. Note that for most calendars in which era 0 years move forward in
624*0e209d39SAndroid Build Coastguard Worker * time (such as Buddhist, Hebrew, or Islamic), it is possible for add or roll to
625*0e209d39SAndroid Build Coastguard Worker * result in negative years for era 0 (that is the only way to represent years before
626*0e209d39SAndroid Build Coastguard Worker * the calendar epoch).
627*0e209d39SAndroid Build Coastguard Worker * When rolling on the hour-in-day or Calendar::HOUR_OF_DAY field, it will roll the
628*0e209d39SAndroid Build Coastguard Worker * hour value in the range between 0 and 23, which is zero-based.
629*0e209d39SAndroid Build Coastguard Worker * <P>
630*0e209d39SAndroid Build Coastguard Worker * NOTE: Do not use this method -- use roll(UCalendarDateFields, int, UErrorCode&) instead.
631*0e209d39SAndroid Build Coastguard Worker *
632*0e209d39SAndroid Build Coastguard Worker * @param field The time field.
633*0e209d39SAndroid Build Coastguard Worker * @param up Indicates if the value of the specified time field is to be rolled
634*0e209d39SAndroid Build Coastguard Worker * up or rolled down. Use true if rolling up, false otherwise.
635*0e209d39SAndroid Build Coastguard Worker * @param status Output param set to success/failure code on exit. If any value
636*0e209d39SAndroid Build Coastguard Worker * previously set in the time field is invalid or restricted by
637*0e209d39SAndroid Build Coastguard Worker * leniency, this will be set to an error status.
638*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.6.
639*0e209d39SAndroid Build Coastguard Worker */
640*0e209d39SAndroid Build Coastguard Worker inline void roll(UCalendarDateFields field, UBool up, UErrorCode& status);
641*0e209d39SAndroid Build Coastguard Worker
642*0e209d39SAndroid Build Coastguard Worker #ifndef U_FORCE_HIDE_DEPRECATED_API
643*0e209d39SAndroid Build Coastguard Worker /**
644*0e209d39SAndroid Build Coastguard Worker * Time Field Rolling function. Rolls by the given amount on the given
645*0e209d39SAndroid Build Coastguard Worker * time field. For example, to roll the current date up by one day, call
646*0e209d39SAndroid Build Coastguard Worker * roll(Calendar::DATE, +1, status). When rolling on the month or
647*0e209d39SAndroid Build Coastguard Worker * Calendar::MONTH field, other fields like date might conflict and, need to be
648*0e209d39SAndroid Build Coastguard Worker * changed. For instance, rolling the month up on the date 01/31/96 will result in
649*0e209d39SAndroid Build Coastguard Worker * 02/29/96. Rolling by a positive value always means rolling forward in time (unless
650*0e209d39SAndroid Build Coastguard Worker * the limit of the field is reached, in which case it may pin or wrap), so for
651*0e209d39SAndroid Build Coastguard Worker * Gregorian calendar, starting with 100 BC and rolling the year by + 1 results in 99 BC.
652*0e209d39SAndroid Build Coastguard Worker * When eras have a definite beginning and end (as in the Chinese calendar, or as in
653*0e209d39SAndroid Build Coastguard Worker * most eras in the Japanese calendar) then rolling the year past either limit of the
654*0e209d39SAndroid Build Coastguard Worker * era will cause the year to wrap around. When eras only have a limit at one end,
655*0e209d39SAndroid Build Coastguard Worker * then attempting to roll the year past that limit will result in pinning the year
656*0e209d39SAndroid Build Coastguard Worker * at that limit. Note that for most calendars in which era 0 years move forward in
657*0e209d39SAndroid Build Coastguard Worker * time (such as Buddhist, Hebrew, or Islamic), it is possible for add or roll to
658*0e209d39SAndroid Build Coastguard Worker * result in negative years for era 0 (that is the only way to represent years before
659*0e209d39SAndroid Build Coastguard Worker * the calendar epoch).
660*0e209d39SAndroid Build Coastguard Worker * When rolling on the hour-in-day or Calendar::HOUR_OF_DAY field, it will roll the
661*0e209d39SAndroid Build Coastguard Worker * hour value in the range between 0 and 23, which is zero-based.
662*0e209d39SAndroid Build Coastguard Worker * <P>
663*0e209d39SAndroid Build Coastguard Worker * The only difference between roll() and add() is that roll() does not change
664*0e209d39SAndroid Build Coastguard Worker * the value of more significant fields when it reaches the minimum or maximum
665*0e209d39SAndroid Build Coastguard Worker * of its range, whereas add() does.
666*0e209d39SAndroid Build Coastguard Worker *
667*0e209d39SAndroid Build Coastguard Worker * @param field The time field.
668*0e209d39SAndroid Build Coastguard Worker * @param amount Indicates amount to roll.
669*0e209d39SAndroid Build Coastguard Worker * @param status Output param set to success/failure code on exit. If any value
670*0e209d39SAndroid Build Coastguard Worker * previously set in the time field is invalid, this will be set to
671*0e209d39SAndroid Build Coastguard Worker * an error status.
672*0e209d39SAndroid Build Coastguard Worker * @deprecated ICU 2.6. Use roll(UCalendarDateFields field, int32_t amount, UErrorCode& status) instead.
673*0e209d39SAndroid Build Coastguard Worker */
674*0e209d39SAndroid Build Coastguard Worker virtual void roll(EDateFields field, int32_t amount, UErrorCode& status);
675*0e209d39SAndroid Build Coastguard Worker #endif // U_FORCE_HIDE_DEPRECATED_API
676*0e209d39SAndroid Build Coastguard Worker
677*0e209d39SAndroid Build Coastguard Worker /**
678*0e209d39SAndroid Build Coastguard Worker * Time Field Rolling function. Rolls by the given amount on the given
679*0e209d39SAndroid Build Coastguard Worker * time field. For example, to roll the current date up by one day, call
680*0e209d39SAndroid Build Coastguard Worker * roll(Calendar::DATE, +1, status). When rolling on the month or
681*0e209d39SAndroid Build Coastguard Worker * Calendar::MONTH field, other fields like date might conflict and, need to be
682*0e209d39SAndroid Build Coastguard Worker * changed. For instance, rolling the month up on the date 01/31/96 will result in
683*0e209d39SAndroid Build Coastguard Worker * 02/29/96. Rolling by a positive value always means rolling forward in time (unless
684*0e209d39SAndroid Build Coastguard Worker * the limit of the field is reached, in which case it may pin or wrap), so for
685*0e209d39SAndroid Build Coastguard Worker * Gregorian calendar, starting with 100 BC and rolling the year by + 1 results in 99 BC.
686*0e209d39SAndroid Build Coastguard Worker * When eras have a definite beginning and end (as in the Chinese calendar, or as in
687*0e209d39SAndroid Build Coastguard Worker * most eras in the Japanese calendar) then rolling the year past either limit of the
688*0e209d39SAndroid Build Coastguard Worker * era will cause the year to wrap around. When eras only have a limit at one end,
689*0e209d39SAndroid Build Coastguard Worker * then attempting to roll the year past that limit will result in pinning the year
690*0e209d39SAndroid Build Coastguard Worker * at that limit. Note that for most calendars in which era 0 years move forward in
691*0e209d39SAndroid Build Coastguard Worker * time (such as Buddhist, Hebrew, or Islamic), it is possible for add or roll to
692*0e209d39SAndroid Build Coastguard Worker * result in negative years for era 0 (that is the only way to represent years before
693*0e209d39SAndroid Build Coastguard Worker * the calendar epoch).
694*0e209d39SAndroid Build Coastguard Worker * When rolling on the hour-in-day or Calendar::HOUR_OF_DAY field, it will roll the
695*0e209d39SAndroid Build Coastguard Worker * hour value in the range between 0 and 23, which is zero-based.
696*0e209d39SAndroid Build Coastguard Worker * <P>
697*0e209d39SAndroid Build Coastguard Worker * The only difference between roll() and add() is that roll() does not change
698*0e209d39SAndroid Build Coastguard Worker * the value of more significant fields when it reaches the minimum or maximum
699*0e209d39SAndroid Build Coastguard Worker * of its range, whereas add() does.
700*0e209d39SAndroid Build Coastguard Worker *
701*0e209d39SAndroid Build Coastguard Worker * @param field The time field.
702*0e209d39SAndroid Build Coastguard Worker * @param amount Indicates amount to roll.
703*0e209d39SAndroid Build Coastguard Worker * @param status Output param set to success/failure code on exit. If any value
704*0e209d39SAndroid Build Coastguard Worker * previously set in the time field is invalid, this will be set to
705*0e209d39SAndroid Build Coastguard Worker * an error status.
706*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.6.
707*0e209d39SAndroid Build Coastguard Worker */
708*0e209d39SAndroid Build Coastguard Worker virtual void roll(UCalendarDateFields field, int32_t amount, UErrorCode& status);
709*0e209d39SAndroid Build Coastguard Worker
710*0e209d39SAndroid Build Coastguard Worker #ifndef U_FORCE_HIDE_DEPRECATED_API
711*0e209d39SAndroid Build Coastguard Worker /**
712*0e209d39SAndroid Build Coastguard Worker * Return the difference between the given time and the time this
713*0e209d39SAndroid Build Coastguard Worker * calendar object is set to. If this calendar is set
714*0e209d39SAndroid Build Coastguard Worker * <em>before</em> the given time, the returned value will be
715*0e209d39SAndroid Build Coastguard Worker * positive. If this calendar is set <em>after</em> the given
716*0e209d39SAndroid Build Coastguard Worker * time, the returned value will be negative. The
717*0e209d39SAndroid Build Coastguard Worker * <code>field</code> parameter specifies the units of the return
718*0e209d39SAndroid Build Coastguard Worker * value. For example, if <code>fieldDifference(when,
719*0e209d39SAndroid Build Coastguard Worker * Calendar::MONTH)</code> returns 3, then this calendar is set to
720*0e209d39SAndroid Build Coastguard Worker * 3 months before <code>when</code>, and possibly some addition
721*0e209d39SAndroid Build Coastguard Worker * time less than one month.
722*0e209d39SAndroid Build Coastguard Worker *
723*0e209d39SAndroid Build Coastguard Worker * <p>As a side effect of this call, this calendar is advanced
724*0e209d39SAndroid Build Coastguard Worker * toward <code>when</code> by the given amount. That is, calling
725*0e209d39SAndroid Build Coastguard Worker * this method has the side effect of calling <code>add(field,
726*0e209d39SAndroid Build Coastguard Worker * n)</code>, where <code>n</code> is the return value.
727*0e209d39SAndroid Build Coastguard Worker *
728*0e209d39SAndroid Build Coastguard Worker * <p>Usage: To use this method, call it first with the largest
729*0e209d39SAndroid Build Coastguard Worker * field of interest, then with progressively smaller fields. For
730*0e209d39SAndroid Build Coastguard Worker * example:
731*0e209d39SAndroid Build Coastguard Worker *
732*0e209d39SAndroid Build Coastguard Worker * <pre>
733*0e209d39SAndroid Build Coastguard Worker * int y = cal->fieldDifference(when, Calendar::YEAR, err);
734*0e209d39SAndroid Build Coastguard Worker * int m = cal->fieldDifference(when, Calendar::MONTH, err);
735*0e209d39SAndroid Build Coastguard Worker * int d = cal->fieldDifference(when, Calendar::DATE, err);</pre>
736*0e209d39SAndroid Build Coastguard Worker *
737*0e209d39SAndroid Build Coastguard Worker * computes the difference between <code>cal</code> and
738*0e209d39SAndroid Build Coastguard Worker * <code>when</code> in years, months, and days.
739*0e209d39SAndroid Build Coastguard Worker *
740*0e209d39SAndroid Build Coastguard Worker * <p>Note: <code>fieldDifference()</code> is
741*0e209d39SAndroid Build Coastguard Worker * <em>asymmetrical</em>. That is, in the following code:
742*0e209d39SAndroid Build Coastguard Worker *
743*0e209d39SAndroid Build Coastguard Worker * <pre>
744*0e209d39SAndroid Build Coastguard Worker * cal->setTime(date1, err);
745*0e209d39SAndroid Build Coastguard Worker * int m1 = cal->fieldDifference(date2, Calendar::MONTH, err);
746*0e209d39SAndroid Build Coastguard Worker * int d1 = cal->fieldDifference(date2, Calendar::DATE, err);
747*0e209d39SAndroid Build Coastguard Worker * cal->setTime(date2, err);
748*0e209d39SAndroid Build Coastguard Worker * int m2 = cal->fieldDifference(date1, Calendar::MONTH, err);
749*0e209d39SAndroid Build Coastguard Worker * int d2 = cal->fieldDifference(date1, Calendar::DATE, err);</pre>
750*0e209d39SAndroid Build Coastguard Worker *
751*0e209d39SAndroid Build Coastguard Worker * one might expect that <code>m1 == -m2 && d1 == -d2</code>.
752*0e209d39SAndroid Build Coastguard Worker * However, this is not generally the case, because of
753*0e209d39SAndroid Build Coastguard Worker * irregularities in the underlying calendar system (e.g., the
754*0e209d39SAndroid Build Coastguard Worker * Gregorian calendar has a varying number of days per month).
755*0e209d39SAndroid Build Coastguard Worker *
756*0e209d39SAndroid Build Coastguard Worker * @param when the date to compare this calendar's time to
757*0e209d39SAndroid Build Coastguard Worker * @param field the field in which to compute the result
758*0e209d39SAndroid Build Coastguard Worker * @param status Output param set to success/failure code on exit. If any value
759*0e209d39SAndroid Build Coastguard Worker * previously set in the time field is invalid, this will be set to
760*0e209d39SAndroid Build Coastguard Worker * an error status.
761*0e209d39SAndroid Build Coastguard Worker * @return the difference, either positive or negative, between
762*0e209d39SAndroid Build Coastguard Worker * this calendar's time and <code>when</code>, in terms of
763*0e209d39SAndroid Build Coastguard Worker * <code>field</code>.
764*0e209d39SAndroid Build Coastguard Worker * @deprecated ICU 2.6. Use fieldDifference(UDate when, UCalendarDateFields field, UErrorCode& status).
765*0e209d39SAndroid Build Coastguard Worker */
766*0e209d39SAndroid Build Coastguard Worker virtual int32_t fieldDifference(UDate when, EDateFields field, UErrorCode& status);
767*0e209d39SAndroid Build Coastguard Worker #endif // U_FORCE_HIDE_DEPRECATED_API
768*0e209d39SAndroid Build Coastguard Worker
769*0e209d39SAndroid Build Coastguard Worker /**
770*0e209d39SAndroid Build Coastguard Worker * Return the difference between the given time and the time this
771*0e209d39SAndroid Build Coastguard Worker * calendar object is set to. If this calendar is set
772*0e209d39SAndroid Build Coastguard Worker * <em>before</em> the given time, the returned value will be
773*0e209d39SAndroid Build Coastguard Worker * positive. If this calendar is set <em>after</em> the given
774*0e209d39SAndroid Build Coastguard Worker * time, the returned value will be negative. The
775*0e209d39SAndroid Build Coastguard Worker * <code>field</code> parameter specifies the units of the return
776*0e209d39SAndroid Build Coastguard Worker * value. For example, if <code>fieldDifference(when,
777*0e209d39SAndroid Build Coastguard Worker * Calendar::MONTH)</code> returns 3, then this calendar is set to
778*0e209d39SAndroid Build Coastguard Worker * 3 months before <code>when</code>, and possibly some addition
779*0e209d39SAndroid Build Coastguard Worker * time less than one month.
780*0e209d39SAndroid Build Coastguard Worker *
781*0e209d39SAndroid Build Coastguard Worker * <p>As a side effect of this call, this calendar is advanced
782*0e209d39SAndroid Build Coastguard Worker * toward <code>when</code> by the given amount. That is, calling
783*0e209d39SAndroid Build Coastguard Worker * this method has the side effect of calling <code>add(field,
784*0e209d39SAndroid Build Coastguard Worker * n)</code>, where <code>n</code> is the return value.
785*0e209d39SAndroid Build Coastguard Worker *
786*0e209d39SAndroid Build Coastguard Worker * <p>Usage: To use this method, call it first with the largest
787*0e209d39SAndroid Build Coastguard Worker * field of interest, then with progressively smaller fields. For
788*0e209d39SAndroid Build Coastguard Worker * example:
789*0e209d39SAndroid Build Coastguard Worker *
790*0e209d39SAndroid Build Coastguard Worker * <pre>
791*0e209d39SAndroid Build Coastguard Worker * int y = cal->fieldDifference(when, Calendar::YEAR, err);
792*0e209d39SAndroid Build Coastguard Worker * int m = cal->fieldDifference(when, Calendar::MONTH, err);
793*0e209d39SAndroid Build Coastguard Worker * int d = cal->fieldDifference(when, Calendar::DATE, err);</pre>
794*0e209d39SAndroid Build Coastguard Worker *
795*0e209d39SAndroid Build Coastguard Worker * computes the difference between <code>cal</code> and
796*0e209d39SAndroid Build Coastguard Worker * <code>when</code> in years, months, and days.
797*0e209d39SAndroid Build Coastguard Worker *
798*0e209d39SAndroid Build Coastguard Worker * <p>Note: <code>fieldDifference()</code> is
799*0e209d39SAndroid Build Coastguard Worker * <em>asymmetrical</em>. That is, in the following code:
800*0e209d39SAndroid Build Coastguard Worker *
801*0e209d39SAndroid Build Coastguard Worker * <pre>
802*0e209d39SAndroid Build Coastguard Worker * cal->setTime(date1, err);
803*0e209d39SAndroid Build Coastguard Worker * int m1 = cal->fieldDifference(date2, Calendar::MONTH, err);
804*0e209d39SAndroid Build Coastguard Worker * int d1 = cal->fieldDifference(date2, Calendar::DATE, err);
805*0e209d39SAndroid Build Coastguard Worker * cal->setTime(date2, err);
806*0e209d39SAndroid Build Coastguard Worker * int m2 = cal->fieldDifference(date1, Calendar::MONTH, err);
807*0e209d39SAndroid Build Coastguard Worker * int d2 = cal->fieldDifference(date1, Calendar::DATE, err);</pre>
808*0e209d39SAndroid Build Coastguard Worker *
809*0e209d39SAndroid Build Coastguard Worker * one might expect that <code>m1 == -m2 && d1 == -d2</code>.
810*0e209d39SAndroid Build Coastguard Worker * However, this is not generally the case, because of
811*0e209d39SAndroid Build Coastguard Worker * irregularities in the underlying calendar system (e.g., the
812*0e209d39SAndroid Build Coastguard Worker * Gregorian calendar has a varying number of days per month).
813*0e209d39SAndroid Build Coastguard Worker *
814*0e209d39SAndroid Build Coastguard Worker * @param when the date to compare this calendar's time to
815*0e209d39SAndroid Build Coastguard Worker * @param field the field in which to compute the result
816*0e209d39SAndroid Build Coastguard Worker * @param status Output param set to success/failure code on exit. If any value
817*0e209d39SAndroid Build Coastguard Worker * previously set in the time field is invalid, this will be set to
818*0e209d39SAndroid Build Coastguard Worker * an error status.
819*0e209d39SAndroid Build Coastguard Worker * @return the difference, either positive or negative, between
820*0e209d39SAndroid Build Coastguard Worker * this calendar's time and <code>when</code>, in terms of
821*0e209d39SAndroid Build Coastguard Worker * <code>field</code>.
822*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.6.
823*0e209d39SAndroid Build Coastguard Worker */
824*0e209d39SAndroid Build Coastguard Worker virtual int32_t fieldDifference(UDate when, UCalendarDateFields field, UErrorCode& status);
825*0e209d39SAndroid Build Coastguard Worker
826*0e209d39SAndroid Build Coastguard Worker /**
827*0e209d39SAndroid Build Coastguard Worker * Sets the calendar's time zone to be the one passed in. The Calendar takes ownership
828*0e209d39SAndroid Build Coastguard Worker * of the TimeZone; the caller is no longer responsible for deleting it. If the
829*0e209d39SAndroid Build Coastguard Worker * given time zone is nullptr, this function has no effect.
830*0e209d39SAndroid Build Coastguard Worker *
831*0e209d39SAndroid Build Coastguard Worker * @param value The given time zone.
832*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
833*0e209d39SAndroid Build Coastguard Worker */
834*0e209d39SAndroid Build Coastguard Worker void adoptTimeZone(TimeZone* value);
835*0e209d39SAndroid Build Coastguard Worker
836*0e209d39SAndroid Build Coastguard Worker /**
837*0e209d39SAndroid Build Coastguard Worker * Sets the calendar's time zone to be the same as the one passed in. The TimeZone
838*0e209d39SAndroid Build Coastguard Worker * passed in is _not_ adopted; the client is still responsible for deleting it.
839*0e209d39SAndroid Build Coastguard Worker *
840*0e209d39SAndroid Build Coastguard Worker * @param zone The given time zone.
841*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
842*0e209d39SAndroid Build Coastguard Worker */
843*0e209d39SAndroid Build Coastguard Worker void setTimeZone(const TimeZone& zone);
844*0e209d39SAndroid Build Coastguard Worker
845*0e209d39SAndroid Build Coastguard Worker /**
846*0e209d39SAndroid Build Coastguard Worker * Returns a reference to the time zone owned by this calendar. The returned reference
847*0e209d39SAndroid Build Coastguard Worker * is only valid until clients make another call to adoptTimeZone or setTimeZone,
848*0e209d39SAndroid Build Coastguard Worker * or this Calendar is destroyed.
849*0e209d39SAndroid Build Coastguard Worker *
850*0e209d39SAndroid Build Coastguard Worker * @return The time zone object associated with this calendar.
851*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
852*0e209d39SAndroid Build Coastguard Worker */
853*0e209d39SAndroid Build Coastguard Worker const TimeZone& getTimeZone() const;
854*0e209d39SAndroid Build Coastguard Worker
855*0e209d39SAndroid Build Coastguard Worker /**
856*0e209d39SAndroid Build Coastguard Worker * Returns the time zone owned by this calendar. The caller owns the returned object
857*0e209d39SAndroid Build Coastguard Worker * and must delete it when done. After this call, the new time zone associated
858*0e209d39SAndroid Build Coastguard Worker * with this Calendar is the default TimeZone as returned by TimeZone::createDefault().
859*0e209d39SAndroid Build Coastguard Worker *
860*0e209d39SAndroid Build Coastguard Worker * @return The time zone object which was associated with this calendar.
861*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
862*0e209d39SAndroid Build Coastguard Worker */
863*0e209d39SAndroid Build Coastguard Worker TimeZone* orphanTimeZone();
864*0e209d39SAndroid Build Coastguard Worker
865*0e209d39SAndroid Build Coastguard Worker /**
866*0e209d39SAndroid Build Coastguard Worker * Queries if the current date for this Calendar is in Daylight Savings Time.
867*0e209d39SAndroid Build Coastguard Worker *
868*0e209d39SAndroid Build Coastguard Worker * @param status Fill-in parameter which receives the status of this operation.
869*0e209d39SAndroid Build Coastguard Worker * @return True if the current date for this Calendar is in Daylight Savings Time,
870*0e209d39SAndroid Build Coastguard Worker * false, otherwise.
871*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
872*0e209d39SAndroid Build Coastguard Worker */
873*0e209d39SAndroid Build Coastguard Worker virtual UBool inDaylightTime(UErrorCode& status) const;
874*0e209d39SAndroid Build Coastguard Worker
875*0e209d39SAndroid Build Coastguard Worker /**
876*0e209d39SAndroid Build Coastguard Worker * Specifies whether or not date/time interpretation is to be lenient. With lenient
877*0e209d39SAndroid Build Coastguard Worker * interpretation, a date such as "February 942, 1996" will be treated as being
878*0e209d39SAndroid Build Coastguard Worker * equivalent to the 941st day after February 1, 1996. With strict interpretation,
879*0e209d39SAndroid Build Coastguard Worker * such dates will cause an error when computing time from the time field values
880*0e209d39SAndroid Build Coastguard Worker * representing the dates.
881*0e209d39SAndroid Build Coastguard Worker *
882*0e209d39SAndroid Build Coastguard Worker * @param lenient True specifies date/time interpretation to be lenient.
883*0e209d39SAndroid Build Coastguard Worker *
884*0e209d39SAndroid Build Coastguard Worker * @see DateFormat#setLenient
885*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
886*0e209d39SAndroid Build Coastguard Worker */
887*0e209d39SAndroid Build Coastguard Worker void setLenient(UBool lenient);
888*0e209d39SAndroid Build Coastguard Worker
889*0e209d39SAndroid Build Coastguard Worker /**
890*0e209d39SAndroid Build Coastguard Worker * Tells whether date/time interpretation is to be lenient.
891*0e209d39SAndroid Build Coastguard Worker *
892*0e209d39SAndroid Build Coastguard Worker * @return True tells that date/time interpretation is to be lenient.
893*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
894*0e209d39SAndroid Build Coastguard Worker */
895*0e209d39SAndroid Build Coastguard Worker UBool isLenient() const;
896*0e209d39SAndroid Build Coastguard Worker
897*0e209d39SAndroid Build Coastguard Worker /**
898*0e209d39SAndroid Build Coastguard Worker * Sets the behavior for handling wall time repeating multiple times
899*0e209d39SAndroid Build Coastguard Worker * at negative time zone offset transitions. For example, 1:30 AM on
900*0e209d39SAndroid Build Coastguard Worker * November 6, 2011 in US Eastern time (America/New_York) occurs twice;
901*0e209d39SAndroid Build Coastguard Worker * 1:30 AM EDT, then 1:30 AM EST one hour later. When <code>UCAL_WALLTIME_FIRST</code>
902*0e209d39SAndroid Build Coastguard Worker * is used, the wall time 1:30AM in this example will be interpreted as 1:30 AM EDT
903*0e209d39SAndroid Build Coastguard Worker * (first occurrence). When <code>UCAL_WALLTIME_LAST</code> is used, it will be
904*0e209d39SAndroid Build Coastguard Worker * interpreted as 1:30 AM EST (last occurrence). The default value is
905*0e209d39SAndroid Build Coastguard Worker * <code>UCAL_WALLTIME_LAST</code>.
906*0e209d39SAndroid Build Coastguard Worker * <p>
907*0e209d39SAndroid Build Coastguard Worker * <b>Note:</b>When <code>UCAL_WALLTIME_NEXT_VALID</code> is not a valid
908*0e209d39SAndroid Build Coastguard Worker * option for this. When the argument is neither <code>UCAL_WALLTIME_FIRST</code>
909*0e209d39SAndroid Build Coastguard Worker * nor <code>UCAL_WALLTIME_LAST</code>, this method has no effect and will keep
910*0e209d39SAndroid Build Coastguard Worker * the current setting.
911*0e209d39SAndroid Build Coastguard Worker *
912*0e209d39SAndroid Build Coastguard Worker * @param option the behavior for handling repeating wall time, either
913*0e209d39SAndroid Build Coastguard Worker * <code>UCAL_WALLTIME_FIRST</code> or <code>UCAL_WALLTIME_LAST</code>.
914*0e209d39SAndroid Build Coastguard Worker * @see #getRepeatedWallTimeOption
915*0e209d39SAndroid Build Coastguard Worker * @stable ICU 49
916*0e209d39SAndroid Build Coastguard Worker */
917*0e209d39SAndroid Build Coastguard Worker void setRepeatedWallTimeOption(UCalendarWallTimeOption option);
918*0e209d39SAndroid Build Coastguard Worker
919*0e209d39SAndroid Build Coastguard Worker /**
920*0e209d39SAndroid Build Coastguard Worker * Gets the behavior for handling wall time repeating multiple times
921*0e209d39SAndroid Build Coastguard Worker * at negative time zone offset transitions.
922*0e209d39SAndroid Build Coastguard Worker *
923*0e209d39SAndroid Build Coastguard Worker * @return the behavior for handling repeating wall time, either
924*0e209d39SAndroid Build Coastguard Worker * <code>UCAL_WALLTIME_FIRST</code> or <code>UCAL_WALLTIME_LAST</code>.
925*0e209d39SAndroid Build Coastguard Worker * @see #setRepeatedWallTimeOption
926*0e209d39SAndroid Build Coastguard Worker * @stable ICU 49
927*0e209d39SAndroid Build Coastguard Worker */
928*0e209d39SAndroid Build Coastguard Worker UCalendarWallTimeOption getRepeatedWallTimeOption() const;
929*0e209d39SAndroid Build Coastguard Worker
930*0e209d39SAndroid Build Coastguard Worker /**
931*0e209d39SAndroid Build Coastguard Worker * Sets the behavior for handling skipped wall time at positive time zone offset
932*0e209d39SAndroid Build Coastguard Worker * transitions. For example, 2:30 AM on March 13, 2011 in US Eastern time (America/New_York)
933*0e209d39SAndroid Build Coastguard Worker * does not exist because the wall time jump from 1:59 AM EST to 3:00 AM EDT. When
934*0e209d39SAndroid Build Coastguard Worker * <code>UCAL_WALLTIME_FIRST</code> is used, 2:30 AM is interpreted as 30 minutes before 3:00 AM
935*0e209d39SAndroid Build Coastguard Worker * EDT, therefore, it will be resolved as 1:30 AM EST. When <code>UCAL_WALLTIME_LAST</code>
936*0e209d39SAndroid Build Coastguard Worker * is used, 2:30 AM is interpreted as 31 minutes after 1:59 AM EST, therefore, it will be
937*0e209d39SAndroid Build Coastguard Worker * resolved as 3:30 AM EDT. When <code>UCAL_WALLTIME_NEXT_VALID</code> is used, 2:30 AM will
938*0e209d39SAndroid Build Coastguard Worker * be resolved as next valid wall time, that is 3:00 AM EDT. The default value is
939*0e209d39SAndroid Build Coastguard Worker * <code>UCAL_WALLTIME_LAST</code>.
940*0e209d39SAndroid Build Coastguard Worker * <p>
941*0e209d39SAndroid Build Coastguard Worker * <b>Note:</b>This option is effective only when this calendar is lenient.
942*0e209d39SAndroid Build Coastguard Worker * When the calendar is strict, such non-existing wall time will cause an error.
943*0e209d39SAndroid Build Coastguard Worker *
944*0e209d39SAndroid Build Coastguard Worker * @param option the behavior for handling skipped wall time at positive time zone
945*0e209d39SAndroid Build Coastguard Worker * offset transitions, one of <code>UCAL_WALLTIME_FIRST</code>, <code>UCAL_WALLTIME_LAST</code> and
946*0e209d39SAndroid Build Coastguard Worker * <code>UCAL_WALLTIME_NEXT_VALID</code>.
947*0e209d39SAndroid Build Coastguard Worker * @see #getSkippedWallTimeOption
948*0e209d39SAndroid Build Coastguard Worker *
949*0e209d39SAndroid Build Coastguard Worker * @stable ICU 49
950*0e209d39SAndroid Build Coastguard Worker */
951*0e209d39SAndroid Build Coastguard Worker void setSkippedWallTimeOption(UCalendarWallTimeOption option);
952*0e209d39SAndroid Build Coastguard Worker
953*0e209d39SAndroid Build Coastguard Worker /**
954*0e209d39SAndroid Build Coastguard Worker * Gets the behavior for handling skipped wall time at positive time zone offset
955*0e209d39SAndroid Build Coastguard Worker * transitions.
956*0e209d39SAndroid Build Coastguard Worker *
957*0e209d39SAndroid Build Coastguard Worker * @return the behavior for handling skipped wall time, one of
958*0e209d39SAndroid Build Coastguard Worker * <code>UCAL_WALLTIME_FIRST</code>, <code>UCAL_WALLTIME_LAST</code>
959*0e209d39SAndroid Build Coastguard Worker * and <code>UCAL_WALLTIME_NEXT_VALID</code>.
960*0e209d39SAndroid Build Coastguard Worker * @see #setSkippedWallTimeOption
961*0e209d39SAndroid Build Coastguard Worker * @stable ICU 49
962*0e209d39SAndroid Build Coastguard Worker */
963*0e209d39SAndroid Build Coastguard Worker UCalendarWallTimeOption getSkippedWallTimeOption() const;
964*0e209d39SAndroid Build Coastguard Worker
965*0e209d39SAndroid Build Coastguard Worker /**
966*0e209d39SAndroid Build Coastguard Worker * Sets what the first day of the week is; e.g., Sunday in US, Monday in France.
967*0e209d39SAndroid Build Coastguard Worker *
968*0e209d39SAndroid Build Coastguard Worker * @param value The given first day of the week.
969*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.6.
970*0e209d39SAndroid Build Coastguard Worker */
971*0e209d39SAndroid Build Coastguard Worker void setFirstDayOfWeek(UCalendarDaysOfWeek value);
972*0e209d39SAndroid Build Coastguard Worker
973*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_DEPRECATED_API
974*0e209d39SAndroid Build Coastguard Worker /**
975*0e209d39SAndroid Build Coastguard Worker * Gets what the first day of the week is; e.g., Sunday in US, Monday in France.
976*0e209d39SAndroid Build Coastguard Worker *
977*0e209d39SAndroid Build Coastguard Worker * @return The first day of the week.
978*0e209d39SAndroid Build Coastguard Worker * @deprecated ICU 2.6 use the overload with error code
979*0e209d39SAndroid Build Coastguard Worker */
980*0e209d39SAndroid Build Coastguard Worker EDaysOfWeek getFirstDayOfWeek() const;
981*0e209d39SAndroid Build Coastguard Worker #endif /* U_HIDE_DEPRECATED_API */
982*0e209d39SAndroid Build Coastguard Worker
983*0e209d39SAndroid Build Coastguard Worker /**
984*0e209d39SAndroid Build Coastguard Worker * Gets what the first day of the week is; e.g., Sunday in US, Monday in France.
985*0e209d39SAndroid Build Coastguard Worker *
986*0e209d39SAndroid Build Coastguard Worker * @param status error code
987*0e209d39SAndroid Build Coastguard Worker * @return The first day of the week.
988*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.6
989*0e209d39SAndroid Build Coastguard Worker */
990*0e209d39SAndroid Build Coastguard Worker UCalendarDaysOfWeek getFirstDayOfWeek(UErrorCode &status) const;
991*0e209d39SAndroid Build Coastguard Worker
992*0e209d39SAndroid Build Coastguard Worker /**
993*0e209d39SAndroid Build Coastguard Worker * Sets what the minimal days required in the first week of the year are; For
994*0e209d39SAndroid Build Coastguard Worker * example, if the first week is defined as one that contains the first day of the
995*0e209d39SAndroid Build Coastguard Worker * first month of a year, call the method with value 1. If it must be a full week,
996*0e209d39SAndroid Build Coastguard Worker * use value 7.
997*0e209d39SAndroid Build Coastguard Worker *
998*0e209d39SAndroid Build Coastguard Worker * @param value The given minimal days required in the first week of the year.
999*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1000*0e209d39SAndroid Build Coastguard Worker */
1001*0e209d39SAndroid Build Coastguard Worker void setMinimalDaysInFirstWeek(uint8_t value);
1002*0e209d39SAndroid Build Coastguard Worker
1003*0e209d39SAndroid Build Coastguard Worker /**
1004*0e209d39SAndroid Build Coastguard Worker * Gets what the minimal days required in the first week of the year are; e.g., if
1005*0e209d39SAndroid Build Coastguard Worker * the first week is defined as one that contains the first day of the first month
1006*0e209d39SAndroid Build Coastguard Worker * of a year, getMinimalDaysInFirstWeek returns 1. If the minimal days required must
1007*0e209d39SAndroid Build Coastguard Worker * be a full week, getMinimalDaysInFirstWeek returns 7.
1008*0e209d39SAndroid Build Coastguard Worker *
1009*0e209d39SAndroid Build Coastguard Worker * @return The minimal days required in the first week of the year.
1010*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1011*0e209d39SAndroid Build Coastguard Worker */
1012*0e209d39SAndroid Build Coastguard Worker uint8_t getMinimalDaysInFirstWeek() const;
1013*0e209d39SAndroid Build Coastguard Worker
1014*0e209d39SAndroid Build Coastguard Worker #ifndef U_FORCE_HIDE_DEPRECATED_API
1015*0e209d39SAndroid Build Coastguard Worker /**
1016*0e209d39SAndroid Build Coastguard Worker * Gets the minimum value for the given time field. e.g., for Gregorian
1017*0e209d39SAndroid Build Coastguard Worker * DAY_OF_MONTH, 1.
1018*0e209d39SAndroid Build Coastguard Worker *
1019*0e209d39SAndroid Build Coastguard Worker * @param field The given time field.
1020*0e209d39SAndroid Build Coastguard Worker * @return The minimum value for the given time field.
1021*0e209d39SAndroid Build Coastguard Worker * @deprecated ICU 2.6. Use getMinimum(UCalendarDateFields field) instead.
1022*0e209d39SAndroid Build Coastguard Worker */
1023*0e209d39SAndroid Build Coastguard Worker virtual int32_t getMinimum(EDateFields field) const;
1024*0e209d39SAndroid Build Coastguard Worker #endif // U_FORCE_HIDE_DEPRECATED_API
1025*0e209d39SAndroid Build Coastguard Worker
1026*0e209d39SAndroid Build Coastguard Worker /**
1027*0e209d39SAndroid Build Coastguard Worker * Gets the minimum value for the given time field. e.g., for Gregorian
1028*0e209d39SAndroid Build Coastguard Worker * DAY_OF_MONTH, 1.
1029*0e209d39SAndroid Build Coastguard Worker *
1030*0e209d39SAndroid Build Coastguard Worker * @param field The given time field.
1031*0e209d39SAndroid Build Coastguard Worker * @return The minimum value for the given time field.
1032*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.6.
1033*0e209d39SAndroid Build Coastguard Worker */
1034*0e209d39SAndroid Build Coastguard Worker virtual int32_t getMinimum(UCalendarDateFields field) const;
1035*0e209d39SAndroid Build Coastguard Worker
1036*0e209d39SAndroid Build Coastguard Worker #ifndef U_FORCE_HIDE_DEPRECATED_API
1037*0e209d39SAndroid Build Coastguard Worker /**
1038*0e209d39SAndroid Build Coastguard Worker * Gets the maximum value for the given time field. e.g. for Gregorian DAY_OF_MONTH,
1039*0e209d39SAndroid Build Coastguard Worker * 31.
1040*0e209d39SAndroid Build Coastguard Worker *
1041*0e209d39SAndroid Build Coastguard Worker * @param field The given time field.
1042*0e209d39SAndroid Build Coastguard Worker * @return The maximum value for the given time field.
1043*0e209d39SAndroid Build Coastguard Worker * @deprecated ICU 2.6. Use getMaximum(UCalendarDateFields field) instead.
1044*0e209d39SAndroid Build Coastguard Worker */
1045*0e209d39SAndroid Build Coastguard Worker virtual int32_t getMaximum(EDateFields field) const;
1046*0e209d39SAndroid Build Coastguard Worker #endif // U_FORCE_HIDE_DEPRECATED_API
1047*0e209d39SAndroid Build Coastguard Worker
1048*0e209d39SAndroid Build Coastguard Worker /**
1049*0e209d39SAndroid Build Coastguard Worker * Gets the maximum value for the given time field. e.g. for Gregorian DAY_OF_MONTH,
1050*0e209d39SAndroid Build Coastguard Worker * 31.
1051*0e209d39SAndroid Build Coastguard Worker *
1052*0e209d39SAndroid Build Coastguard Worker * @param field The given time field.
1053*0e209d39SAndroid Build Coastguard Worker * @return The maximum value for the given time field.
1054*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.6.
1055*0e209d39SAndroid Build Coastguard Worker */
1056*0e209d39SAndroid Build Coastguard Worker virtual int32_t getMaximum(UCalendarDateFields field) const;
1057*0e209d39SAndroid Build Coastguard Worker
1058*0e209d39SAndroid Build Coastguard Worker #ifndef U_FORCE_HIDE_DEPRECATED_API
1059*0e209d39SAndroid Build Coastguard Worker /**
1060*0e209d39SAndroid Build Coastguard Worker * Gets the highest minimum value for the given field if varies. Otherwise same as
1061*0e209d39SAndroid Build Coastguard Worker * getMinimum(). For Gregorian, no difference.
1062*0e209d39SAndroid Build Coastguard Worker *
1063*0e209d39SAndroid Build Coastguard Worker * @param field The given time field.
1064*0e209d39SAndroid Build Coastguard Worker * @return The highest minimum value for the given time field.
1065*0e209d39SAndroid Build Coastguard Worker * @deprecated ICU 2.6. Use getGreatestMinimum(UCalendarDateFields field) instead.
1066*0e209d39SAndroid Build Coastguard Worker */
1067*0e209d39SAndroid Build Coastguard Worker virtual int32_t getGreatestMinimum(EDateFields field) const;
1068*0e209d39SAndroid Build Coastguard Worker #endif // U_FORCE_HIDE_DEPRECATED_API
1069*0e209d39SAndroid Build Coastguard Worker
1070*0e209d39SAndroid Build Coastguard Worker /**
1071*0e209d39SAndroid Build Coastguard Worker * Gets the highest minimum value for the given field if varies. Otherwise same as
1072*0e209d39SAndroid Build Coastguard Worker * getMinimum(). For Gregorian, no difference.
1073*0e209d39SAndroid Build Coastguard Worker *
1074*0e209d39SAndroid Build Coastguard Worker * @param field The given time field.
1075*0e209d39SAndroid Build Coastguard Worker * @return The highest minimum value for the given time field.
1076*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.6.
1077*0e209d39SAndroid Build Coastguard Worker */
1078*0e209d39SAndroid Build Coastguard Worker virtual int32_t getGreatestMinimum(UCalendarDateFields field) const;
1079*0e209d39SAndroid Build Coastguard Worker
1080*0e209d39SAndroid Build Coastguard Worker #ifndef U_FORCE_HIDE_DEPRECATED_API
1081*0e209d39SAndroid Build Coastguard Worker /**
1082*0e209d39SAndroid Build Coastguard Worker * Gets the lowest maximum value for the given field if varies. Otherwise same as
1083*0e209d39SAndroid Build Coastguard Worker * getMaximum(). e.g., for Gregorian DAY_OF_MONTH, 28.
1084*0e209d39SAndroid Build Coastguard Worker *
1085*0e209d39SAndroid Build Coastguard Worker * @param field The given time field.
1086*0e209d39SAndroid Build Coastguard Worker * @return The lowest maximum value for the given time field.
1087*0e209d39SAndroid Build Coastguard Worker * @deprecated ICU 2.6. Use getLeastMaximum(UCalendarDateFields field) instead.
1088*0e209d39SAndroid Build Coastguard Worker */
1089*0e209d39SAndroid Build Coastguard Worker virtual int32_t getLeastMaximum(EDateFields field) const;
1090*0e209d39SAndroid Build Coastguard Worker #endif // U_FORCE_HIDE_DEPRECATED_API
1091*0e209d39SAndroid Build Coastguard Worker
1092*0e209d39SAndroid Build Coastguard Worker /**
1093*0e209d39SAndroid Build Coastguard Worker * Gets the lowest maximum value for the given field if varies. Otherwise same as
1094*0e209d39SAndroid Build Coastguard Worker * getMaximum(). e.g., for Gregorian DAY_OF_MONTH, 28.
1095*0e209d39SAndroid Build Coastguard Worker *
1096*0e209d39SAndroid Build Coastguard Worker * @param field The given time field.
1097*0e209d39SAndroid Build Coastguard Worker * @return The lowest maximum value for the given time field.
1098*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.6.
1099*0e209d39SAndroid Build Coastguard Worker */
1100*0e209d39SAndroid Build Coastguard Worker virtual int32_t getLeastMaximum(UCalendarDateFields field) const;
1101*0e209d39SAndroid Build Coastguard Worker
1102*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_DEPRECATED_API
1103*0e209d39SAndroid Build Coastguard Worker /**
1104*0e209d39SAndroid Build Coastguard Worker * Return the minimum value that this field could have, given the current date.
1105*0e209d39SAndroid Build Coastguard Worker * For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum().
1106*0e209d39SAndroid Build Coastguard Worker *
1107*0e209d39SAndroid Build Coastguard Worker * The version of this function on Calendar uses an iterative algorithm to determine the
1108*0e209d39SAndroid Build Coastguard Worker * actual minimum value for the field. There is almost always a more efficient way to
1109*0e209d39SAndroid Build Coastguard Worker * accomplish this (in most cases, you can simply return getMinimum()). GregorianCalendar
1110*0e209d39SAndroid Build Coastguard Worker * overrides this function with a more efficient implementation.
1111*0e209d39SAndroid Build Coastguard Worker *
1112*0e209d39SAndroid Build Coastguard Worker * @param field the field to determine the minimum of
1113*0e209d39SAndroid Build Coastguard Worker * @param status Fill-in parameter which receives the status of this operation.
1114*0e209d39SAndroid Build Coastguard Worker * @return the minimum of the given field for the current date of this Calendar
1115*0e209d39SAndroid Build Coastguard Worker * @deprecated ICU 2.6. Use getActualMinimum(UCalendarDateFields field, UErrorCode& status) instead.
1116*0e209d39SAndroid Build Coastguard Worker */
1117*0e209d39SAndroid Build Coastguard Worker int32_t getActualMinimum(EDateFields field, UErrorCode& status) const;
1118*0e209d39SAndroid Build Coastguard Worker #endif /* U_HIDE_DEPRECATED_API */
1119*0e209d39SAndroid Build Coastguard Worker
1120*0e209d39SAndroid Build Coastguard Worker /**
1121*0e209d39SAndroid Build Coastguard Worker * Return the minimum value that this field could have, given the current date.
1122*0e209d39SAndroid Build Coastguard Worker * For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum().
1123*0e209d39SAndroid Build Coastguard Worker *
1124*0e209d39SAndroid Build Coastguard Worker * The version of this function on Calendar uses an iterative algorithm to determine the
1125*0e209d39SAndroid Build Coastguard Worker * actual minimum value for the field. There is almost always a more efficient way to
1126*0e209d39SAndroid Build Coastguard Worker * accomplish this (in most cases, you can simply return getMinimum()). GregorianCalendar
1127*0e209d39SAndroid Build Coastguard Worker * overrides this function with a more efficient implementation.
1128*0e209d39SAndroid Build Coastguard Worker *
1129*0e209d39SAndroid Build Coastguard Worker * @param field the field to determine the minimum of
1130*0e209d39SAndroid Build Coastguard Worker * @param status Fill-in parameter which receives the status of this operation.
1131*0e209d39SAndroid Build Coastguard Worker * @return the minimum of the given field for the current date of this Calendar
1132*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.6.
1133*0e209d39SAndroid Build Coastguard Worker */
1134*0e209d39SAndroid Build Coastguard Worker virtual int32_t getActualMinimum(UCalendarDateFields field, UErrorCode& status) const;
1135*0e209d39SAndroid Build Coastguard Worker
1136*0e209d39SAndroid Build Coastguard Worker /**
1137*0e209d39SAndroid Build Coastguard Worker * Return the maximum value that this field could have, given the current date.
1138*0e209d39SAndroid Build Coastguard Worker * For example, with the date "Feb 3, 1997" and the DAY_OF_MONTH field, the actual
1139*0e209d39SAndroid Build Coastguard Worker * maximum would be 28; for "Feb 3, 1996" it s 29. Similarly for a Hebrew calendar,
1140*0e209d39SAndroid Build Coastguard Worker * for some years the actual maximum for MONTH is 12, and for others 13.
1141*0e209d39SAndroid Build Coastguard Worker *
1142*0e209d39SAndroid Build Coastguard Worker * The version of this function on Calendar uses an iterative algorithm to determine the
1143*0e209d39SAndroid Build Coastguard Worker * actual maximum value for the field. There is almost always a more efficient way to
1144*0e209d39SAndroid Build Coastguard Worker * accomplish this (in most cases, you can simply return getMaximum()). GregorianCalendar
1145*0e209d39SAndroid Build Coastguard Worker * overrides this function with a more efficient implementation.
1146*0e209d39SAndroid Build Coastguard Worker *
1147*0e209d39SAndroid Build Coastguard Worker * @param field the field to determine the maximum of
1148*0e209d39SAndroid Build Coastguard Worker * @param status Fill-in parameter which receives the status of this operation.
1149*0e209d39SAndroid Build Coastguard Worker * @return the maximum of the given field for the current date of this Calendar
1150*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.6.
1151*0e209d39SAndroid Build Coastguard Worker */
1152*0e209d39SAndroid Build Coastguard Worker virtual int32_t getActualMaximum(UCalendarDateFields field, UErrorCode& status) const;
1153*0e209d39SAndroid Build Coastguard Worker
1154*0e209d39SAndroid Build Coastguard Worker /**
1155*0e209d39SAndroid Build Coastguard Worker * Gets the value for a given time field. Recalculate the current time field values
1156*0e209d39SAndroid Build Coastguard Worker * if the time value has been changed by a call to setTime(). Return zero for unset
1157*0e209d39SAndroid Build Coastguard Worker * fields if any fields have been explicitly set by a call to set(). To force a
1158*0e209d39SAndroid Build Coastguard Worker * recomputation of all fields regardless of the previous state, call complete().
1159*0e209d39SAndroid Build Coastguard Worker * This method is semantically const, but may alter the object in memory.
1160*0e209d39SAndroid Build Coastguard Worker *
1161*0e209d39SAndroid Build Coastguard Worker * @param field The given time field.
1162*0e209d39SAndroid Build Coastguard Worker * @param status Fill-in parameter which receives the status of the operation.
1163*0e209d39SAndroid Build Coastguard Worker * @return The value for the given time field, or zero if the field is unset,
1164*0e209d39SAndroid Build Coastguard Worker * and set() has been called for any other field.
1165*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.6.
1166*0e209d39SAndroid Build Coastguard Worker */
1167*0e209d39SAndroid Build Coastguard Worker int32_t get(UCalendarDateFields field, UErrorCode& status) const;
1168*0e209d39SAndroid Build Coastguard Worker
1169*0e209d39SAndroid Build Coastguard Worker /**
1170*0e209d39SAndroid Build Coastguard Worker * Determines if the given time field has a value set. This can affect in the
1171*0e209d39SAndroid Build Coastguard Worker * resolving of time in Calendar. Unset fields have a value of zero, by definition.
1172*0e209d39SAndroid Build Coastguard Worker *
1173*0e209d39SAndroid Build Coastguard Worker * @param field The given time field.
1174*0e209d39SAndroid Build Coastguard Worker * @return True if the given time field has a value set; false otherwise.
1175*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.6.
1176*0e209d39SAndroid Build Coastguard Worker */
1177*0e209d39SAndroid Build Coastguard Worker UBool isSet(UCalendarDateFields field) const;
1178*0e209d39SAndroid Build Coastguard Worker
1179*0e209d39SAndroid Build Coastguard Worker /**
1180*0e209d39SAndroid Build Coastguard Worker * Sets the given time field with the given value.
1181*0e209d39SAndroid Build Coastguard Worker *
1182*0e209d39SAndroid Build Coastguard Worker * @param field The given time field.
1183*0e209d39SAndroid Build Coastguard Worker * @param value The value to be set for the given time field.
1184*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.6.
1185*0e209d39SAndroid Build Coastguard Worker */
1186*0e209d39SAndroid Build Coastguard Worker void set(UCalendarDateFields field, int32_t value);
1187*0e209d39SAndroid Build Coastguard Worker
1188*0e209d39SAndroid Build Coastguard Worker /**
1189*0e209d39SAndroid Build Coastguard Worker * Sets the values for the fields YEAR, MONTH, and DATE. Other field values are
1190*0e209d39SAndroid Build Coastguard Worker * retained; call clear() first if this is not desired.
1191*0e209d39SAndroid Build Coastguard Worker *
1192*0e209d39SAndroid Build Coastguard Worker * @param year The value used to set the YEAR time field.
1193*0e209d39SAndroid Build Coastguard Worker * @param month The value used to set the MONTH time field. Month value is 0-based.
1194*0e209d39SAndroid Build Coastguard Worker * e.g., 0 for January.
1195*0e209d39SAndroid Build Coastguard Worker * @param date The value used to set the DATE time field.
1196*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1197*0e209d39SAndroid Build Coastguard Worker */
1198*0e209d39SAndroid Build Coastguard Worker void set(int32_t year, int32_t month, int32_t date);
1199*0e209d39SAndroid Build Coastguard Worker
1200*0e209d39SAndroid Build Coastguard Worker /**
1201*0e209d39SAndroid Build Coastguard Worker * Sets the values for the fields YEAR, MONTH, DATE, HOUR_OF_DAY, and MINUTE. Other
1202*0e209d39SAndroid Build Coastguard Worker * field values are retained; call clear() first if this is not desired.
1203*0e209d39SAndroid Build Coastguard Worker *
1204*0e209d39SAndroid Build Coastguard Worker * @param year The value used to set the YEAR time field.
1205*0e209d39SAndroid Build Coastguard Worker * @param month The value used to set the MONTH time field. Month value is
1206*0e209d39SAndroid Build Coastguard Worker * 0-based. E.g., 0 for January.
1207*0e209d39SAndroid Build Coastguard Worker * @param date The value used to set the DATE time field.
1208*0e209d39SAndroid Build Coastguard Worker * @param hour The value used to set the HOUR_OF_DAY time field.
1209*0e209d39SAndroid Build Coastguard Worker * @param minute The value used to set the MINUTE time field.
1210*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1211*0e209d39SAndroid Build Coastguard Worker */
1212*0e209d39SAndroid Build Coastguard Worker void set(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute);
1213*0e209d39SAndroid Build Coastguard Worker
1214*0e209d39SAndroid Build Coastguard Worker /**
1215*0e209d39SAndroid Build Coastguard Worker * Sets the values for the fields YEAR, MONTH, DATE, HOUR_OF_DAY, MINUTE, and SECOND.
1216*0e209d39SAndroid Build Coastguard Worker * Other field values are retained; call clear() first if this is not desired.
1217*0e209d39SAndroid Build Coastguard Worker *
1218*0e209d39SAndroid Build Coastguard Worker * @param year The value used to set the YEAR time field.
1219*0e209d39SAndroid Build Coastguard Worker * @param month The value used to set the MONTH time field. Month value is
1220*0e209d39SAndroid Build Coastguard Worker * 0-based. E.g., 0 for January.
1221*0e209d39SAndroid Build Coastguard Worker * @param date The value used to set the DATE time field.
1222*0e209d39SAndroid Build Coastguard Worker * @param hour The value used to set the HOUR_OF_DAY time field.
1223*0e209d39SAndroid Build Coastguard Worker * @param minute The value used to set the MINUTE time field.
1224*0e209d39SAndroid Build Coastguard Worker * @param second The value used to set the SECOND time field.
1225*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1226*0e209d39SAndroid Build Coastguard Worker */
1227*0e209d39SAndroid Build Coastguard Worker void set(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, int32_t second);
1228*0e209d39SAndroid Build Coastguard Worker
1229*0e209d39SAndroid Build Coastguard Worker /**
1230*0e209d39SAndroid Build Coastguard Worker * Clears the values of all the time fields, making them both unset and assigning
1231*0e209d39SAndroid Build Coastguard Worker * them a value of zero. The field values will be determined during the next
1232*0e209d39SAndroid Build Coastguard Worker * resolving of time into time fields.
1233*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1234*0e209d39SAndroid Build Coastguard Worker */
1235*0e209d39SAndroid Build Coastguard Worker void clear();
1236*0e209d39SAndroid Build Coastguard Worker
1237*0e209d39SAndroid Build Coastguard Worker /**
1238*0e209d39SAndroid Build Coastguard Worker * Clears the value in the given time field, both making it unset and assigning it a
1239*0e209d39SAndroid Build Coastguard Worker * value of zero. This field value will be determined during the next resolving of
1240*0e209d39SAndroid Build Coastguard Worker * time into time fields. Clearing UCAL_ORDINAL_MONTH or UCAL_MONTH will
1241*0e209d39SAndroid Build Coastguard Worker * clear both fields.
1242*0e209d39SAndroid Build Coastguard Worker *
1243*0e209d39SAndroid Build Coastguard Worker * @param field The time field to be cleared.
1244*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.6.
1245*0e209d39SAndroid Build Coastguard Worker */
1246*0e209d39SAndroid Build Coastguard Worker void clear(UCalendarDateFields field);
1247*0e209d39SAndroid Build Coastguard Worker
1248*0e209d39SAndroid Build Coastguard Worker /**
1249*0e209d39SAndroid Build Coastguard Worker * Returns a unique class ID POLYMORPHICALLY. Pure virtual method. This method is to
1250*0e209d39SAndroid Build Coastguard Worker * implement a simple version of RTTI, since not all C++ compilers support genuine
1251*0e209d39SAndroid Build Coastguard Worker * RTTI. Polymorphic operator==() and clone() methods call this method.
1252*0e209d39SAndroid Build Coastguard Worker * <P>
1253*0e209d39SAndroid Build Coastguard Worker * Concrete subclasses of Calendar must implement getDynamicClassID() and also a
1254*0e209d39SAndroid Build Coastguard Worker * static method and data member:
1255*0e209d39SAndroid Build Coastguard Worker *
1256*0e209d39SAndroid Build Coastguard Worker * static UClassID getStaticClassID() { return (UClassID)&fgClassID; }
1257*0e209d39SAndroid Build Coastguard Worker * static char fgClassID;
1258*0e209d39SAndroid Build Coastguard Worker *
1259*0e209d39SAndroid Build Coastguard Worker * @return The class ID for this object. All objects of a given class have the
1260*0e209d39SAndroid Build Coastguard Worker * same class ID. Objects of other classes have different class IDs.
1261*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1262*0e209d39SAndroid Build Coastguard Worker */
1263*0e209d39SAndroid Build Coastguard Worker virtual UClassID getDynamicClassID() const override = 0;
1264*0e209d39SAndroid Build Coastguard Worker
1265*0e209d39SAndroid Build Coastguard Worker /**
1266*0e209d39SAndroid Build Coastguard Worker * Returns the calendar type name string for this Calendar object.
1267*0e209d39SAndroid Build Coastguard Worker * The returned string is the legacy ICU calendar attribute value,
1268*0e209d39SAndroid Build Coastguard Worker * for example, "gregorian" or "japanese".
1269*0e209d39SAndroid Build Coastguard Worker *
1270*0e209d39SAndroid Build Coastguard Worker * See type="old type name" for the calendar attribute of locale IDs
1271*0e209d39SAndroid Build Coastguard Worker * at http://www.unicode.org/reports/tr35/#Key_Type_Definitions
1272*0e209d39SAndroid Build Coastguard Worker *
1273*0e209d39SAndroid Build Coastguard Worker * Sample code for getting the LDML/BCP 47 calendar key value:
1274*0e209d39SAndroid Build Coastguard Worker * \code
1275*0e209d39SAndroid Build Coastguard Worker * const char *calType = cal->getType();
1276*0e209d39SAndroid Build Coastguard Worker * if (0 == strcmp(calType, "unknown")) {
1277*0e209d39SAndroid Build Coastguard Worker * // deal with unknown calendar type
1278*0e209d39SAndroid Build Coastguard Worker * } else {
1279*0e209d39SAndroid Build Coastguard Worker * string localeID("root@calendar=");
1280*0e209d39SAndroid Build Coastguard Worker * localeID.append(calType);
1281*0e209d39SAndroid Build Coastguard Worker * char langTag[100];
1282*0e209d39SAndroid Build Coastguard Worker * UErrorCode errorCode = U_ZERO_ERROR;
1283*0e209d39SAndroid Build Coastguard Worker * int32_t length = uloc_toLanguageTag(localeID.c_str(), langTag, (int32_t)sizeof(langTag), true, &errorCode);
1284*0e209d39SAndroid Build Coastguard Worker * if (U_FAILURE(errorCode)) {
1285*0e209d39SAndroid Build Coastguard Worker * // deal with errors & overflow
1286*0e209d39SAndroid Build Coastguard Worker * }
1287*0e209d39SAndroid Build Coastguard Worker * string lang(langTag, length);
1288*0e209d39SAndroid Build Coastguard Worker * size_t caPos = lang.find("-ca-");
1289*0e209d39SAndroid Build Coastguard Worker * lang.erase(0, caPos + 4);
1290*0e209d39SAndroid Build Coastguard Worker * // lang now contains the LDML calendar type
1291*0e209d39SAndroid Build Coastguard Worker * }
1292*0e209d39SAndroid Build Coastguard Worker * \endcode
1293*0e209d39SAndroid Build Coastguard Worker *
1294*0e209d39SAndroid Build Coastguard Worker * @return legacy calendar type name string
1295*0e209d39SAndroid Build Coastguard Worker * @stable ICU 49
1296*0e209d39SAndroid Build Coastguard Worker */
1297*0e209d39SAndroid Build Coastguard Worker virtual const char * getType() const = 0;
1298*0e209d39SAndroid Build Coastguard Worker
1299*0e209d39SAndroid Build Coastguard Worker /**
1300*0e209d39SAndroid Build Coastguard Worker * Returns whether the given day of the week is a weekday, a weekend day,
1301*0e209d39SAndroid Build Coastguard Worker * or a day that transitions from one to the other, for the locale and
1302*0e209d39SAndroid Build Coastguard Worker * calendar system associated with this Calendar (the locale's region is
1303*0e209d39SAndroid Build Coastguard Worker * often the most determinant factor). If a transition occurs at midnight,
1304*0e209d39SAndroid Build Coastguard Worker * then the days before and after the transition will have the
1305*0e209d39SAndroid Build Coastguard Worker * type UCAL_WEEKDAY or UCAL_WEEKEND. If a transition occurs at a time
1306*0e209d39SAndroid Build Coastguard Worker * other than midnight, then the day of the transition will have
1307*0e209d39SAndroid Build Coastguard Worker * the type UCAL_WEEKEND_ONSET or UCAL_WEEKEND_CEASE. In this case, the
1308*0e209d39SAndroid Build Coastguard Worker * method getWeekendTransition() will return the point of
1309*0e209d39SAndroid Build Coastguard Worker * transition.
1310*0e209d39SAndroid Build Coastguard Worker * @param dayOfWeek The day of the week whose type is desired (UCAL_SUNDAY..UCAL_SATURDAY).
1311*0e209d39SAndroid Build Coastguard Worker * @param status The error code for the operation.
1312*0e209d39SAndroid Build Coastguard Worker * @return The UCalendarWeekdayType for the day of the week.
1313*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.4
1314*0e209d39SAndroid Build Coastguard Worker */
1315*0e209d39SAndroid Build Coastguard Worker virtual UCalendarWeekdayType getDayOfWeekType(UCalendarDaysOfWeek dayOfWeek, UErrorCode &status) const;
1316*0e209d39SAndroid Build Coastguard Worker
1317*0e209d39SAndroid Build Coastguard Worker /**
1318*0e209d39SAndroid Build Coastguard Worker * Returns the time during the day at which the weekend begins or ends in
1319*0e209d39SAndroid Build Coastguard Worker * this calendar system. If getDayOfWeekType() returns UCAL_WEEKEND_ONSET
1320*0e209d39SAndroid Build Coastguard Worker * for the specified dayOfWeek, return the time at which the weekend begins.
1321*0e209d39SAndroid Build Coastguard Worker * If getDayOfWeekType() returns UCAL_WEEKEND_CEASE for the specified dayOfWeek,
1322*0e209d39SAndroid Build Coastguard Worker * return the time at which the weekend ends. If getDayOfWeekType() returns
1323*0e209d39SAndroid Build Coastguard Worker * some other UCalendarWeekdayType for the specified dayOfWeek, is it an error condition
1324*0e209d39SAndroid Build Coastguard Worker * (U_ILLEGAL_ARGUMENT_ERROR).
1325*0e209d39SAndroid Build Coastguard Worker * @param dayOfWeek The day of the week for which the weekend transition time is
1326*0e209d39SAndroid Build Coastguard Worker * desired (UCAL_SUNDAY..UCAL_SATURDAY).
1327*0e209d39SAndroid Build Coastguard Worker * @param status The error code for the operation.
1328*0e209d39SAndroid Build Coastguard Worker * @return The milliseconds after midnight at which the weekend begins or ends.
1329*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.4
1330*0e209d39SAndroid Build Coastguard Worker */
1331*0e209d39SAndroid Build Coastguard Worker virtual int32_t getWeekendTransition(UCalendarDaysOfWeek dayOfWeek, UErrorCode &status) const;
1332*0e209d39SAndroid Build Coastguard Worker
1333*0e209d39SAndroid Build Coastguard Worker /**
1334*0e209d39SAndroid Build Coastguard Worker * Returns true if the given UDate is in the weekend in
1335*0e209d39SAndroid Build Coastguard Worker * this calendar system.
1336*0e209d39SAndroid Build Coastguard Worker * @param date The UDate in question.
1337*0e209d39SAndroid Build Coastguard Worker * @param status The error code for the operation.
1338*0e209d39SAndroid Build Coastguard Worker * @return true if the given UDate is in the weekend in
1339*0e209d39SAndroid Build Coastguard Worker * this calendar system, false otherwise.
1340*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.4
1341*0e209d39SAndroid Build Coastguard Worker */
1342*0e209d39SAndroid Build Coastguard Worker virtual UBool isWeekend(UDate date, UErrorCode &status) const;
1343*0e209d39SAndroid Build Coastguard Worker
1344*0e209d39SAndroid Build Coastguard Worker /**
1345*0e209d39SAndroid Build Coastguard Worker * Returns true if this Calendar's current date-time is in the weekend in
1346*0e209d39SAndroid Build Coastguard Worker * this calendar system.
1347*0e209d39SAndroid Build Coastguard Worker * @return true if this Calendar's current date-time is in the weekend in
1348*0e209d39SAndroid Build Coastguard Worker * this calendar system, false otherwise.
1349*0e209d39SAndroid Build Coastguard Worker * @stable ICU 4.4
1350*0e209d39SAndroid Build Coastguard Worker */
1351*0e209d39SAndroid Build Coastguard Worker virtual UBool isWeekend() const;
1352*0e209d39SAndroid Build Coastguard Worker
1353*0e209d39SAndroid Build Coastguard Worker /**
1354*0e209d39SAndroid Build Coastguard Worker * Returns true if the date is in a leap year. Recalculate the current time
1355*0e209d39SAndroid Build Coastguard Worker * field values if the time value has been changed by a call to * setTime().
1356*0e209d39SAndroid Build Coastguard Worker * This method is semantically const, but may alter the object in memory.
1357*0e209d39SAndroid Build Coastguard Worker * A "leap year" is a year that contains more days than other years (for
1358*0e209d39SAndroid Build Coastguard Worker * solar or lunar calendars) or more months than other years (for lunisolar
1359*0e209d39SAndroid Build Coastguard Worker * calendars like Hebrew or Chinese), as defined in the ECMAScript Temporal
1360*0e209d39SAndroid Build Coastguard Worker * proposal.
1361*0e209d39SAndroid Build Coastguard Worker *
1362*0e209d39SAndroid Build Coastguard Worker * @param status ICU Error Code
1363*0e209d39SAndroid Build Coastguard Worker * @return True if the date in the fields is in a Temporal proposal
1364*0e209d39SAndroid Build Coastguard Worker * defined leap year. False otherwise.
1365*0e209d39SAndroid Build Coastguard Worker * @stable ICU 73
1366*0e209d39SAndroid Build Coastguard Worker */
1367*0e209d39SAndroid Build Coastguard Worker virtual bool inTemporalLeapYear(UErrorCode& status) const;
1368*0e209d39SAndroid Build Coastguard Worker
1369*0e209d39SAndroid Build Coastguard Worker /**
1370*0e209d39SAndroid Build Coastguard Worker * Gets The Temporal monthCode value corresponding to the month for the date.
1371*0e209d39SAndroid Build Coastguard Worker * The value is a string identifier that starts with the literal grapheme
1372*0e209d39SAndroid Build Coastguard Worker * "M" followed by two graphemes representing the zero-padded month number
1373*0e209d39SAndroid Build Coastguard Worker * of the current month in a normal (non-leap) year and suffixed by an
1374*0e209d39SAndroid Build Coastguard Worker * optional literal grapheme "L" if this is a leap month in a lunisolar
1375*0e209d39SAndroid Build Coastguard Worker * calendar. The 25 possible values are "M01" .. "M13" and "M01L" .. "M12L".
1376*0e209d39SAndroid Build Coastguard Worker * For the Hebrew calendar, the values are "M01" .. "M12" for non-leap year, and
1377*0e209d39SAndroid Build Coastguard Worker * "M01" .. "M05", "M05L", "M06" .. "M12" for leap year.
1378*0e209d39SAndroid Build Coastguard Worker * For the Chinese calendar, the values are "M01" .. "M12" for non-leap year and
1379*0e209d39SAndroid Build Coastguard Worker * in leap year with another monthCode in "M01L" .. "M12L".
1380*0e209d39SAndroid Build Coastguard Worker * For Coptic and Ethiopian calendar, the Temporal monthCode values for any
1381*0e209d39SAndroid Build Coastguard Worker * years are "M01" to "M13".
1382*0e209d39SAndroid Build Coastguard Worker *
1383*0e209d39SAndroid Build Coastguard Worker * @param status ICU Error Code
1384*0e209d39SAndroid Build Coastguard Worker * @return One of 25 possible strings in {"M01".."M13", "M01L".."M12L"}.
1385*0e209d39SAndroid Build Coastguard Worker * @stable ICU 73
1386*0e209d39SAndroid Build Coastguard Worker */
1387*0e209d39SAndroid Build Coastguard Worker virtual const char* getTemporalMonthCode(UErrorCode& status) const;
1388*0e209d39SAndroid Build Coastguard Worker
1389*0e209d39SAndroid Build Coastguard Worker /**
1390*0e209d39SAndroid Build Coastguard Worker * Sets The Temporal monthCode which is a string identifier that starts
1391*0e209d39SAndroid Build Coastguard Worker * with the literal grapheme "M" followed by two graphemes representing
1392*0e209d39SAndroid Build Coastguard Worker * the zero-padded month number of the current month in a normal
1393*0e209d39SAndroid Build Coastguard Worker * (non-leap) year and suffixed by an optional literal grapheme "L" if this
1394*0e209d39SAndroid Build Coastguard Worker * is a leap month in a lunisolar calendar. The 25 possible values are
1395*0e209d39SAndroid Build Coastguard Worker * "M01" .. "M13" and "M01L" .. "M12L". For Hebrew calendar, the values are
1396*0e209d39SAndroid Build Coastguard Worker * "M01" .. "M12" for non-leap years, and "M01" .. "M05", "M05L", "M06"
1397*0e209d39SAndroid Build Coastguard Worker * .. "M12" for leap year.
1398*0e209d39SAndroid Build Coastguard Worker * For the Chinese calendar, the values are "M01" .. "M12" for non-leap year and
1399*0e209d39SAndroid Build Coastguard Worker * in leap year with another monthCode in "M01L" .. "M12L".
1400*0e209d39SAndroid Build Coastguard Worker * For Coptic and Ethiopian calendar, the Temporal monthCode values for any
1401*0e209d39SAndroid Build Coastguard Worker * years are "M01" to "M13".
1402*0e209d39SAndroid Build Coastguard Worker *
1403*0e209d39SAndroid Build Coastguard Worker * @param temporalMonth The value to be set for temporal monthCode.
1404*0e209d39SAndroid Build Coastguard Worker * @param status ICU Error Code
1405*0e209d39SAndroid Build Coastguard Worker *
1406*0e209d39SAndroid Build Coastguard Worker * @stable ICU 73
1407*0e209d39SAndroid Build Coastguard Worker */
1408*0e209d39SAndroid Build Coastguard Worker virtual void setTemporalMonthCode(const char* temporalMonth, UErrorCode& status);
1409*0e209d39SAndroid Build Coastguard Worker
1410*0e209d39SAndroid Build Coastguard Worker protected:
1411*0e209d39SAndroid Build Coastguard Worker
1412*0e209d39SAndroid Build Coastguard Worker /**
1413*0e209d39SAndroid Build Coastguard Worker * Constructs a Calendar with the default time zone as returned by
1414*0e209d39SAndroid Build Coastguard Worker * TimeZone::createInstance(), and the default locale.
1415*0e209d39SAndroid Build Coastguard Worker *
1416*0e209d39SAndroid Build Coastguard Worker * @param success Indicates the status of Calendar object construction. Returns
1417*0e209d39SAndroid Build Coastguard Worker * U_ZERO_ERROR if constructed successfully.
1418*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1419*0e209d39SAndroid Build Coastguard Worker */
1420*0e209d39SAndroid Build Coastguard Worker Calendar(UErrorCode& success);
1421*0e209d39SAndroid Build Coastguard Worker
1422*0e209d39SAndroid Build Coastguard Worker /**
1423*0e209d39SAndroid Build Coastguard Worker * Copy constructor
1424*0e209d39SAndroid Build Coastguard Worker *
1425*0e209d39SAndroid Build Coastguard Worker * @param source Calendar object to be copied from
1426*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1427*0e209d39SAndroid Build Coastguard Worker */
1428*0e209d39SAndroid Build Coastguard Worker Calendar(const Calendar& source);
1429*0e209d39SAndroid Build Coastguard Worker
1430*0e209d39SAndroid Build Coastguard Worker /**
1431*0e209d39SAndroid Build Coastguard Worker * Default assignment operator
1432*0e209d39SAndroid Build Coastguard Worker *
1433*0e209d39SAndroid Build Coastguard Worker * @param right Calendar object to be copied
1434*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1435*0e209d39SAndroid Build Coastguard Worker */
1436*0e209d39SAndroid Build Coastguard Worker Calendar& operator=(const Calendar& right);
1437*0e209d39SAndroid Build Coastguard Worker
1438*0e209d39SAndroid Build Coastguard Worker /**
1439*0e209d39SAndroid Build Coastguard Worker * Constructs a Calendar with the given time zone and locale. Clients are no longer
1440*0e209d39SAndroid Build Coastguard Worker * responsible for deleting the given time zone object after it's adopted.
1441*0e209d39SAndroid Build Coastguard Worker *
1442*0e209d39SAndroid Build Coastguard Worker * @param zone The given time zone.
1443*0e209d39SAndroid Build Coastguard Worker * @param aLocale The given locale.
1444*0e209d39SAndroid Build Coastguard Worker * @param success Indicates the status of Calendar object construction. Returns
1445*0e209d39SAndroid Build Coastguard Worker * U_ZERO_ERROR if constructed successfully.
1446*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1447*0e209d39SAndroid Build Coastguard Worker */
1448*0e209d39SAndroid Build Coastguard Worker Calendar(TimeZone* zone, const Locale& aLocale, UErrorCode& success);
1449*0e209d39SAndroid Build Coastguard Worker
1450*0e209d39SAndroid Build Coastguard Worker /**
1451*0e209d39SAndroid Build Coastguard Worker * Constructs a Calendar with the given time zone and locale.
1452*0e209d39SAndroid Build Coastguard Worker *
1453*0e209d39SAndroid Build Coastguard Worker * @param zone The given time zone.
1454*0e209d39SAndroid Build Coastguard Worker * @param aLocale The given locale.
1455*0e209d39SAndroid Build Coastguard Worker * @param success Indicates the status of Calendar object construction. Returns
1456*0e209d39SAndroid Build Coastguard Worker * U_ZERO_ERROR if constructed successfully.
1457*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1458*0e209d39SAndroid Build Coastguard Worker */
1459*0e209d39SAndroid Build Coastguard Worker Calendar(const TimeZone& zone, const Locale& aLocale, UErrorCode& success);
1460*0e209d39SAndroid Build Coastguard Worker
1461*0e209d39SAndroid Build Coastguard Worker /**
1462*0e209d39SAndroid Build Coastguard Worker * Converts Calendar's time field values to GMT as milliseconds.
1463*0e209d39SAndroid Build Coastguard Worker *
1464*0e209d39SAndroid Build Coastguard Worker * @param status Output param set to success/failure code on exit. If any value
1465*0e209d39SAndroid Build Coastguard Worker * previously set in the time field is invalid or restricted by
1466*0e209d39SAndroid Build Coastguard Worker * leniency, this will be set to an error status.
1467*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1468*0e209d39SAndroid Build Coastguard Worker */
1469*0e209d39SAndroid Build Coastguard Worker virtual void computeTime(UErrorCode& status);
1470*0e209d39SAndroid Build Coastguard Worker
1471*0e209d39SAndroid Build Coastguard Worker /**
1472*0e209d39SAndroid Build Coastguard Worker * Converts GMT as milliseconds to time field values. This allows you to sync up the
1473*0e209d39SAndroid Build Coastguard Worker * time field values with a new time that is set for the calendar. This method
1474*0e209d39SAndroid Build Coastguard Worker * does NOT recompute the time first; to recompute the time, then the fields, use
1475*0e209d39SAndroid Build Coastguard Worker * the method complete().
1476*0e209d39SAndroid Build Coastguard Worker *
1477*0e209d39SAndroid Build Coastguard Worker * @param status Output param set to success/failure code on exit. If any value
1478*0e209d39SAndroid Build Coastguard Worker * previously set in the time field is invalid or restricted by
1479*0e209d39SAndroid Build Coastguard Worker * leniency, this will be set to an error status.
1480*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1481*0e209d39SAndroid Build Coastguard Worker */
1482*0e209d39SAndroid Build Coastguard Worker virtual void computeFields(UErrorCode& status);
1483*0e209d39SAndroid Build Coastguard Worker
1484*0e209d39SAndroid Build Coastguard Worker /**
1485*0e209d39SAndroid Build Coastguard Worker * Gets this Calendar's current time as a long.
1486*0e209d39SAndroid Build Coastguard Worker *
1487*0e209d39SAndroid Build Coastguard Worker * @param status Output param set to success/failure code on exit. If any value
1488*0e209d39SAndroid Build Coastguard Worker * previously set in the time field is invalid or restricted by
1489*0e209d39SAndroid Build Coastguard Worker * leniency, this will be set to an error status.
1490*0e209d39SAndroid Build Coastguard Worker * @return the current time as UTC milliseconds from the epoch.
1491*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1492*0e209d39SAndroid Build Coastguard Worker */
1493*0e209d39SAndroid Build Coastguard Worker double getTimeInMillis(UErrorCode& status) const;
1494*0e209d39SAndroid Build Coastguard Worker
1495*0e209d39SAndroid Build Coastguard Worker /**
1496*0e209d39SAndroid Build Coastguard Worker * Sets this Calendar's current time from the given long value.
1497*0e209d39SAndroid Build Coastguard Worker * @param millis the new time in UTC milliseconds from the epoch.
1498*0e209d39SAndroid Build Coastguard Worker * @param status Output param set to success/failure code on exit. If any value
1499*0e209d39SAndroid Build Coastguard Worker * previously set in the time field is invalid or restricted by
1500*0e209d39SAndroid Build Coastguard Worker * leniency, this will be set to an error status.
1501*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1502*0e209d39SAndroid Build Coastguard Worker */
1503*0e209d39SAndroid Build Coastguard Worker void setTimeInMillis( double millis, UErrorCode& status );
1504*0e209d39SAndroid Build Coastguard Worker
1505*0e209d39SAndroid Build Coastguard Worker /**
1506*0e209d39SAndroid Build Coastguard Worker * Recomputes the current time from currently set fields, and then fills in any
1507*0e209d39SAndroid Build Coastguard Worker * unset fields in the time field list.
1508*0e209d39SAndroid Build Coastguard Worker *
1509*0e209d39SAndroid Build Coastguard Worker * @param status Output param set to success/failure code on exit. If any value
1510*0e209d39SAndroid Build Coastguard Worker * previously set in the time field is invalid or restricted by
1511*0e209d39SAndroid Build Coastguard Worker * leniency, this will be set to an error status.
1512*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1513*0e209d39SAndroid Build Coastguard Worker */
1514*0e209d39SAndroid Build Coastguard Worker void complete(UErrorCode& status);
1515*0e209d39SAndroid Build Coastguard Worker
1516*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_DEPRECATED_API
1517*0e209d39SAndroid Build Coastguard Worker /**
1518*0e209d39SAndroid Build Coastguard Worker * Gets the value for a given time field. Subclasses can use this function to get
1519*0e209d39SAndroid Build Coastguard Worker * field values without forcing recomputation of time.
1520*0e209d39SAndroid Build Coastguard Worker *
1521*0e209d39SAndroid Build Coastguard Worker * @param field The given time field.
1522*0e209d39SAndroid Build Coastguard Worker * @return The value for the given time field.
1523*0e209d39SAndroid Build Coastguard Worker * @deprecated ICU 2.6. Use internalGet(UCalendarDateFields field) instead.
1524*0e209d39SAndroid Build Coastguard Worker */
internalGet(EDateFields field)1525*0e209d39SAndroid Build Coastguard Worker inline int32_t internalGet(EDateFields field) const {return fFields[field];}
1526*0e209d39SAndroid Build Coastguard Worker #endif /* U_HIDE_DEPRECATED_API */
1527*0e209d39SAndroid Build Coastguard Worker
1528*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_INTERNAL_API
1529*0e209d39SAndroid Build Coastguard Worker /**
1530*0e209d39SAndroid Build Coastguard Worker * Gets the value for a given time field. Subclasses can use this function to get
1531*0e209d39SAndroid Build Coastguard Worker * field values without forcing recomputation of time. If the field's stamp is UNSET,
1532*0e209d39SAndroid Build Coastguard Worker * the defaultValue is used.
1533*0e209d39SAndroid Build Coastguard Worker *
1534*0e209d39SAndroid Build Coastguard Worker * @param field The given time field.
1535*0e209d39SAndroid Build Coastguard Worker * @param defaultValue a default value used if the field is unset.
1536*0e209d39SAndroid Build Coastguard Worker * @return The value for the given time field.
1537*0e209d39SAndroid Build Coastguard Worker * @internal
1538*0e209d39SAndroid Build Coastguard Worker */
internalGet(UCalendarDateFields field,int32_t defaultValue)1539*0e209d39SAndroid Build Coastguard Worker inline int32_t internalGet(UCalendarDateFields field, int32_t defaultValue) const {return fStamp[field]>kUnset ? fFields[field] : defaultValue;}
1540*0e209d39SAndroid Build Coastguard Worker
1541*0e209d39SAndroid Build Coastguard Worker /**
1542*0e209d39SAndroid Build Coastguard Worker * Gets the value for a given time field. Subclasses can use this function to get
1543*0e209d39SAndroid Build Coastguard Worker * field values without forcing recomputation of time.
1544*0e209d39SAndroid Build Coastguard Worker *
1545*0e209d39SAndroid Build Coastguard Worker * @param field The given time field.
1546*0e209d39SAndroid Build Coastguard Worker * @return The value for the given time field.
1547*0e209d39SAndroid Build Coastguard Worker * @internal
1548*0e209d39SAndroid Build Coastguard Worker */
internalGet(UCalendarDateFields field)1549*0e209d39SAndroid Build Coastguard Worker inline int32_t internalGet(UCalendarDateFields field) const {return fFields[field];}
1550*0e209d39SAndroid Build Coastguard Worker
1551*0e209d39SAndroid Build Coastguard Worker /**
1552*0e209d39SAndroid Build Coastguard Worker * The year in this calendar is counting from 1 backward if the era is 0.
1553*0e209d39SAndroid Build Coastguard Worker * @return The year in era 0 of this calendar is counting backward from 1.
1554*0e209d39SAndroid Build Coastguard Worker * @internal
1555*0e209d39SAndroid Build Coastguard Worker */
isEra0CountingBackward()1556*0e209d39SAndroid Build Coastguard Worker virtual bool isEra0CountingBackward() const { return false; }
1557*0e209d39SAndroid Build Coastguard Worker #endif /* U_HIDE_INTERNAL_API */
1558*0e209d39SAndroid Build Coastguard Worker
1559*0e209d39SAndroid Build Coastguard Worker /**
1560*0e209d39SAndroid Build Coastguard Worker * Use this function instead of internalGet(UCAL_MONTH). The implementation
1561*0e209d39SAndroid Build Coastguard Worker * check the timestamp of UCAL_MONTH and UCAL_ORDINAL_MONTH and use the
1562*0e209d39SAndroid Build Coastguard Worker * one set later. The subclass should override it to conver the value of UCAL_ORDINAL_MONTH
1563*0e209d39SAndroid Build Coastguard Worker * to UCAL_MONTH correctly if UCAL_ORDINAL_MONTH has higher priority.
1564*0e209d39SAndroid Build Coastguard Worker *
1565*0e209d39SAndroid Build Coastguard Worker * @return The value for the UCAL_MONTH.
1566*0e209d39SAndroid Build Coastguard Worker * @internal
1567*0e209d39SAndroid Build Coastguard Worker */
1568*0e209d39SAndroid Build Coastguard Worker virtual int32_t internalGetMonth(UErrorCode& status) const;
1569*0e209d39SAndroid Build Coastguard Worker
1570*0e209d39SAndroid Build Coastguard Worker /**
1571*0e209d39SAndroid Build Coastguard Worker * Use this function instead of internalGet(UCAL_MONTH, defaultValue). The implementation
1572*0e209d39SAndroid Build Coastguard Worker * check the timestamp of UCAL_MONTH and UCAL_ORDINAL_MONTH and use the
1573*0e209d39SAndroid Build Coastguard Worker * one set later. The subclass should override it to conver the value of UCAL_ORDINAL_MONTH
1574*0e209d39SAndroid Build Coastguard Worker * to UCAL_MONTH correctly if UCAL_ORDINAL_MONTH has higher priority.
1575*0e209d39SAndroid Build Coastguard Worker *
1576*0e209d39SAndroid Build Coastguard Worker * @param defaultValue a default value used if the UCAL_MONTH and
1577*0e209d39SAndroid Build Coastguard Worker * UCAL_ORDINAL are both unset.
1578*0e209d39SAndroid Build Coastguard Worker * @param status Output param set to failure code on function return
1579*0e209d39SAndroid Build Coastguard Worker * when this function fails.
1580*0e209d39SAndroid Build Coastguard Worker * @return The value for the UCAL_MONTH.
1581*0e209d39SAndroid Build Coastguard Worker * @internal
1582*0e209d39SAndroid Build Coastguard Worker */
1583*0e209d39SAndroid Build Coastguard Worker virtual int32_t internalGetMonth(int32_t defaultValue, UErrorCode& status) const;
1584*0e209d39SAndroid Build Coastguard Worker
1585*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_DEPRECATED_API
1586*0e209d39SAndroid Build Coastguard Worker /**
1587*0e209d39SAndroid Build Coastguard Worker * Sets the value for a given time field. This is a fast internal method for
1588*0e209d39SAndroid Build Coastguard Worker * subclasses. It does not affect the areFieldsInSync, isTimeSet, or areAllFieldsSet
1589*0e209d39SAndroid Build Coastguard Worker * flags.
1590*0e209d39SAndroid Build Coastguard Worker *
1591*0e209d39SAndroid Build Coastguard Worker * @param field The given time field.
1592*0e209d39SAndroid Build Coastguard Worker * @param value The value for the given time field.
1593*0e209d39SAndroid Build Coastguard Worker * @deprecated ICU 2.6. Use internalSet(UCalendarDateFields field, int32_t value) instead.
1594*0e209d39SAndroid Build Coastguard Worker */
1595*0e209d39SAndroid Build Coastguard Worker void internalSet(EDateFields field, int32_t value);
1596*0e209d39SAndroid Build Coastguard Worker #endif /* U_HIDE_DEPRECATED_API */
1597*0e209d39SAndroid Build Coastguard Worker
1598*0e209d39SAndroid Build Coastguard Worker /**
1599*0e209d39SAndroid Build Coastguard Worker * Sets the value for a given time field. This is a fast internal method for
1600*0e209d39SAndroid Build Coastguard Worker * subclasses. It does not affect the areFieldsInSync, isTimeSet, or areAllFieldsSet
1601*0e209d39SAndroid Build Coastguard Worker * flags.
1602*0e209d39SAndroid Build Coastguard Worker *
1603*0e209d39SAndroid Build Coastguard Worker * @param field The given time field.
1604*0e209d39SAndroid Build Coastguard Worker * @param value The value for the given time field.
1605*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.6.
1606*0e209d39SAndroid Build Coastguard Worker */
1607*0e209d39SAndroid Build Coastguard Worker inline void internalSet(UCalendarDateFields field, int32_t value);
1608*0e209d39SAndroid Build Coastguard Worker
1609*0e209d39SAndroid Build Coastguard Worker /**
1610*0e209d39SAndroid Build Coastguard Worker * Prepare this calendar for computing the actual minimum or maximum.
1611*0e209d39SAndroid Build Coastguard Worker * This method modifies this calendar's fields; it is called on a
1612*0e209d39SAndroid Build Coastguard Worker * temporary calendar.
1613*0e209d39SAndroid Build Coastguard Worker * @internal
1614*0e209d39SAndroid Build Coastguard Worker */
1615*0e209d39SAndroid Build Coastguard Worker virtual void prepareGetActual(UCalendarDateFields field, UBool isMinimum, UErrorCode &status);
1616*0e209d39SAndroid Build Coastguard Worker
1617*0e209d39SAndroid Build Coastguard Worker /**
1618*0e209d39SAndroid Build Coastguard Worker * Limit enums. Not in sync with UCalendarLimitType (refers to internal fields).
1619*0e209d39SAndroid Build Coastguard Worker * @internal
1620*0e209d39SAndroid Build Coastguard Worker */
1621*0e209d39SAndroid Build Coastguard Worker enum ELimitType {
1622*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_INTERNAL_API
1623*0e209d39SAndroid Build Coastguard Worker UCAL_LIMIT_MINIMUM = 0,
1624*0e209d39SAndroid Build Coastguard Worker UCAL_LIMIT_GREATEST_MINIMUM,
1625*0e209d39SAndroid Build Coastguard Worker UCAL_LIMIT_LEAST_MAXIMUM,
1626*0e209d39SAndroid Build Coastguard Worker UCAL_LIMIT_MAXIMUM,
1627*0e209d39SAndroid Build Coastguard Worker UCAL_LIMIT_COUNT
1628*0e209d39SAndroid Build Coastguard Worker #endif /* U_HIDE_INTERNAL_API */
1629*0e209d39SAndroid Build Coastguard Worker };
1630*0e209d39SAndroid Build Coastguard Worker
1631*0e209d39SAndroid Build Coastguard Worker /**
1632*0e209d39SAndroid Build Coastguard Worker * Subclass API for defining limits of different types.
1633*0e209d39SAndroid Build Coastguard Worker * Subclasses must implement this method to return limits for the
1634*0e209d39SAndroid Build Coastguard Worker * following fields:
1635*0e209d39SAndroid Build Coastguard Worker *
1636*0e209d39SAndroid Build Coastguard Worker * <pre>UCAL_ERA
1637*0e209d39SAndroid Build Coastguard Worker * UCAL_YEAR
1638*0e209d39SAndroid Build Coastguard Worker * UCAL_MONTH
1639*0e209d39SAndroid Build Coastguard Worker * UCAL_WEEK_OF_YEAR
1640*0e209d39SAndroid Build Coastguard Worker * UCAL_WEEK_OF_MONTH
1641*0e209d39SAndroid Build Coastguard Worker * UCAL_DATE (DAY_OF_MONTH on Java)
1642*0e209d39SAndroid Build Coastguard Worker * UCAL_DAY_OF_YEAR
1643*0e209d39SAndroid Build Coastguard Worker * UCAL_DAY_OF_WEEK_IN_MONTH
1644*0e209d39SAndroid Build Coastguard Worker * UCAL_YEAR_WOY
1645*0e209d39SAndroid Build Coastguard Worker * UCAL_EXTENDED_YEAR</pre>
1646*0e209d39SAndroid Build Coastguard Worker *
1647*0e209d39SAndroid Build Coastguard Worker * @param field one of the above field numbers
1648*0e209d39SAndroid Build Coastguard Worker * @param limitType one of <code>MINIMUM</code>, <code>GREATEST_MINIMUM</code>,
1649*0e209d39SAndroid Build Coastguard Worker * <code>LEAST_MAXIMUM</code>, or <code>MAXIMUM</code>
1650*0e209d39SAndroid Build Coastguard Worker * @internal
1651*0e209d39SAndroid Build Coastguard Worker */
1652*0e209d39SAndroid Build Coastguard Worker virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const = 0;
1653*0e209d39SAndroid Build Coastguard Worker
1654*0e209d39SAndroid Build Coastguard Worker /**
1655*0e209d39SAndroid Build Coastguard Worker * Return a limit for a field.
1656*0e209d39SAndroid Build Coastguard Worker * @param field the field, from <code>0..UCAL_MAX_FIELD</code>
1657*0e209d39SAndroid Build Coastguard Worker * @param limitType the type specifier for the limit
1658*0e209d39SAndroid Build Coastguard Worker * @see #ELimitType
1659*0e209d39SAndroid Build Coastguard Worker * @internal
1660*0e209d39SAndroid Build Coastguard Worker */
1661*0e209d39SAndroid Build Coastguard Worker virtual int32_t getLimit(UCalendarDateFields field, ELimitType limitType) const;
1662*0e209d39SAndroid Build Coastguard Worker
1663*0e209d39SAndroid Build Coastguard Worker /**
1664*0e209d39SAndroid Build Coastguard Worker * Return the Julian day number of day before the first day of the
1665*0e209d39SAndroid Build Coastguard Worker * given month in the given extended year. Subclasses should override
1666*0e209d39SAndroid Build Coastguard Worker * this method to implement their calendar system.
1667*0e209d39SAndroid Build Coastguard Worker * @param eyear the extended year
1668*0e209d39SAndroid Build Coastguard Worker * @param month the zero-based month, or 0 if useMonth is false
1669*0e209d39SAndroid Build Coastguard Worker * @param useMonth if false, compute the day before the first day of
1670*0e209d39SAndroid Build Coastguard Worker * the given year, otherwise, compute the day before the first day of
1671*0e209d39SAndroid Build Coastguard Worker * the given month
1672*0e209d39SAndroid Build Coastguard Worker * @param status Output param set to failure code on function return
1673*0e209d39SAndroid Build Coastguard Worker * when this function fails.
1674*0e209d39SAndroid Build Coastguard Worker * @return the Julian day number of the day before the first
1675*0e209d39SAndroid Build Coastguard Worker * day of the given month and year
1676*0e209d39SAndroid Build Coastguard Worker * @internal
1677*0e209d39SAndroid Build Coastguard Worker */
1678*0e209d39SAndroid Build Coastguard Worker virtual int64_t handleComputeMonthStart(int32_t eyear, int32_t month,
1679*0e209d39SAndroid Build Coastguard Worker UBool useMonth, UErrorCode& status) const = 0;
1680*0e209d39SAndroid Build Coastguard Worker
1681*0e209d39SAndroid Build Coastguard Worker /**
1682*0e209d39SAndroid Build Coastguard Worker * Return the number of days in the given month of the given extended
1683*0e209d39SAndroid Build Coastguard Worker * year of this calendar system. Subclasses should override this
1684*0e209d39SAndroid Build Coastguard Worker * method if they can provide a more correct or more efficient
1685*0e209d39SAndroid Build Coastguard Worker * implementation than the default implementation in Calendar.
1686*0e209d39SAndroid Build Coastguard Worker * @internal
1687*0e209d39SAndroid Build Coastguard Worker */
1688*0e209d39SAndroid Build Coastguard Worker virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month, UErrorCode& status) const ;
1689*0e209d39SAndroid Build Coastguard Worker
1690*0e209d39SAndroid Build Coastguard Worker /**
1691*0e209d39SAndroid Build Coastguard Worker * Return the number of days in the given extended year of this
1692*0e209d39SAndroid Build Coastguard Worker * calendar system. Subclasses should override this method if they can
1693*0e209d39SAndroid Build Coastguard Worker * provide a more correct or more efficient implementation than the
1694*0e209d39SAndroid Build Coastguard Worker * default implementation in Calendar.
1695*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1696*0e209d39SAndroid Build Coastguard Worker */
1697*0e209d39SAndroid Build Coastguard Worker virtual int32_t handleGetYearLength(int32_t eyear) const;
1698*0e209d39SAndroid Build Coastguard Worker
1699*0e209d39SAndroid Build Coastguard Worker
1700*0e209d39SAndroid Build Coastguard Worker /**
1701*0e209d39SAndroid Build Coastguard Worker * Return the extended year defined by the current fields. This will
1702*0e209d39SAndroid Build Coastguard Worker * use the UCAL_EXTENDED_YEAR field or the UCAL_YEAR and supra-year fields (such
1703*0e209d39SAndroid Build Coastguard Worker * as UCAL_ERA) specific to the calendar system, depending on which set of
1704*0e209d39SAndroid Build Coastguard Worker * fields is newer.
1705*0e209d39SAndroid Build Coastguard Worker * @param status ICU Error Code
1706*0e209d39SAndroid Build Coastguard Worker * @return the extended year
1707*0e209d39SAndroid Build Coastguard Worker * @internal
1708*0e209d39SAndroid Build Coastguard Worker */
1709*0e209d39SAndroid Build Coastguard Worker virtual int32_t handleGetExtendedYear(UErrorCode& status) = 0;
1710*0e209d39SAndroid Build Coastguard Worker
1711*0e209d39SAndroid Build Coastguard Worker /**
1712*0e209d39SAndroid Build Coastguard Worker * Subclasses may override this. This method calls
1713*0e209d39SAndroid Build Coastguard Worker * handleGetMonthLength() to obtain the calendar-specific month
1714*0e209d39SAndroid Build Coastguard Worker * length.
1715*0e209d39SAndroid Build Coastguard Worker * @param bestField which field to use to calculate the date
1716*0e209d39SAndroid Build Coastguard Worker * @param status ICU Error Code
1717*0e209d39SAndroid Build Coastguard Worker * @return julian day specified by calendar fields.
1718*0e209d39SAndroid Build Coastguard Worker * @internal
1719*0e209d39SAndroid Build Coastguard Worker */
1720*0e209d39SAndroid Build Coastguard Worker virtual int32_t handleComputeJulianDay(UCalendarDateFields bestField, UErrorCode &status);
1721*0e209d39SAndroid Build Coastguard Worker
1722*0e209d39SAndroid Build Coastguard Worker /**
1723*0e209d39SAndroid Build Coastguard Worker * Subclasses must override this to convert from week fields
1724*0e209d39SAndroid Build Coastguard Worker * (YEAR_WOY and WEEK_OF_YEAR) to an extended year in the case
1725*0e209d39SAndroid Build Coastguard Worker * where YEAR, EXTENDED_YEAR are not set.
1726*0e209d39SAndroid Build Coastguard Worker * The Calendar implementation assumes yearWoy is in extended gregorian form
1727*0e209d39SAndroid Build Coastguard Worker * @return the extended year, UCAL_EXTENDED_YEAR
1728*0e209d39SAndroid Build Coastguard Worker * @internal
1729*0e209d39SAndroid Build Coastguard Worker */
1730*0e209d39SAndroid Build Coastguard Worker virtual int32_t handleGetExtendedYearFromWeekFields(int32_t yearWoy, int32_t woy, UErrorCode& status);
1731*0e209d39SAndroid Build Coastguard Worker
1732*0e209d39SAndroid Build Coastguard Worker /**
1733*0e209d39SAndroid Build Coastguard Worker * Validate a single field of this calendar. Subclasses should
1734*0e209d39SAndroid Build Coastguard Worker * override this method to validate any calendar-specific fields.
1735*0e209d39SAndroid Build Coastguard Worker * Generic fields can be handled by `Calendar::validateField()`.
1736*0e209d39SAndroid Build Coastguard Worker * @internal
1737*0e209d39SAndroid Build Coastguard Worker */
1738*0e209d39SAndroid Build Coastguard Worker virtual void validateField(UCalendarDateFields field, UErrorCode &status);
1739*0e209d39SAndroid Build Coastguard Worker
1740*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_INTERNAL_API
1741*0e209d39SAndroid Build Coastguard Worker /**
1742*0e209d39SAndroid Build Coastguard Worker * Compute the Julian day from fields. Will determine whether to use
1743*0e209d39SAndroid Build Coastguard Worker * the JULIAN_DAY field directly, or other fields.
1744*0e209d39SAndroid Build Coastguard Worker * @param status ICU Error Code
1745*0e209d39SAndroid Build Coastguard Worker * @return the julian day
1746*0e209d39SAndroid Build Coastguard Worker * @internal
1747*0e209d39SAndroid Build Coastguard Worker */
1748*0e209d39SAndroid Build Coastguard Worker int32_t computeJulianDay(UErrorCode &status);
1749*0e209d39SAndroid Build Coastguard Worker
1750*0e209d39SAndroid Build Coastguard Worker /**
1751*0e209d39SAndroid Build Coastguard Worker * Compute the milliseconds in the day from the fields. This is a
1752*0e209d39SAndroid Build Coastguard Worker * value from 0 to 23:59:59.999 inclusive, unless fields are out of
1753*0e209d39SAndroid Build Coastguard Worker * range, in which case it can be an arbitrary value. This value
1754*0e209d39SAndroid Build Coastguard Worker * reflects local zone wall time.
1755*0e209d39SAndroid Build Coastguard Worker * @internal
1756*0e209d39SAndroid Build Coastguard Worker */
1757*0e209d39SAndroid Build Coastguard Worker double computeMillisInDay();
1758*0e209d39SAndroid Build Coastguard Worker
1759*0e209d39SAndroid Build Coastguard Worker /**
1760*0e209d39SAndroid Build Coastguard Worker * This method can assume EXTENDED_YEAR has been set.
1761*0e209d39SAndroid Build Coastguard Worker * @param millis milliseconds of the date fields
1762*0e209d39SAndroid Build Coastguard Worker * @param millisInDay milliseconds of the time fields; may be out
1763*0e209d39SAndroid Build Coastguard Worker * or range.
1764*0e209d39SAndroid Build Coastguard Worker * @param ec Output param set to failure code on function return
1765*0e209d39SAndroid Build Coastguard Worker * when this function fails.
1766*0e209d39SAndroid Build Coastguard Worker * @internal
1767*0e209d39SAndroid Build Coastguard Worker */
1768*0e209d39SAndroid Build Coastguard Worker int32_t computeZoneOffset(double millis, double millisInDay, UErrorCode &ec);
1769*0e209d39SAndroid Build Coastguard Worker
1770*0e209d39SAndroid Build Coastguard Worker
1771*0e209d39SAndroid Build Coastguard Worker /**
1772*0e209d39SAndroid Build Coastguard Worker * Determine the best stamp in a range.
1773*0e209d39SAndroid Build Coastguard Worker * @param start first enum to look at
1774*0e209d39SAndroid Build Coastguard Worker * @param end last enum to look at
1775*0e209d39SAndroid Build Coastguard Worker * @param bestSoFar stamp prior to function call
1776*0e209d39SAndroid Build Coastguard Worker * @return the stamp value of the best stamp
1777*0e209d39SAndroid Build Coastguard Worker * @internal
1778*0e209d39SAndroid Build Coastguard Worker */
1779*0e209d39SAndroid Build Coastguard Worker int32_t newestStamp(UCalendarDateFields start, UCalendarDateFields end, int32_t bestSoFar) const;
1780*0e209d39SAndroid Build Coastguard Worker
1781*0e209d39SAndroid Build Coastguard Worker /**
1782*0e209d39SAndroid Build Coastguard Worker * Marker for end of resolve set (row or group). Value for field resolution tables.
1783*0e209d39SAndroid Build Coastguard Worker *
1784*0e209d39SAndroid Build Coastguard Worker * @see #resolveFields
1785*0e209d39SAndroid Build Coastguard Worker * @internal
1786*0e209d39SAndroid Build Coastguard Worker */
1787*0e209d39SAndroid Build Coastguard Worker static constexpr int32_t kResolveSTOP = -1;
1788*0e209d39SAndroid Build Coastguard Worker /**
1789*0e209d39SAndroid Build Coastguard Worker * Value to be bitwised "ORed" against resolve table field values for remapping.
1790*0e209d39SAndroid Build Coastguard Worker * Example: (UCAL_DATE | kResolveRemap) in 1st column will cause 'UCAL_DATE' to be returned,
1791*0e209d39SAndroid Build Coastguard Worker * but will not examine the value of UCAL_DATE.
1792*0e209d39SAndroid Build Coastguard Worker * Value for field resolution tables.
1793*0e209d39SAndroid Build Coastguard Worker *
1794*0e209d39SAndroid Build Coastguard Worker * @see #resolveFields
1795*0e209d39SAndroid Build Coastguard Worker * @internal
1796*0e209d39SAndroid Build Coastguard Worker */
1797*0e209d39SAndroid Build Coastguard Worker static constexpr int32_t kResolveRemap = 32;
1798*0e209d39SAndroid Build Coastguard Worker
1799*0e209d39SAndroid Build Coastguard Worker /**
1800*0e209d39SAndroid Build Coastguard Worker * Precedence table for Dates
1801*0e209d39SAndroid Build Coastguard Worker * @see #resolveFields
1802*0e209d39SAndroid Build Coastguard Worker * @internal
1803*0e209d39SAndroid Build Coastguard Worker */
1804*0e209d39SAndroid Build Coastguard Worker static const UFieldResolutionTable kDatePrecedence[];
1805*0e209d39SAndroid Build Coastguard Worker
1806*0e209d39SAndroid Build Coastguard Worker /**
1807*0e209d39SAndroid Build Coastguard Worker * Precedence table for Year
1808*0e209d39SAndroid Build Coastguard Worker * @see #resolveFields
1809*0e209d39SAndroid Build Coastguard Worker * @internal
1810*0e209d39SAndroid Build Coastguard Worker */
1811*0e209d39SAndroid Build Coastguard Worker static const UFieldResolutionTable kYearPrecedence[];
1812*0e209d39SAndroid Build Coastguard Worker
1813*0e209d39SAndroid Build Coastguard Worker /**
1814*0e209d39SAndroid Build Coastguard Worker * Precedence table for Day of Week
1815*0e209d39SAndroid Build Coastguard Worker * @see #resolveFields
1816*0e209d39SAndroid Build Coastguard Worker * @internal
1817*0e209d39SAndroid Build Coastguard Worker */
1818*0e209d39SAndroid Build Coastguard Worker static const UFieldResolutionTable kDOWPrecedence[];
1819*0e209d39SAndroid Build Coastguard Worker
1820*0e209d39SAndroid Build Coastguard Worker /**
1821*0e209d39SAndroid Build Coastguard Worker * Precedence table for Months
1822*0e209d39SAndroid Build Coastguard Worker * @see #resolveFields
1823*0e209d39SAndroid Build Coastguard Worker * @internal
1824*0e209d39SAndroid Build Coastguard Worker */
1825*0e209d39SAndroid Build Coastguard Worker static const UFieldResolutionTable kMonthPrecedence[];
1826*0e209d39SAndroid Build Coastguard Worker
1827*0e209d39SAndroid Build Coastguard Worker /**
1828*0e209d39SAndroid Build Coastguard Worker * Given a precedence table, return the newest field combination in
1829*0e209d39SAndroid Build Coastguard Worker * the table, or UCAL_FIELD_COUNT if none is found.
1830*0e209d39SAndroid Build Coastguard Worker *
1831*0e209d39SAndroid Build Coastguard Worker * <p>The precedence table is a 3-dimensional array of integers. It
1832*0e209d39SAndroid Build Coastguard Worker * may be thought of as an array of groups. Each group is an array of
1833*0e209d39SAndroid Build Coastguard Worker * lines. Each line is an array of field numbers. Within a line, if
1834*0e209d39SAndroid Build Coastguard Worker * all fields are set, then the time stamp of the line is taken to be
1835*0e209d39SAndroid Build Coastguard Worker * the stamp of the most recently set field. If any field of a line is
1836*0e209d39SAndroid Build Coastguard Worker * unset, then the line fails to match. Within a group, the line with
1837*0e209d39SAndroid Build Coastguard Worker * the newest time stamp is selected. The first field of the line is
1838*0e209d39SAndroid Build Coastguard Worker * returned to indicate which line matched.
1839*0e209d39SAndroid Build Coastguard Worker *
1840*0e209d39SAndroid Build Coastguard Worker * <p>In some cases, it may be desirable to map a line to field that
1841*0e209d39SAndroid Build Coastguard Worker * whose stamp is NOT examined. For example, if the best field is
1842*0e209d39SAndroid Build Coastguard Worker * DAY_OF_WEEK then the DAY_OF_WEEK_IN_MONTH algorithm may be used. In
1843*0e209d39SAndroid Build Coastguard Worker * order to do this, insert the value <code>kResolveRemap | F</code> at
1844*0e209d39SAndroid Build Coastguard Worker * the start of the line, where <code>F</code> is the desired return
1845*0e209d39SAndroid Build Coastguard Worker * field value. This field will NOT be examined; it only determines
1846*0e209d39SAndroid Build Coastguard Worker * the return value if the other fields in the line are the newest.
1847*0e209d39SAndroid Build Coastguard Worker *
1848*0e209d39SAndroid Build Coastguard Worker * <p>If all lines of a group contain at least one unset field, then no
1849*0e209d39SAndroid Build Coastguard Worker * line will match, and the group as a whole will fail to match. In
1850*0e209d39SAndroid Build Coastguard Worker * that case, the next group will be processed. If all groups fail to
1851*0e209d39SAndroid Build Coastguard Worker * match, then UCAL_FIELD_COUNT is returned.
1852*0e209d39SAndroid Build Coastguard Worker * @internal
1853*0e209d39SAndroid Build Coastguard Worker */
1854*0e209d39SAndroid Build Coastguard Worker UCalendarDateFields resolveFields(const UFieldResolutionTable *precedenceTable) const;
1855*0e209d39SAndroid Build Coastguard Worker #endif /* U_HIDE_INTERNAL_API */
1856*0e209d39SAndroid Build Coastguard Worker
1857*0e209d39SAndroid Build Coastguard Worker
1858*0e209d39SAndroid Build Coastguard Worker /**
1859*0e209d39SAndroid Build Coastguard Worker * @internal
1860*0e209d39SAndroid Build Coastguard Worker */
1861*0e209d39SAndroid Build Coastguard Worker virtual const UFieldResolutionTable* getFieldResolutionTable() const;
1862*0e209d39SAndroid Build Coastguard Worker
1863*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_INTERNAL_API
1864*0e209d39SAndroid Build Coastguard Worker /**
1865*0e209d39SAndroid Build Coastguard Worker * Return the field that is newer, either defaultField, or
1866*0e209d39SAndroid Build Coastguard Worker * alternateField. If neither is newer or neither is set, return defaultField.
1867*0e209d39SAndroid Build Coastguard Worker * @internal
1868*0e209d39SAndroid Build Coastguard Worker */
1869*0e209d39SAndroid Build Coastguard Worker UCalendarDateFields newerField(UCalendarDateFields defaultField, UCalendarDateFields alternateField) const;
1870*0e209d39SAndroid Build Coastguard Worker #endif /* U_HIDE_INTERNAL_API */
1871*0e209d39SAndroid Build Coastguard Worker
1872*0e209d39SAndroid Build Coastguard Worker
1873*0e209d39SAndroid Build Coastguard Worker private:
1874*0e209d39SAndroid Build Coastguard Worker /**
1875*0e209d39SAndroid Build Coastguard Worker * Helper function for calculating limits by trial and error
1876*0e209d39SAndroid Build Coastguard Worker * @param field The field being investigated
1877*0e209d39SAndroid Build Coastguard Worker * @param startValue starting (least max) value of field
1878*0e209d39SAndroid Build Coastguard Worker * @param endValue ending (greatest max) value of field
1879*0e209d39SAndroid Build Coastguard Worker * @param status return type
1880*0e209d39SAndroid Build Coastguard Worker * @internal (private)
1881*0e209d39SAndroid Build Coastguard Worker */
1882*0e209d39SAndroid Build Coastguard Worker int32_t getActualHelper(UCalendarDateFields field, int32_t startValue, int32_t endValue, UErrorCode &status) const;
1883*0e209d39SAndroid Build Coastguard Worker
1884*0e209d39SAndroid Build Coastguard Worker
1885*0e209d39SAndroid Build Coastguard Worker protected:
1886*0e209d39SAndroid Build Coastguard Worker /**
1887*0e209d39SAndroid Build Coastguard Worker * The flag which indicates if the current time is set in the calendar.
1888*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1889*0e209d39SAndroid Build Coastguard Worker */
1890*0e209d39SAndroid Build Coastguard Worker UBool fIsTimeSet;
1891*0e209d39SAndroid Build Coastguard Worker
1892*0e209d39SAndroid Build Coastguard Worker /**
1893*0e209d39SAndroid Build Coastguard Worker * True if the fields are in sync with the currently set time of this Calendar.
1894*0e209d39SAndroid Build Coastguard Worker * If false, then the next attempt to get the value of a field will
1895*0e209d39SAndroid Build Coastguard Worker * force a recomputation of all fields from the current value of the time
1896*0e209d39SAndroid Build Coastguard Worker * field.
1897*0e209d39SAndroid Build Coastguard Worker * <P>
1898*0e209d39SAndroid Build Coastguard Worker * This should really be named areFieldsInSync, but the old name is retained
1899*0e209d39SAndroid Build Coastguard Worker * for backward compatibility.
1900*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1901*0e209d39SAndroid Build Coastguard Worker */
1902*0e209d39SAndroid Build Coastguard Worker UBool fAreFieldsSet;
1903*0e209d39SAndroid Build Coastguard Worker
1904*0e209d39SAndroid Build Coastguard Worker /**
1905*0e209d39SAndroid Build Coastguard Worker * True if all of the fields have been set. This is initially false, and set to
1906*0e209d39SAndroid Build Coastguard Worker * true by computeFields().
1907*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1908*0e209d39SAndroid Build Coastguard Worker */
1909*0e209d39SAndroid Build Coastguard Worker UBool fAreAllFieldsSet;
1910*0e209d39SAndroid Build Coastguard Worker
1911*0e209d39SAndroid Build Coastguard Worker /**
1912*0e209d39SAndroid Build Coastguard Worker * True if all fields have been virtually set, but have not yet been
1913*0e209d39SAndroid Build Coastguard Worker * computed. This occurs only in setTimeInMillis(). A calendar set
1914*0e209d39SAndroid Build Coastguard Worker * to this state will compute all fields from the time if it becomes
1915*0e209d39SAndroid Build Coastguard Worker * necessary, but otherwise will delay such computation.
1916*0e209d39SAndroid Build Coastguard Worker * @stable ICU 3.0
1917*0e209d39SAndroid Build Coastguard Worker */
1918*0e209d39SAndroid Build Coastguard Worker UBool fAreFieldsVirtuallySet;
1919*0e209d39SAndroid Build Coastguard Worker
1920*0e209d39SAndroid Build Coastguard Worker /**
1921*0e209d39SAndroid Build Coastguard Worker * Get the current time without recomputing.
1922*0e209d39SAndroid Build Coastguard Worker *
1923*0e209d39SAndroid Build Coastguard Worker * @return the current time without recomputing.
1924*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1925*0e209d39SAndroid Build Coastguard Worker */
internalGetTime()1926*0e209d39SAndroid Build Coastguard Worker UDate internalGetTime() const { return fTime; }
1927*0e209d39SAndroid Build Coastguard Worker
1928*0e209d39SAndroid Build Coastguard Worker /**
1929*0e209d39SAndroid Build Coastguard Worker * Set the current time without affecting flags or fields.
1930*0e209d39SAndroid Build Coastguard Worker *
1931*0e209d39SAndroid Build Coastguard Worker * @param time The time to be set
1932*0e209d39SAndroid Build Coastguard Worker * @return the current time without recomputing.
1933*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1934*0e209d39SAndroid Build Coastguard Worker */
internalSetTime(UDate time)1935*0e209d39SAndroid Build Coastguard Worker void internalSetTime(UDate time) { fTime = time; }
1936*0e209d39SAndroid Build Coastguard Worker
1937*0e209d39SAndroid Build Coastguard Worker /**
1938*0e209d39SAndroid Build Coastguard Worker * The time fields containing values into which the millis is computed.
1939*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1940*0e209d39SAndroid Build Coastguard Worker */
1941*0e209d39SAndroid Build Coastguard Worker int32_t fFields[UCAL_FIELD_COUNT];
1942*0e209d39SAndroid Build Coastguard Worker
1943*0e209d39SAndroid Build Coastguard Worker #ifndef U_FORCE_HIDE_DEPRECATED_API
1944*0e209d39SAndroid Build Coastguard Worker /**
1945*0e209d39SAndroid Build Coastguard Worker * The flags which tell if a specified time field for the calendar is set.
1946*0e209d39SAndroid Build Coastguard Worker * @deprecated ICU 2.8 use (fStamp[n]!=kUnset)
1947*0e209d39SAndroid Build Coastguard Worker */
1948*0e209d39SAndroid Build Coastguard Worker UBool fIsSet[UCAL_FIELD_COUNT];
1949*0e209d39SAndroid Build Coastguard Worker #endif // U_FORCE_HIDE_DEPRECATED_API
1950*0e209d39SAndroid Build Coastguard Worker
1951*0e209d39SAndroid Build Coastguard Worker /** Special values of stamp[]
1952*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1953*0e209d39SAndroid Build Coastguard Worker */
1954*0e209d39SAndroid Build Coastguard Worker enum {
1955*0e209d39SAndroid Build Coastguard Worker kUnset = 0,
1956*0e209d39SAndroid Build Coastguard Worker kInternallySet,
1957*0e209d39SAndroid Build Coastguard Worker kMinimumUserStamp
1958*0e209d39SAndroid Build Coastguard Worker };
1959*0e209d39SAndroid Build Coastguard Worker
1960*0e209d39SAndroid Build Coastguard Worker /**
1961*0e209d39SAndroid Build Coastguard Worker * Pseudo-time-stamps which specify when each field was set. There
1962*0e209d39SAndroid Build Coastguard Worker * are two special values, UNSET and INTERNALLY_SET. Values from
1963*0e209d39SAndroid Build Coastguard Worker * MINIMUM_USER_SET to Integer.MAX_VALUE are legal user set values.
1964*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
1965*0e209d39SAndroid Build Coastguard Worker */
1966*0e209d39SAndroid Build Coastguard Worker int32_t fStamp[UCAL_FIELD_COUNT];
1967*0e209d39SAndroid Build Coastguard Worker
1968*0e209d39SAndroid Build Coastguard Worker /**
1969*0e209d39SAndroid Build Coastguard Worker * Subclasses may override this method to compute several fields
1970*0e209d39SAndroid Build Coastguard Worker * specific to each calendar system. These are:
1971*0e209d39SAndroid Build Coastguard Worker *
1972*0e209d39SAndroid Build Coastguard Worker * <ul><li>ERA
1973*0e209d39SAndroid Build Coastguard Worker * <li>YEAR
1974*0e209d39SAndroid Build Coastguard Worker * <li>MONTH
1975*0e209d39SAndroid Build Coastguard Worker * <li>DAY_OF_MONTH
1976*0e209d39SAndroid Build Coastguard Worker * <li>DAY_OF_YEAR
1977*0e209d39SAndroid Build Coastguard Worker * <li>EXTENDED_YEAR</ul>
1978*0e209d39SAndroid Build Coastguard Worker *
1979*0e209d39SAndroid Build Coastguard Worker * Subclasses can refer to the DAY_OF_WEEK and DOW_LOCAL fields, which
1980*0e209d39SAndroid Build Coastguard Worker * will be set when this method is called. Subclasses can also call
1981*0e209d39SAndroid Build Coastguard Worker * the getGregorianXxx() methods to obtain Gregorian calendar
1982*0e209d39SAndroid Build Coastguard Worker * equivalents for the given Julian day.
1983*0e209d39SAndroid Build Coastguard Worker *
1984*0e209d39SAndroid Build Coastguard Worker * <p>In addition, subclasses should compute any subclass-specific
1985*0e209d39SAndroid Build Coastguard Worker * fields, that is, fields from BASE_FIELD_COUNT to
1986*0e209d39SAndroid Build Coastguard Worker * getFieldCount() - 1.
1987*0e209d39SAndroid Build Coastguard Worker *
1988*0e209d39SAndroid Build Coastguard Worker * <p>The default implementation in <code>Calendar</code> implements
1989*0e209d39SAndroid Build Coastguard Worker * a pure proleptic Gregorian calendar.
1990*0e209d39SAndroid Build Coastguard Worker * @internal
1991*0e209d39SAndroid Build Coastguard Worker */
1992*0e209d39SAndroid Build Coastguard Worker virtual void handleComputeFields(int32_t julianDay, UErrorCode &status);
1993*0e209d39SAndroid Build Coastguard Worker
1994*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_INTERNAL_API
1995*0e209d39SAndroid Build Coastguard Worker /**
1996*0e209d39SAndroid Build Coastguard Worker * Return the extended year on the Gregorian calendar as computed by
1997*0e209d39SAndroid Build Coastguard Worker * <code>computeGregorianFields()</code>.
1998*0e209d39SAndroid Build Coastguard Worker * @internal
1999*0e209d39SAndroid Build Coastguard Worker */
getGregorianYear()2000*0e209d39SAndroid Build Coastguard Worker int32_t getGregorianYear() const {
2001*0e209d39SAndroid Build Coastguard Worker return fGregorianYear;
2002*0e209d39SAndroid Build Coastguard Worker }
2003*0e209d39SAndroid Build Coastguard Worker
2004*0e209d39SAndroid Build Coastguard Worker /**
2005*0e209d39SAndroid Build Coastguard Worker * Return the month (0-based) on the Gregorian calendar as computed by
2006*0e209d39SAndroid Build Coastguard Worker * <code>computeGregorianFields()</code>.
2007*0e209d39SAndroid Build Coastguard Worker * @internal
2008*0e209d39SAndroid Build Coastguard Worker */
getGregorianMonth()2009*0e209d39SAndroid Build Coastguard Worker int32_t getGregorianMonth() const {
2010*0e209d39SAndroid Build Coastguard Worker return fGregorianMonth;
2011*0e209d39SAndroid Build Coastguard Worker }
2012*0e209d39SAndroid Build Coastguard Worker
2013*0e209d39SAndroid Build Coastguard Worker /**
2014*0e209d39SAndroid Build Coastguard Worker * Return the day of year (1-based) on the Gregorian calendar as
2015*0e209d39SAndroid Build Coastguard Worker * computed by <code>computeGregorianFields()</code>.
2016*0e209d39SAndroid Build Coastguard Worker * @internal
2017*0e209d39SAndroid Build Coastguard Worker */
getGregorianDayOfYear()2018*0e209d39SAndroid Build Coastguard Worker int32_t getGregorianDayOfYear() const {
2019*0e209d39SAndroid Build Coastguard Worker return fGregorianDayOfYear;
2020*0e209d39SAndroid Build Coastguard Worker }
2021*0e209d39SAndroid Build Coastguard Worker
2022*0e209d39SAndroid Build Coastguard Worker /**
2023*0e209d39SAndroid Build Coastguard Worker * Return the day of month (1-based) on the Gregorian calendar as
2024*0e209d39SAndroid Build Coastguard Worker * computed by <code>computeGregorianFields()</code>.
2025*0e209d39SAndroid Build Coastguard Worker * @internal
2026*0e209d39SAndroid Build Coastguard Worker */
getGregorianDayOfMonth()2027*0e209d39SAndroid Build Coastguard Worker int32_t getGregorianDayOfMonth() const {
2028*0e209d39SAndroid Build Coastguard Worker return fGregorianDayOfMonth;
2029*0e209d39SAndroid Build Coastguard Worker }
2030*0e209d39SAndroid Build Coastguard Worker #endif /* U_HIDE_INTERNAL_API */
2031*0e209d39SAndroid Build Coastguard Worker
2032*0e209d39SAndroid Build Coastguard Worker /**
2033*0e209d39SAndroid Build Coastguard Worker * Called by computeJulianDay. Returns the default month (0-based) for the year,
2034*0e209d39SAndroid Build Coastguard Worker * taking year and era into account. Defaults to 0 for Gregorian, which doesn't care.
2035*0e209d39SAndroid Build Coastguard Worker * @param eyear The extended year
2036*0e209d39SAndroid Build Coastguard Worker * @param status Output param set to failure code on function return
2037*0e209d39SAndroid Build Coastguard Worker * when this function fails.
2038*0e209d39SAndroid Build Coastguard Worker * @internal
2039*0e209d39SAndroid Build Coastguard Worker */
2040*0e209d39SAndroid Build Coastguard Worker virtual int32_t getDefaultMonthInYear(int32_t eyear, UErrorCode& status);
2041*0e209d39SAndroid Build Coastguard Worker
2042*0e209d39SAndroid Build Coastguard Worker
2043*0e209d39SAndroid Build Coastguard Worker /**
2044*0e209d39SAndroid Build Coastguard Worker * Called by computeJulianDay. Returns the default day (1-based) for the month,
2045*0e209d39SAndroid Build Coastguard Worker * taking currently-set year and era into account. Defaults to 1 for Gregorian.
2046*0e209d39SAndroid Build Coastguard Worker * @param eyear the extended year
2047*0e209d39SAndroid Build Coastguard Worker * @param month the month in the year
2048*0e209d39SAndroid Build Coastguard Worker * @internal
2049*0e209d39SAndroid Build Coastguard Worker */
2050*0e209d39SAndroid Build Coastguard Worker virtual int32_t getDefaultDayInMonth(int32_t eyear, int32_t month);
2051*0e209d39SAndroid Build Coastguard Worker
2052*0e209d39SAndroid Build Coastguard Worker //-------------------------------------------------------------------------
2053*0e209d39SAndroid Build Coastguard Worker // Protected utility methods for use by subclasses. These are very handy
2054*0e209d39SAndroid Build Coastguard Worker // for implementing add, roll, and computeFields.
2055*0e209d39SAndroid Build Coastguard Worker //-------------------------------------------------------------------------
2056*0e209d39SAndroid Build Coastguard Worker
2057*0e209d39SAndroid Build Coastguard Worker /**
2058*0e209d39SAndroid Build Coastguard Worker * Adjust the specified field so that it is within
2059*0e209d39SAndroid Build Coastguard Worker * the allowable range for the date to which this calendar is set.
2060*0e209d39SAndroid Build Coastguard Worker * For example, in a Gregorian calendar pinning the {@link #UCalendarDateFields DAY_OF_MONTH}
2061*0e209d39SAndroid Build Coastguard Worker * field for a calendar set to April 31 would cause it to be set
2062*0e209d39SAndroid Build Coastguard Worker * to April 30.
2063*0e209d39SAndroid Build Coastguard Worker * <p>
2064*0e209d39SAndroid Build Coastguard Worker * <b>Subclassing:</b>
2065*0e209d39SAndroid Build Coastguard Worker * <br>
2066*0e209d39SAndroid Build Coastguard Worker * This utility method is intended for use by subclasses that need to implement
2067*0e209d39SAndroid Build Coastguard Worker * their own overrides of {@link #roll roll} and {@link #add add}.
2068*0e209d39SAndroid Build Coastguard Worker * <p>
2069*0e209d39SAndroid Build Coastguard Worker * <b>Note:</b>
2070*0e209d39SAndroid Build Coastguard Worker * <code>pinField</code> is implemented in terms of
2071*0e209d39SAndroid Build Coastguard Worker * {@link #getActualMinimum getActualMinimum}
2072*0e209d39SAndroid Build Coastguard Worker * and {@link #getActualMaximum getActualMaximum}. If either of those methods uses
2073*0e209d39SAndroid Build Coastguard Worker * a slow, iterative algorithm for a particular field, it would be
2074*0e209d39SAndroid Build Coastguard Worker * unwise to attempt to call <code>pinField</code> for that field. If you
2075*0e209d39SAndroid Build Coastguard Worker * really do need to do so, you should override this method to do
2076*0e209d39SAndroid Build Coastguard Worker * something more efficient for that field.
2077*0e209d39SAndroid Build Coastguard Worker * <p>
2078*0e209d39SAndroid Build Coastguard Worker * @param field The calendar field whose value should be pinned.
2079*0e209d39SAndroid Build Coastguard Worker * @param status Output param set to failure code on function return
2080*0e209d39SAndroid Build Coastguard Worker * when this function fails.
2081*0e209d39SAndroid Build Coastguard Worker *
2082*0e209d39SAndroid Build Coastguard Worker * @see #getActualMinimum
2083*0e209d39SAndroid Build Coastguard Worker * @see #getActualMaximum
2084*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.0
2085*0e209d39SAndroid Build Coastguard Worker */
2086*0e209d39SAndroid Build Coastguard Worker virtual void pinField(UCalendarDateFields field, UErrorCode& status);
2087*0e209d39SAndroid Build Coastguard Worker
2088*0e209d39SAndroid Build Coastguard Worker /**
2089*0e209d39SAndroid Build Coastguard Worker * Return the week number of a day, within a period. This may be the week number in
2090*0e209d39SAndroid Build Coastguard Worker * a year or the week number in a month. Usually this will be a value >= 1, but if
2091*0e209d39SAndroid Build Coastguard Worker * some initial days of the period are excluded from week 1, because
2092*0e209d39SAndroid Build Coastguard Worker * {@link #getMinimalDaysInFirstWeek getMinimalDaysInFirstWeek} is > 1, then
2093*0e209d39SAndroid Build Coastguard Worker * the week number will be zero for those
2094*0e209d39SAndroid Build Coastguard Worker * initial days. This method requires the day number and day of week for some
2095*0e209d39SAndroid Build Coastguard Worker * known date in the period in order to determine the day of week
2096*0e209d39SAndroid Build Coastguard Worker * on the desired day.
2097*0e209d39SAndroid Build Coastguard Worker * <p>
2098*0e209d39SAndroid Build Coastguard Worker * <b>Subclassing:</b>
2099*0e209d39SAndroid Build Coastguard Worker * <br>
2100*0e209d39SAndroid Build Coastguard Worker * This method is intended for use by subclasses in implementing their
2101*0e209d39SAndroid Build Coastguard Worker * {@link #computeTime computeTime} and/or {@link #computeFields computeFields} methods.
2102*0e209d39SAndroid Build Coastguard Worker * It is often useful in {@link #getActualMinimum getActualMinimum} and
2103*0e209d39SAndroid Build Coastguard Worker * {@link #getActualMaximum getActualMaximum} as well.
2104*0e209d39SAndroid Build Coastguard Worker * <p>
2105*0e209d39SAndroid Build Coastguard Worker * This variant is handy for computing the week number of some other
2106*0e209d39SAndroid Build Coastguard Worker * day of a period (often the first or last day of the period) when its day
2107*0e209d39SAndroid Build Coastguard Worker * of the week is not known but the day number and day of week for some other
2108*0e209d39SAndroid Build Coastguard Worker * day in the period (e.g. the current date) <em>is</em> known.
2109*0e209d39SAndroid Build Coastguard Worker * <p>
2110*0e209d39SAndroid Build Coastguard Worker * @param desiredDay The {@link #UCalendarDateFields DAY_OF_YEAR} or
2111*0e209d39SAndroid Build Coastguard Worker * {@link #UCalendarDateFields DAY_OF_MONTH} whose week number is desired.
2112*0e209d39SAndroid Build Coastguard Worker * Should be 1 for the first day of the period.
2113*0e209d39SAndroid Build Coastguard Worker *
2114*0e209d39SAndroid Build Coastguard Worker * @param dayOfPeriod The {@link #UCalendarDateFields DAY_OF_YEAR}
2115*0e209d39SAndroid Build Coastguard Worker * or {@link #UCalendarDateFields DAY_OF_MONTH} for a day in the period whose
2116*0e209d39SAndroid Build Coastguard Worker * {@link #UCalendarDateFields DAY_OF_WEEK} is specified by the
2117*0e209d39SAndroid Build Coastguard Worker * <code>knownDayOfWeek</code> parameter.
2118*0e209d39SAndroid Build Coastguard Worker * Should be 1 for first day of period.
2119*0e209d39SAndroid Build Coastguard Worker *
2120*0e209d39SAndroid Build Coastguard Worker * @param dayOfWeek The {@link #UCalendarDateFields DAY_OF_WEEK} for the day
2121*0e209d39SAndroid Build Coastguard Worker * corresponding to the <code>knownDayOfPeriod</code> parameter.
2122*0e209d39SAndroid Build Coastguard Worker * 1-based with 1=Sunday.
2123*0e209d39SAndroid Build Coastguard Worker *
2124*0e209d39SAndroid Build Coastguard Worker * @return The week number (one-based), or zero if the day falls before
2125*0e209d39SAndroid Build Coastguard Worker * the first week because
2126*0e209d39SAndroid Build Coastguard Worker * {@link #getMinimalDaysInFirstWeek getMinimalDaysInFirstWeek}
2127*0e209d39SAndroid Build Coastguard Worker * is more than one.
2128*0e209d39SAndroid Build Coastguard Worker *
2129*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.8
2130*0e209d39SAndroid Build Coastguard Worker */
2131*0e209d39SAndroid Build Coastguard Worker int32_t weekNumber(int32_t desiredDay, int32_t dayOfPeriod, int32_t dayOfWeek);
2132*0e209d39SAndroid Build Coastguard Worker
2133*0e209d39SAndroid Build Coastguard Worker
2134*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_INTERNAL_API
2135*0e209d39SAndroid Build Coastguard Worker /**
2136*0e209d39SAndroid Build Coastguard Worker * Return the week number of a day, within a period. This may be the week number in
2137*0e209d39SAndroid Build Coastguard Worker * a year, or the week number in a month. Usually this will be a value >= 1, but if
2138*0e209d39SAndroid Build Coastguard Worker * some initial days of the period are excluded from week 1, because
2139*0e209d39SAndroid Build Coastguard Worker * {@link #getMinimalDaysInFirstWeek getMinimalDaysInFirstWeek} is > 1,
2140*0e209d39SAndroid Build Coastguard Worker * then the week number will be zero for those
2141*0e209d39SAndroid Build Coastguard Worker * initial days. This method requires the day of week for the given date in order to
2142*0e209d39SAndroid Build Coastguard Worker * determine the result.
2143*0e209d39SAndroid Build Coastguard Worker * <p>
2144*0e209d39SAndroid Build Coastguard Worker * <b>Subclassing:</b>
2145*0e209d39SAndroid Build Coastguard Worker * <br>
2146*0e209d39SAndroid Build Coastguard Worker * This method is intended for use by subclasses in implementing their
2147*0e209d39SAndroid Build Coastguard Worker * {@link #computeTime computeTime} and/or {@link #computeFields computeFields} methods.
2148*0e209d39SAndroid Build Coastguard Worker * It is often useful in {@link #getActualMinimum getActualMinimum} and
2149*0e209d39SAndroid Build Coastguard Worker * {@link #getActualMaximum getActualMaximum} as well.
2150*0e209d39SAndroid Build Coastguard Worker * <p>
2151*0e209d39SAndroid Build Coastguard Worker * @param dayOfPeriod The {@link #UCalendarDateFields DAY_OF_YEAR} or
2152*0e209d39SAndroid Build Coastguard Worker * {@link #UCalendarDateFields DAY_OF_MONTH} whose week number is desired.
2153*0e209d39SAndroid Build Coastguard Worker * Should be 1 for the first day of the period.
2154*0e209d39SAndroid Build Coastguard Worker *
2155*0e209d39SAndroid Build Coastguard Worker * @param dayOfWeek The {@link #UCalendarDateFields DAY_OF_WEEK} for the day
2156*0e209d39SAndroid Build Coastguard Worker * corresponding to the <code>dayOfPeriod</code> parameter.
2157*0e209d39SAndroid Build Coastguard Worker * 1-based with 1=Sunday.
2158*0e209d39SAndroid Build Coastguard Worker *
2159*0e209d39SAndroid Build Coastguard Worker * @return The week number (one-based), or zero if the day falls before
2160*0e209d39SAndroid Build Coastguard Worker * the first week because
2161*0e209d39SAndroid Build Coastguard Worker * {@link #getMinimalDaysInFirstWeek getMinimalDaysInFirstWeek}
2162*0e209d39SAndroid Build Coastguard Worker * is more than one.
2163*0e209d39SAndroid Build Coastguard Worker * @internal
2164*0e209d39SAndroid Build Coastguard Worker */
2165*0e209d39SAndroid Build Coastguard Worker inline int32_t weekNumber(int32_t dayOfPeriod, int32_t dayOfWeek);
2166*0e209d39SAndroid Build Coastguard Worker
2167*0e209d39SAndroid Build Coastguard Worker /**
2168*0e209d39SAndroid Build Coastguard Worker * returns the local DOW, valid range 0..6
2169*0e209d39SAndroid Build Coastguard Worker * @internal
2170*0e209d39SAndroid Build Coastguard Worker */
2171*0e209d39SAndroid Build Coastguard Worker int32_t getLocalDOW(UErrorCode& status);
2172*0e209d39SAndroid Build Coastguard Worker #endif /* U_HIDE_INTERNAL_API */
2173*0e209d39SAndroid Build Coastguard Worker
2174*0e209d39SAndroid Build Coastguard Worker private:
2175*0e209d39SAndroid Build Coastguard Worker
2176*0e209d39SAndroid Build Coastguard Worker /**
2177*0e209d39SAndroid Build Coastguard Worker * The next available value for fStamp[]
2178*0e209d39SAndroid Build Coastguard Worker */
2179*0e209d39SAndroid Build Coastguard Worker int32_t fNextStamp;// = MINIMUM_USER_STAMP;
2180*0e209d39SAndroid Build Coastguard Worker
2181*0e209d39SAndroid Build Coastguard Worker /**
2182*0e209d39SAndroid Build Coastguard Worker * Recalculates the time stamp array (fStamp).
2183*0e209d39SAndroid Build Coastguard Worker * Resets fNextStamp to lowest next stamp value.
2184*0e209d39SAndroid Build Coastguard Worker */
2185*0e209d39SAndroid Build Coastguard Worker void recalculateStamp();
2186*0e209d39SAndroid Build Coastguard Worker
2187*0e209d39SAndroid Build Coastguard Worker /**
2188*0e209d39SAndroid Build Coastguard Worker * The current time set for the calendar.
2189*0e209d39SAndroid Build Coastguard Worker */
2190*0e209d39SAndroid Build Coastguard Worker UDate fTime;
2191*0e209d39SAndroid Build Coastguard Worker
2192*0e209d39SAndroid Build Coastguard Worker /**
2193*0e209d39SAndroid Build Coastguard Worker * @see #setLenient
2194*0e209d39SAndroid Build Coastguard Worker */
2195*0e209d39SAndroid Build Coastguard Worker UBool fLenient;
2196*0e209d39SAndroid Build Coastguard Worker
2197*0e209d39SAndroid Build Coastguard Worker /**
2198*0e209d39SAndroid Build Coastguard Worker * Time zone affects the time calculation done by Calendar. Calendar subclasses use
2199*0e209d39SAndroid Build Coastguard Worker * the time zone data to produce the local time. Always set; never nullptr.
2200*0e209d39SAndroid Build Coastguard Worker */
2201*0e209d39SAndroid Build Coastguard Worker TimeZone* fZone;
2202*0e209d39SAndroid Build Coastguard Worker
2203*0e209d39SAndroid Build Coastguard Worker /**
2204*0e209d39SAndroid Build Coastguard Worker * Option for repeated wall time
2205*0e209d39SAndroid Build Coastguard Worker * @see #setRepeatedWallTimeOption
2206*0e209d39SAndroid Build Coastguard Worker */
2207*0e209d39SAndroid Build Coastguard Worker UCalendarWallTimeOption fRepeatedWallTime;
2208*0e209d39SAndroid Build Coastguard Worker
2209*0e209d39SAndroid Build Coastguard Worker /**
2210*0e209d39SAndroid Build Coastguard Worker * Option for skipped wall time
2211*0e209d39SAndroid Build Coastguard Worker * @see #setSkippedWallTimeOption
2212*0e209d39SAndroid Build Coastguard Worker */
2213*0e209d39SAndroid Build Coastguard Worker UCalendarWallTimeOption fSkippedWallTime;
2214*0e209d39SAndroid Build Coastguard Worker
2215*0e209d39SAndroid Build Coastguard Worker /**
2216*0e209d39SAndroid Build Coastguard Worker * Both firstDayOfWeek and minimalDaysInFirstWeek are locale-dependent. They are
2217*0e209d39SAndroid Build Coastguard Worker * used to figure out the week count for a specific date for a given locale. These
2218*0e209d39SAndroid Build Coastguard Worker * must be set when a Calendar is constructed. For example, in US locale,
2219*0e209d39SAndroid Build Coastguard Worker * firstDayOfWeek is SUNDAY; minimalDaysInFirstWeek is 1. They are used to figure
2220*0e209d39SAndroid Build Coastguard Worker * out the week count for a specific date for a given locale. These must be set when
2221*0e209d39SAndroid Build Coastguard Worker * a Calendar is constructed.
2222*0e209d39SAndroid Build Coastguard Worker */
2223*0e209d39SAndroid Build Coastguard Worker UCalendarDaysOfWeek fFirstDayOfWeek;
2224*0e209d39SAndroid Build Coastguard Worker uint8_t fMinimalDaysInFirstWeek;
2225*0e209d39SAndroid Build Coastguard Worker UCalendarDaysOfWeek fWeekendOnset;
2226*0e209d39SAndroid Build Coastguard Worker int32_t fWeekendOnsetMillis;
2227*0e209d39SAndroid Build Coastguard Worker UCalendarDaysOfWeek fWeekendCease;
2228*0e209d39SAndroid Build Coastguard Worker int32_t fWeekendCeaseMillis;
2229*0e209d39SAndroid Build Coastguard Worker
2230*0e209d39SAndroid Build Coastguard Worker /**
2231*0e209d39SAndroid Build Coastguard Worker * Sets firstDayOfWeek and minimalDaysInFirstWeek. Called at Calendar construction
2232*0e209d39SAndroid Build Coastguard Worker * time.
2233*0e209d39SAndroid Build Coastguard Worker *
2234*0e209d39SAndroid Build Coastguard Worker * @param desiredLocale The given locale.
2235*0e209d39SAndroid Build Coastguard Worker * @param type The calendar type identifier, e.g: gregorian, buddhist, etc.
2236*0e209d39SAndroid Build Coastguard Worker * @param success Indicates the status of setting the week count data from
2237*0e209d39SAndroid Build Coastguard Worker * the resource for the given locale. Returns U_ZERO_ERROR if
2238*0e209d39SAndroid Build Coastguard Worker * constructed successfully.
2239*0e209d39SAndroid Build Coastguard Worker */
2240*0e209d39SAndroid Build Coastguard Worker void setWeekData(const Locale& desiredLocale, const char *type, UErrorCode& success);
2241*0e209d39SAndroid Build Coastguard Worker
2242*0e209d39SAndroid Build Coastguard Worker /**
2243*0e209d39SAndroid Build Coastguard Worker * Recompute the time and update the status fields isTimeSet
2244*0e209d39SAndroid Build Coastguard Worker * and areFieldsSet. Callers should check isTimeSet and only
2245*0e209d39SAndroid Build Coastguard Worker * call this method if isTimeSet is false.
2246*0e209d39SAndroid Build Coastguard Worker *
2247*0e209d39SAndroid Build Coastguard Worker * @param status Output param set to success/failure code on exit. If any value
2248*0e209d39SAndroid Build Coastguard Worker * previously set in the time field is invalid or restricted by
2249*0e209d39SAndroid Build Coastguard Worker * leniency, this will be set to an error status.
2250*0e209d39SAndroid Build Coastguard Worker */
2251*0e209d39SAndroid Build Coastguard Worker void updateTime(UErrorCode& status);
2252*0e209d39SAndroid Build Coastguard Worker
2253*0e209d39SAndroid Build Coastguard Worker /**
2254*0e209d39SAndroid Build Coastguard Worker * The Gregorian year, as computed by computeGregorianFields() and
2255*0e209d39SAndroid Build Coastguard Worker * returned by getGregorianYear().
2256*0e209d39SAndroid Build Coastguard Worker * @see #computeGregorianFields
2257*0e209d39SAndroid Build Coastguard Worker */
2258*0e209d39SAndroid Build Coastguard Worker int32_t fGregorianYear;
2259*0e209d39SAndroid Build Coastguard Worker
2260*0e209d39SAndroid Build Coastguard Worker /**
2261*0e209d39SAndroid Build Coastguard Worker * The Gregorian month, as computed by computeGregorianFields() and
2262*0e209d39SAndroid Build Coastguard Worker * returned by getGregorianMonth().
2263*0e209d39SAndroid Build Coastguard Worker * @see #computeGregorianFields
2264*0e209d39SAndroid Build Coastguard Worker */
2265*0e209d39SAndroid Build Coastguard Worker int32_t fGregorianMonth;
2266*0e209d39SAndroid Build Coastguard Worker
2267*0e209d39SAndroid Build Coastguard Worker /**
2268*0e209d39SAndroid Build Coastguard Worker * The Gregorian day of the year, as computed by
2269*0e209d39SAndroid Build Coastguard Worker * computeGregorianFields() and returned by getGregorianDayOfYear().
2270*0e209d39SAndroid Build Coastguard Worker * @see #computeGregorianFields
2271*0e209d39SAndroid Build Coastguard Worker */
2272*0e209d39SAndroid Build Coastguard Worker int32_t fGregorianDayOfYear;
2273*0e209d39SAndroid Build Coastguard Worker
2274*0e209d39SAndroid Build Coastguard Worker /**
2275*0e209d39SAndroid Build Coastguard Worker * The Gregorian day of the month, as computed by
2276*0e209d39SAndroid Build Coastguard Worker * computeGregorianFields() and returned by getGregorianDayOfMonth().
2277*0e209d39SAndroid Build Coastguard Worker * @see #computeGregorianFields
2278*0e209d39SAndroid Build Coastguard Worker */
2279*0e209d39SAndroid Build Coastguard Worker int32_t fGregorianDayOfMonth;
2280*0e209d39SAndroid Build Coastguard Worker
2281*0e209d39SAndroid Build Coastguard Worker /* calculations */
2282*0e209d39SAndroid Build Coastguard Worker
2283*0e209d39SAndroid Build Coastguard Worker /**
2284*0e209d39SAndroid Build Coastguard Worker * Compute the Gregorian calendar year, month, and day of month from
2285*0e209d39SAndroid Build Coastguard Worker * the given Julian day. These values are not stored in fields, but in
2286*0e209d39SAndroid Build Coastguard Worker * member variables gregorianXxx. Also compute the DAY_OF_WEEK and
2287*0e209d39SAndroid Build Coastguard Worker * DOW_LOCAL fields.
2288*0e209d39SAndroid Build Coastguard Worker */
2289*0e209d39SAndroid Build Coastguard Worker void computeGregorianAndDOWFields(int32_t julianDay, UErrorCode &ec);
2290*0e209d39SAndroid Build Coastguard Worker
2291*0e209d39SAndroid Build Coastguard Worker protected:
2292*0e209d39SAndroid Build Coastguard Worker
2293*0e209d39SAndroid Build Coastguard Worker /**
2294*0e209d39SAndroid Build Coastguard Worker * Compute the Gregorian calendar year, month, and day of month from the
2295*0e209d39SAndroid Build Coastguard Worker * Julian day. These values are not stored in fields, but in member
2296*0e209d39SAndroid Build Coastguard Worker * variables gregorianXxx. They are used for time zone computations and by
2297*0e209d39SAndroid Build Coastguard Worker * subclasses that are Gregorian derivatives. Subclasses may call this
2298*0e209d39SAndroid Build Coastguard Worker * method to perform a Gregorian calendar millis->fields computation.
2299*0e209d39SAndroid Build Coastguard Worker */
2300*0e209d39SAndroid Build Coastguard Worker void computeGregorianFields(int32_t julianDay, UErrorCode &ec);
2301*0e209d39SAndroid Build Coastguard Worker
2302*0e209d39SAndroid Build Coastguard Worker private:
2303*0e209d39SAndroid Build Coastguard Worker
2304*0e209d39SAndroid Build Coastguard Worker /**
2305*0e209d39SAndroid Build Coastguard Worker * Compute the fields WEEK_OF_YEAR, YEAR_WOY, WEEK_OF_MONTH,
2306*0e209d39SAndroid Build Coastguard Worker * DAY_OF_WEEK_IN_MONTH, and DOW_LOCAL from EXTENDED_YEAR, YEAR,
2307*0e209d39SAndroid Build Coastguard Worker * DAY_OF_WEEK, and DAY_OF_YEAR. The latter fields are computed by the
2308*0e209d39SAndroid Build Coastguard Worker * subclass based on the calendar system.
2309*0e209d39SAndroid Build Coastguard Worker *
2310*0e209d39SAndroid Build Coastguard Worker * <p>The YEAR_WOY field is computed simplistically. It is equal to YEAR
2311*0e209d39SAndroid Build Coastguard Worker * most of the time, but at the year boundary it may be adjusted to YEAR-1
2312*0e209d39SAndroid Build Coastguard Worker * or YEAR+1 to reflect the overlap of a week into an adjacent year. In
2313*0e209d39SAndroid Build Coastguard Worker * this case, a simple increment or decrement is performed on YEAR, even
2314*0e209d39SAndroid Build Coastguard Worker * though this may yield an invalid YEAR value. For instance, if the YEAR
2315*0e209d39SAndroid Build Coastguard Worker * is part of a calendar system with an N-year cycle field CYCLE, then
2316*0e209d39SAndroid Build Coastguard Worker * incrementing the YEAR may involve incrementing CYCLE and setting YEAR
2317*0e209d39SAndroid Build Coastguard Worker * back to 0 or 1. This is not handled by this code, and in fact cannot be
2318*0e209d39SAndroid Build Coastguard Worker * simply handled without having subclasses define an entire parallel set of
2319*0e209d39SAndroid Build Coastguard Worker * fields for fields larger than or equal to a year. This additional
2320*0e209d39SAndroid Build Coastguard Worker * complexity is not warranted, since the intention of the YEAR_WOY field is
2321*0e209d39SAndroid Build Coastguard Worker * to support ISO 8601 notation, so it will typically be used with a
2322*0e209d39SAndroid Build Coastguard Worker * proleptic Gregorian calendar, which has no field larger than a year.
2323*0e209d39SAndroid Build Coastguard Worker */
2324*0e209d39SAndroid Build Coastguard Worker void computeWeekFields(UErrorCode &ec);
2325*0e209d39SAndroid Build Coastguard Worker
2326*0e209d39SAndroid Build Coastguard Worker
2327*0e209d39SAndroid Build Coastguard Worker /**
2328*0e209d39SAndroid Build Coastguard Worker * Ensure that each field is within its valid range by calling {@link
2329*0e209d39SAndroid Build Coastguard Worker * #validateField(int, int&)} on each field that has been set. This method
2330*0e209d39SAndroid Build Coastguard Worker * should only be called if this calendar is not lenient.
2331*0e209d39SAndroid Build Coastguard Worker * @see #isLenient
2332*0e209d39SAndroid Build Coastguard Worker * @see #validateField(int, int&)
2333*0e209d39SAndroid Build Coastguard Worker */
2334*0e209d39SAndroid Build Coastguard Worker void validateFields(UErrorCode &status);
2335*0e209d39SAndroid Build Coastguard Worker
2336*0e209d39SAndroid Build Coastguard Worker /**
2337*0e209d39SAndroid Build Coastguard Worker * Validate a single field of this calendar given its minimum and
2338*0e209d39SAndroid Build Coastguard Worker * maximum allowed value. If the field is out of range,
2339*0e209d39SAndroid Build Coastguard Worker * <code>U_ILLEGAL_ARGUMENT_ERROR</code> will be set. Subclasses may
2340*0e209d39SAndroid Build Coastguard Worker * use this method in their implementation of {@link
2341*0e209d39SAndroid Build Coastguard Worker * #validateField(int, int&)}.
2342*0e209d39SAndroid Build Coastguard Worker */
2343*0e209d39SAndroid Build Coastguard Worker void validateField(UCalendarDateFields field, int32_t min, int32_t max, UErrorCode& status);
2344*0e209d39SAndroid Build Coastguard Worker
2345*0e209d39SAndroid Build Coastguard Worker protected:
2346*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_INTERNAL_API
2347*0e209d39SAndroid Build Coastguard Worker /**
2348*0e209d39SAndroid Build Coastguard Worker * Convert a quasi Julian date to the day of the week. The Julian date used here is
2349*0e209d39SAndroid Build Coastguard Worker * not a true Julian date, since it is measured from midnight, not noon. Return
2350*0e209d39SAndroid Build Coastguard Worker * value is one-based.
2351*0e209d39SAndroid Build Coastguard Worker *
2352*0e209d39SAndroid Build Coastguard Worker * @param julian The given Julian date number.
2353*0e209d39SAndroid Build Coastguard Worker * @return Day number from 1..7 (SUN..SAT).
2354*0e209d39SAndroid Build Coastguard Worker * @internal
2355*0e209d39SAndroid Build Coastguard Worker */
2356*0e209d39SAndroid Build Coastguard Worker static uint8_t julianDayToDayOfWeek(int32_t julian);
2357*0e209d39SAndroid Build Coastguard Worker #endif /* U_HIDE_INTERNAL_API */
2358*0e209d39SAndroid Build Coastguard Worker
2359*0e209d39SAndroid Build Coastguard Worker private:
2360*0e209d39SAndroid Build Coastguard Worker char validLocale[ULOC_FULLNAME_CAPACITY];
2361*0e209d39SAndroid Build Coastguard Worker char actualLocale[ULOC_FULLNAME_CAPACITY];
2362*0e209d39SAndroid Build Coastguard Worker
2363*0e209d39SAndroid Build Coastguard Worker public:
2364*0e209d39SAndroid Build Coastguard Worker #if !UCONFIG_NO_SERVICE
2365*0e209d39SAndroid Build Coastguard Worker /**
2366*0e209d39SAndroid Build Coastguard Worker * INTERNAL FOR 2.6 -- Registration.
2367*0e209d39SAndroid Build Coastguard Worker */
2368*0e209d39SAndroid Build Coastguard Worker
2369*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_INTERNAL_API
2370*0e209d39SAndroid Build Coastguard Worker /**
2371*0e209d39SAndroid Build Coastguard Worker * Return a StringEnumeration over the locales available at the time of the call,
2372*0e209d39SAndroid Build Coastguard Worker * including registered locales.
2373*0e209d39SAndroid Build Coastguard Worker * @return a StringEnumeration over the locales available at the time of the call
2374*0e209d39SAndroid Build Coastguard Worker * @internal
2375*0e209d39SAndroid Build Coastguard Worker */
2376*0e209d39SAndroid Build Coastguard Worker static StringEnumeration* getAvailableLocales();
2377*0e209d39SAndroid Build Coastguard Worker
2378*0e209d39SAndroid Build Coastguard Worker /**
2379*0e209d39SAndroid Build Coastguard Worker * Register a new Calendar factory. The factory will be adopted.
2380*0e209d39SAndroid Build Coastguard Worker * INTERNAL in 2.6
2381*0e209d39SAndroid Build Coastguard Worker *
2382*0e209d39SAndroid Build Coastguard Worker * Because ICU may choose to cache Calendars internally, this must
2383*0e209d39SAndroid Build Coastguard Worker * be called at application startup, prior to any calls to
2384*0e209d39SAndroid Build Coastguard Worker * Calendar::createInstance to avoid undefined behavior.
2385*0e209d39SAndroid Build Coastguard Worker *
2386*0e209d39SAndroid Build Coastguard Worker * @param toAdopt the factory instance to be adopted
2387*0e209d39SAndroid Build Coastguard Worker * @param status the in/out status code, no special meanings are assigned
2388*0e209d39SAndroid Build Coastguard Worker * @return a registry key that can be used to unregister this factory
2389*0e209d39SAndroid Build Coastguard Worker * @internal
2390*0e209d39SAndroid Build Coastguard Worker */
2391*0e209d39SAndroid Build Coastguard Worker static URegistryKey registerFactory(ICUServiceFactory* toAdopt, UErrorCode& status);
2392*0e209d39SAndroid Build Coastguard Worker
2393*0e209d39SAndroid Build Coastguard Worker /**
2394*0e209d39SAndroid Build Coastguard Worker * Unregister a previously-registered CalendarFactory using the key returned from the
2395*0e209d39SAndroid Build Coastguard Worker * register call. Key becomes invalid after a successful call and should not be used again.
2396*0e209d39SAndroid Build Coastguard Worker * The CalendarFactory corresponding to the key will be deleted.
2397*0e209d39SAndroid Build Coastguard Worker * INTERNAL in 2.6
2398*0e209d39SAndroid Build Coastguard Worker *
2399*0e209d39SAndroid Build Coastguard Worker * Because ICU may choose to cache Calendars internally, this should
2400*0e209d39SAndroid Build Coastguard Worker * be called during application shutdown, after all calls to
2401*0e209d39SAndroid Build Coastguard Worker * Calendar::createInstance to avoid undefined behavior.
2402*0e209d39SAndroid Build Coastguard Worker *
2403*0e209d39SAndroid Build Coastguard Worker * @param key the registry key returned by a previous call to registerFactory
2404*0e209d39SAndroid Build Coastguard Worker * @param status the in/out status code, no special meanings are assigned
2405*0e209d39SAndroid Build Coastguard Worker * @return true if the factory for the key was successfully unregistered
2406*0e209d39SAndroid Build Coastguard Worker * @internal
2407*0e209d39SAndroid Build Coastguard Worker */
2408*0e209d39SAndroid Build Coastguard Worker static UBool unregister(URegistryKey key, UErrorCode& status);
2409*0e209d39SAndroid Build Coastguard Worker #endif /* U_HIDE_INTERNAL_API */
2410*0e209d39SAndroid Build Coastguard Worker
2411*0e209d39SAndroid Build Coastguard Worker /**
2412*0e209d39SAndroid Build Coastguard Worker * Multiple Calendar Implementation
2413*0e209d39SAndroid Build Coastguard Worker * @internal
2414*0e209d39SAndroid Build Coastguard Worker */
2415*0e209d39SAndroid Build Coastguard Worker friend class CalendarFactory;
2416*0e209d39SAndroid Build Coastguard Worker
2417*0e209d39SAndroid Build Coastguard Worker /**
2418*0e209d39SAndroid Build Coastguard Worker * Multiple Calendar Implementation
2419*0e209d39SAndroid Build Coastguard Worker * @internal
2420*0e209d39SAndroid Build Coastguard Worker */
2421*0e209d39SAndroid Build Coastguard Worker friend class CalendarService;
2422*0e209d39SAndroid Build Coastguard Worker
2423*0e209d39SAndroid Build Coastguard Worker /**
2424*0e209d39SAndroid Build Coastguard Worker * Multiple Calendar Implementation
2425*0e209d39SAndroid Build Coastguard Worker * @internal
2426*0e209d39SAndroid Build Coastguard Worker */
2427*0e209d39SAndroid Build Coastguard Worker friend class DefaultCalendarFactory;
2428*0e209d39SAndroid Build Coastguard Worker #endif /* !UCONFIG_NO_SERVICE */
2429*0e209d39SAndroid Build Coastguard Worker
2430*0e209d39SAndroid Build Coastguard Worker /**
2431*0e209d39SAndroid Build Coastguard Worker * @return true if this calendar has a default century (i.e. 03 -> 2003)
2432*0e209d39SAndroid Build Coastguard Worker * @internal
2433*0e209d39SAndroid Build Coastguard Worker */
2434*0e209d39SAndroid Build Coastguard Worker virtual UBool haveDefaultCentury() const = 0;
2435*0e209d39SAndroid Build Coastguard Worker
2436*0e209d39SAndroid Build Coastguard Worker /**
2437*0e209d39SAndroid Build Coastguard Worker * @return the start of the default century, as a UDate
2438*0e209d39SAndroid Build Coastguard Worker * @internal
2439*0e209d39SAndroid Build Coastguard Worker */
2440*0e209d39SAndroid Build Coastguard Worker virtual UDate defaultCenturyStart() const = 0;
2441*0e209d39SAndroid Build Coastguard Worker /**
2442*0e209d39SAndroid Build Coastguard Worker * @return the beginning year of the default century, as a year
2443*0e209d39SAndroid Build Coastguard Worker * @internal
2444*0e209d39SAndroid Build Coastguard Worker */
2445*0e209d39SAndroid Build Coastguard Worker virtual int32_t defaultCenturyStartYear() const = 0;
2446*0e209d39SAndroid Build Coastguard Worker
2447*0e209d39SAndroid Build Coastguard Worker /** Get the locale for this calendar object. You can choose between valid and actual locale.
2448*0e209d39SAndroid Build Coastguard Worker * @param type type of the locale we're looking for (valid or actual)
2449*0e209d39SAndroid Build Coastguard Worker * @param status error code for the operation
2450*0e209d39SAndroid Build Coastguard Worker * @return the locale
2451*0e209d39SAndroid Build Coastguard Worker * @stable ICU 2.8
2452*0e209d39SAndroid Build Coastguard Worker */
2453*0e209d39SAndroid Build Coastguard Worker Locale getLocale(ULocDataLocaleType type, UErrorCode &status) const;
2454*0e209d39SAndroid Build Coastguard Worker
2455*0e209d39SAndroid Build Coastguard Worker /**
2456*0e209d39SAndroid Build Coastguard Worker * @return The related Gregorian year; will be obtained by modifying the value
2457*0e209d39SAndroid Build Coastguard Worker * obtained by get from UCAL_EXTENDED_YEAR field
2458*0e209d39SAndroid Build Coastguard Worker * @internal
2459*0e209d39SAndroid Build Coastguard Worker */
2460*0e209d39SAndroid Build Coastguard Worker virtual int32_t getRelatedYear(UErrorCode &status) const;
2461*0e209d39SAndroid Build Coastguard Worker
2462*0e209d39SAndroid Build Coastguard Worker /**
2463*0e209d39SAndroid Build Coastguard Worker * @param year The related Gregorian year to set; will be modified as necessary then
2464*0e209d39SAndroid Build Coastguard Worker * set in UCAL_EXTENDED_YEAR field
2465*0e209d39SAndroid Build Coastguard Worker * @internal
2466*0e209d39SAndroid Build Coastguard Worker */
2467*0e209d39SAndroid Build Coastguard Worker virtual void setRelatedYear(int32_t year);
2468*0e209d39SAndroid Build Coastguard Worker
2469*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_INTERNAL_API
2470*0e209d39SAndroid Build Coastguard Worker /** Get the locale for this calendar object. You can choose between valid and actual locale.
2471*0e209d39SAndroid Build Coastguard Worker * @param type type of the locale we're looking for (valid or actual)
2472*0e209d39SAndroid Build Coastguard Worker * @param status error code for the operation
2473*0e209d39SAndroid Build Coastguard Worker * @return the locale
2474*0e209d39SAndroid Build Coastguard Worker * @internal
2475*0e209d39SAndroid Build Coastguard Worker */
2476*0e209d39SAndroid Build Coastguard Worker const char* getLocaleID(ULocDataLocaleType type, UErrorCode &status) const;
2477*0e209d39SAndroid Build Coastguard Worker #endif /* U_HIDE_INTERNAL_API */
2478*0e209d39SAndroid Build Coastguard Worker
2479*0e209d39SAndroid Build Coastguard Worker private:
2480*0e209d39SAndroid Build Coastguard Worker /**
2481*0e209d39SAndroid Build Coastguard Worker * Cast TimeZone used by this object to BasicTimeZone, or nullptr if the TimeZone
2482*0e209d39SAndroid Build Coastguard Worker * is not an instance of BasicTimeZone.
2483*0e209d39SAndroid Build Coastguard Worker */
2484*0e209d39SAndroid Build Coastguard Worker BasicTimeZone* getBasicTimeZone() const;
2485*0e209d39SAndroid Build Coastguard Worker
2486*0e209d39SAndroid Build Coastguard Worker /**
2487*0e209d39SAndroid Build Coastguard Worker * Find the previous zone transition near the given time.
2488*0e209d39SAndroid Build Coastguard Worker * @param base The base time, inclusive
2489*0e209d39SAndroid Build Coastguard Worker * @param transitionTime Receives the result time
2490*0e209d39SAndroid Build Coastguard Worker * @param status The error status
2491*0e209d39SAndroid Build Coastguard Worker * @return true if a transition is found.
2492*0e209d39SAndroid Build Coastguard Worker */
2493*0e209d39SAndroid Build Coastguard Worker UBool getImmediatePreviousZoneTransition(UDate base, UDate *transitionTime, UErrorCode& status) const;
2494*0e209d39SAndroid Build Coastguard Worker
2495*0e209d39SAndroid Build Coastguard Worker public:
2496*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_INTERNAL_API
2497*0e209d39SAndroid Build Coastguard Worker /**
2498*0e209d39SAndroid Build Coastguard Worker * Creates a new Calendar from a Locale for the cache.
2499*0e209d39SAndroid Build Coastguard Worker * This method does not set the time or timezone in returned calendar.
2500*0e209d39SAndroid Build Coastguard Worker * @param locale the locale.
2501*0e209d39SAndroid Build Coastguard Worker * @param status any error returned here.
2502*0e209d39SAndroid Build Coastguard Worker * @return the new Calendar object with no time or timezone set.
2503*0e209d39SAndroid Build Coastguard Worker * @internal For ICU use only.
2504*0e209d39SAndroid Build Coastguard Worker */
2505*0e209d39SAndroid Build Coastguard Worker static Calendar * U_EXPORT2 makeInstance(
2506*0e209d39SAndroid Build Coastguard Worker const Locale &locale, UErrorCode &status);
2507*0e209d39SAndroid Build Coastguard Worker
2508*0e209d39SAndroid Build Coastguard Worker /**
2509*0e209d39SAndroid Build Coastguard Worker * Get the calendar type for given locale.
2510*0e209d39SAndroid Build Coastguard Worker * @param locale the locale
2511*0e209d39SAndroid Build Coastguard Worker * @param typeBuffer calendar type returned here
2512*0e209d39SAndroid Build Coastguard Worker * @param typeBufferSize The size of typeBuffer in bytes. If the type
2513*0e209d39SAndroid Build Coastguard Worker * can't fit in the buffer, this method sets status to
2514*0e209d39SAndroid Build Coastguard Worker * U_BUFFER_OVERFLOW_ERROR
2515*0e209d39SAndroid Build Coastguard Worker * @param status error, if any, returned here.
2516*0e209d39SAndroid Build Coastguard Worker * @internal For ICU use only.
2517*0e209d39SAndroid Build Coastguard Worker */
2518*0e209d39SAndroid Build Coastguard Worker static void U_EXPORT2 getCalendarTypeFromLocale(
2519*0e209d39SAndroid Build Coastguard Worker const Locale &locale,
2520*0e209d39SAndroid Build Coastguard Worker char *typeBuffer,
2521*0e209d39SAndroid Build Coastguard Worker int32_t typeBufferSize,
2522*0e209d39SAndroid Build Coastguard Worker UErrorCode &status);
2523*0e209d39SAndroid Build Coastguard Worker #endif /* U_HIDE_INTERNAL_API */
2524*0e209d39SAndroid Build Coastguard Worker };
2525*0e209d39SAndroid Build Coastguard Worker
2526*0e209d39SAndroid Build Coastguard Worker // -------------------------------------
2527*0e209d39SAndroid Build Coastguard Worker
2528*0e209d39SAndroid Build Coastguard Worker inline Calendar*
createInstance(TimeZone * zone,UErrorCode & errorCode)2529*0e209d39SAndroid Build Coastguard Worker Calendar::createInstance(TimeZone* zone, UErrorCode& errorCode)
2530*0e209d39SAndroid Build Coastguard Worker {
2531*0e209d39SAndroid Build Coastguard Worker // since the Locale isn't specified, use the default locale
2532*0e209d39SAndroid Build Coastguard Worker return createInstance(zone, Locale::getDefault(), errorCode);
2533*0e209d39SAndroid Build Coastguard Worker }
2534*0e209d39SAndroid Build Coastguard Worker
2535*0e209d39SAndroid Build Coastguard Worker // -------------------------------------
2536*0e209d39SAndroid Build Coastguard Worker
2537*0e209d39SAndroid Build Coastguard Worker inline void
roll(UCalendarDateFields field,UBool up,UErrorCode & status)2538*0e209d39SAndroid Build Coastguard Worker Calendar::roll(UCalendarDateFields field, UBool up, UErrorCode& status)
2539*0e209d39SAndroid Build Coastguard Worker {
2540*0e209d39SAndroid Build Coastguard Worker roll(field, (int32_t)(up ? +1 : -1), status);
2541*0e209d39SAndroid Build Coastguard Worker }
2542*0e209d39SAndroid Build Coastguard Worker
2543*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_DEPRECATED_API
2544*0e209d39SAndroid Build Coastguard Worker inline void
roll(EDateFields field,UBool up,UErrorCode & status)2545*0e209d39SAndroid Build Coastguard Worker Calendar::roll(EDateFields field, UBool up, UErrorCode& status)
2546*0e209d39SAndroid Build Coastguard Worker {
2547*0e209d39SAndroid Build Coastguard Worker roll((UCalendarDateFields) field, up, status);
2548*0e209d39SAndroid Build Coastguard Worker }
2549*0e209d39SAndroid Build Coastguard Worker #endif /* U_HIDE_DEPRECATED_API */
2550*0e209d39SAndroid Build Coastguard Worker
2551*0e209d39SAndroid Build Coastguard Worker
2552*0e209d39SAndroid Build Coastguard Worker // -------------------------------------
2553*0e209d39SAndroid Build Coastguard Worker
2554*0e209d39SAndroid Build Coastguard Worker /**
2555*0e209d39SAndroid Build Coastguard Worker * Fast method for subclasses. The caller must maintain fUserSetDSTOffset and
2556*0e209d39SAndroid Build Coastguard Worker * fUserSetZoneOffset, as well as the isSet[] array.
2557*0e209d39SAndroid Build Coastguard Worker */
2558*0e209d39SAndroid Build Coastguard Worker
2559*0e209d39SAndroid Build Coastguard Worker inline void
internalSet(UCalendarDateFields field,int32_t value)2560*0e209d39SAndroid Build Coastguard Worker Calendar::internalSet(UCalendarDateFields field, int32_t value)
2561*0e209d39SAndroid Build Coastguard Worker {
2562*0e209d39SAndroid Build Coastguard Worker fFields[field] = value;
2563*0e209d39SAndroid Build Coastguard Worker fStamp[field] = kInternallySet;
2564*0e209d39SAndroid Build Coastguard Worker fIsSet[field] = true; // Remove later
2565*0e209d39SAndroid Build Coastguard Worker }
2566*0e209d39SAndroid Build Coastguard Worker
2567*0e209d39SAndroid Build Coastguard Worker /**
2568*0e209d39SAndroid Build Coastguard Worker * Macro for the class to declare it override
2569*0e209d39SAndroid Build Coastguard Worker * haveDefaultCentury, defaultCenturyStart, and
2570*0e209d39SAndroid Build Coastguard Worker * defaultCenturyStartYear functions in this class.
2571*0e209d39SAndroid Build Coastguard Worker * @internal
2572*0e209d39SAndroid Build Coastguard Worker */
2573*0e209d39SAndroid Build Coastguard Worker #define DECLARE_OVERRIDE_SYSTEM_DEFAULT_CENTURY \
2574*0e209d39SAndroid Build Coastguard Worker virtual UBool haveDefaultCentury() const override; \
2575*0e209d39SAndroid Build Coastguard Worker virtual UDate defaultCenturyStart() const override; \
2576*0e209d39SAndroid Build Coastguard Worker virtual int32_t defaultCenturyStartYear() const override;
2577*0e209d39SAndroid Build Coastguard Worker
2578*0e209d39SAndroid Build Coastguard Worker #ifndef U_HIDE_INTERNAL_API
weekNumber(int32_t dayOfPeriod,int32_t dayOfWeek)2579*0e209d39SAndroid Build Coastguard Worker inline int32_t Calendar::weekNumber(int32_t dayOfPeriod, int32_t dayOfWeek)
2580*0e209d39SAndroid Build Coastguard Worker {
2581*0e209d39SAndroid Build Coastguard Worker return weekNumber(dayOfPeriod, dayOfPeriod, dayOfWeek);
2582*0e209d39SAndroid Build Coastguard Worker }
2583*0e209d39SAndroid Build Coastguard Worker #endif /* U_HIDE_INTERNAL_API */
2584*0e209d39SAndroid Build Coastguard Worker
2585*0e209d39SAndroid Build Coastguard Worker U_NAMESPACE_END
2586*0e209d39SAndroid Build Coastguard Worker
2587*0e209d39SAndroid Build Coastguard Worker #endif /* #if !UCONFIG_NO_FORMATTING */
2588*0e209d39SAndroid Build Coastguard Worker
2589*0e209d39SAndroid Build Coastguard Worker #endif /* U_SHOW_CPLUSPLUS_API */
2590*0e209d39SAndroid Build Coastguard Worker
2591*0e209d39SAndroid Build Coastguard Worker #endif // _CALENDAR
2592