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