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