1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 ********************************************************************************
5 * Copyright (C) 1997-2014, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 ********************************************************************************
11 * Modification History:
13 * Date Name Description
14 * 04/22/97 aliu Expanded and corrected comments and other header
16 * 05/01/97 aliu Made equals(), before(), after() arguments const.
17 * 05/20/97 aliu Replaced fAreFieldsSet with fAreFieldsInSync and
19 * 07/27/98 stephen Sync up with JDK 1.2
20 * 11/15/99 weiv added YEAR_WOY and DOW_LOCAL
22 * 8/19/2002 srl Removed Javaisms
23 * 11/07/2003 srl Update, clean up documentation.
24 ********************************************************************************
30 #include "unicode/utypes.h"
34 * \brief C++ API: Calendar object
36 #if !UCONFIG_NO_FORMATTING
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"
44 #if U_SHOW_CPLUSPLUS_API
47 class ICUServiceFactory
;
52 typedef int32_t UFieldResolutionTable
[12][8];
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.)
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.
71 * <b>NOTE</b>: (ICU 2.6) The subclass interface should be considered unstable
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
82 * Calendar *rightNow = Calendar::createInstance(errCode);
84 * \htmlonly</blockquote>\endhtmlonly
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).
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.
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.
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.
112 * \htmlonly<blockquote>\endhtmlonly
114 * MONTH + DAY_OF_MONTH
115 * MONTH + WEEK_OF_MONTH + DAY_OF_WEEK
116 * MONTH + DAY_OF_WEEK_IN_MONTH + DAY_OF_WEEK
118 * DAY_OF_WEEK + WEEK_OF_YEAR
120 * \htmlonly</blockquote>\endhtmlonly
122 * For the time of day:
124 * \htmlonly<blockquote>\endhtmlonly
129 * \htmlonly</blockquote>\endhtmlonly
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.
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.
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.
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.
158 * <strong>Note:</strong> There are certain possible ambiguities in
159 * interpretation of certain singular times, which are resolved in the
162 * <li> 24:00:00 "belongs" to the following day. That is,
163 * 23:59 on Dec 31, 1969 < 24:00 on Jan 1, 1970 < 24:01:00 on Jan 1, 1970
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) < 12:01 am, and 12:00 pm (noon) < 12:01 pm
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}
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>.
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>.
188 * <p><big><b>Supported range</b></big>
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>
203 class U_I18N_API Calendar
: public UObject
{
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
213 #ifndef U_HIDE_DEPRECATED_API
215 * ERA may be defined on other platforms. To avoid any potential problems undefined it here.
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
245 FIELD_COUNT
= UCAL_FIELD_COUNT
// See ucal.h for other fields.
246 #endif /* U_HIDE_DEPRECATED_API */
249 #ifndef U_HIDE_DEPRECATED_API
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
267 * Useful constants for month. Note: Calendar month is 0-based.
268 * @deprecated ICU 2.6. Use C enum UCalendarMonths defined in ucal.h
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
294 #endif /* U_HIDE_DEPRECATED_API */
303 * Create and return a polymorphic copy of this calendar.
305 * @return a polymorphic copy of this calendar.
308 virtual Calendar
* clone(void) const = 0;
311 * Creates a Calendar using the default timezone and locale. Clients are responsible
312 * for deleting the object returned.
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.
321 static Calendar
* U_EXPORT2
createInstance(UErrorCode
& success
);
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.
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
332 * @return A Calendar if created successfully. NULL otherwise.
335 static Calendar
* U_EXPORT2
createInstance(TimeZone
* zoneToAdopt
, UErrorCode
& success
);
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.
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
345 * @return A Calendar if created successfully. NULL otherwise.
348 static Calendar
* U_EXPORT2
createInstance(const TimeZone
& zone
, UErrorCode
& success
);
351 * Creates a Calendar using the default timezone and the given locale.
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
357 * @return A Calendar if created successfully. NULL otherwise.
360 static Calendar
* U_EXPORT2
createInstance(const Locale
& aLocale
, UErrorCode
& success
);
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.
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
372 * @return A Calendar if created successfully. NULL otherwise.
375 static Calendar
* U_EXPORT2
createInstance(TimeZone
* zoneToAdopt
, const Locale
& aLocale
, UErrorCode
& success
);
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.
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
386 * @return A Calendar if created successfully. NULL otherwise.
389 static Calendar
* U_EXPORT2
createInstance(const TimeZone
& zone
, const Locale
& aLocale
, UErrorCode
& success
);
392 * Returns a list of the locales for which Calendars are installed.
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.
400 static const Locale
* U_EXPORT2
getAvailableLocales(int32_t& count
);
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.
419 static StringEnumeration
* U_EXPORT2
getKeywordValuesForLocale(const char* key
,
420 const Locale
& locale
, UBool commonlyUsed
, UErrorCode
& status
);
423 * Returns the current UTC (GMT) time measured in milliseconds since 0:00:00 on 1/1/70
424 * (derived from the system time).
426 * @return The current UTC time in milliseconds.
429 static UDate U_EXPORT2
getNow(void);
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).
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
444 inline UDate
getTime(UErrorCode
& status
) const { return getTimeInMillis(status
); }
447 * Sets this Calendar's current time with the given UDate. The time specified should
448 * be in non-local UTC (GMT) time.
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.
456 inline void setTime(UDate date
, UErrorCode
& status
) { setTimeInMillis(date
, status
); }
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.
464 * @param that The Calendar object to be compared with.
465 * @return True if the given Calendar is the same as this Calendar; false
469 virtual UBool
operator==(const Calendar
& that
) const;
472 * Compares the inequality of two Calendar objects.
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
479 UBool
operator!=(const Calendar
& that
) const {return !operator==(that
);}
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.
488 * @param other the Calendar to be compared with this Calendar
491 virtual UBool
isEquivalentTo(const Calendar
& other
) const;
494 * Compares the Calendar time, whereas Calendar::operator== compares the equality of
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.
507 UBool
equals(const Calendar
& when
, UErrorCode
& status
) const;
510 * Returns true if this Calendar's current time is before "when"'s current time.
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.
522 UBool
before(const Calendar
& when
, UErrorCode
& status
) const;
525 * Returns true if this Calendar's current time is after "when"'s current time.
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.
537 UBool
after(const Calendar
& when
, UErrorCode
& status
) const;
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
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).
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
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.
559 virtual void add(EDateFields field
, int32_t amount
, UErrorCode
& status
);
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
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).
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
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.
581 virtual void add(UCalendarDateFields field
, int32_t amount
, UErrorCode
& status
);
583 #ifndef U_HIDE_DEPRECATED_API
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.
606 * NOTE: Do not use this method -- use roll(EDateFields, int, UErrorCode&) instead.
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.
616 inline void roll(EDateFields field
, UBool up
, UErrorCode
& status
);
617 #endif /* U_HIDE_DEPRECATED_API */
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.
641 * NOTE: Do not use this method -- use roll(UCalendarDateFields, int, UErrorCode&) instead.
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.
651 inline void roll(UCalendarDateFields field
, UBool up
, UErrorCode
& status
);
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.
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.
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
682 * @deprecated ICU 2.6. Use roll(UCalendarDateFields field, int32_t amount, UErrorCode& status) instead.
684 virtual void roll(EDateFields field
, int32_t amount
, UErrorCode
& status
);
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.
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.
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
717 virtual void roll(UCalendarDateFields field
, int32_t amount
, UErrorCode
& status
);
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.
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.
736 * <p>Usage: To use this method, call it first with the largest
737 * field of interest, then with progressively smaller fields. For
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>
745 * computes the difference between <code>cal</code> and
746 * <code>when</code> in years, months, and days.
748 * <p>Note: <code>fieldDifference()</code> is
749 * <em>asymmetrical</em>. That is, in the following code:
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>
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).
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
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).
774 virtual int32_t fieldDifference(UDate when
, EDateFields field
, UErrorCode
& status
);
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.
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.
793 * <p>Usage: To use this method, call it first with the largest
794 * field of interest, then with progressively smaller fields. For
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>
802 * computes the difference between <code>cal</code> and
803 * <code>when</code> in years, months, and days.
805 * <p>Note: <code>fieldDifference()</code> is
806 * <em>asymmetrical</em>. That is, in the following code:
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>
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).
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
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>.
831 virtual int32_t fieldDifference(UDate when
, UCalendarDateFields field
, UErrorCode
& status
);
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.
838 * @param value The given time zone.
841 void adoptTimeZone(TimeZone
* value
);
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.
847 * @param zone The given time zone.
850 void setTimeZone(const TimeZone
& zone
);
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.
857 * @return The time zone object associated with this calendar.
860 const TimeZone
& getTimeZone(void) const;
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().
867 * @return The time zone object which was associated with this calendar.
870 TimeZone
* orphanTimeZone(void);
873 * Queries if the current date for this Calendar is in Daylight Savings Time.
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,
880 virtual UBool
inDaylightTime(UErrorCode
& status
) const = 0;
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.
889 * @param lenient True specifies date/time interpretation to be lenient.
891 * @see DateFormat#setLenient
894 void setLenient(UBool lenient
);
897 * Tells whether date/time interpretation is to be lenient.
899 * @return True tells that date/time interpretation is to be lenient.
902 UBool
isLenient(void) const;
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>.
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.
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
924 void setRepeatedWallTimeOption(UCalendarWallTimeOption option
);
927 * Gets the behavior for handling wall time repeating multiple times
928 * at negative time zone offset transitions.
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
935 UCalendarWallTimeOption
getRepeatedWallTimeOption(void) const;
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>.
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.
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
958 void setSkippedWallTimeOption(UCalendarWallTimeOption option
);
961 * Gets the behavior for handling skipped wall time at positive time zone offset
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
970 UCalendarWallTimeOption
getSkippedWallTimeOption(void) const;
972 #ifndef U_HIDE_DEPRECATED_API
974 * Sets what the first day of the week is; e.g., Sunday in US, Monday in France.
976 * @param value The given first day of the week.
977 * @deprecated ICU 2.6. Use setFirstDayOfWeek(UCalendarDaysOfWeek value) instead.
979 void setFirstDayOfWeek(EDaysOfWeek value
);
980 #endif /* U_HIDE_DEPRECATED_API */
983 * Sets what the first day of the week is; e.g., Sunday in US, Monday in France.
985 * @param value The given first day of the week.
988 void setFirstDayOfWeek(UCalendarDaysOfWeek value
);
990 #ifndef U_HIDE_DEPRECATED_API
992 * Gets what the first day of the week is; e.g., Sunday in US, Monday in France.
994 * @return The first day of the week.
995 * @deprecated ICU 2.6 use the overload with error code
997 EDaysOfWeek
getFirstDayOfWeek(void) const;
998 #endif /* U_HIDE_DEPRECATED_API */
1001 * Gets what the first day of the week is; e.g., Sunday in US, Monday in France.
1003 * @param status error code
1004 * @return The first day of the week.
1007 UCalendarDaysOfWeek
getFirstDayOfWeek(UErrorCode
&status
) const;
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,
1015 * @param value The given minimal days required in the first week of the year.
1018 void setMinimalDaysInFirstWeek(uint8_t value
);
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.
1026 * @return The minimal days required in the first week of the year.
1029 uint8_t getMinimalDaysInFirstWeek(void) const;
1032 * Gets the minimum value for the given time field. e.g., for Gregorian
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.
1039 virtual int32_t getMinimum(EDateFields field
) const;
1042 * Gets the minimum value for the given time field. e.g., for Gregorian
1045 * @param field The given time field.
1046 * @return The minimum value for the given time field.
1049 virtual int32_t getMinimum(UCalendarDateFields field
) const;
1052 * Gets the maximum value for the given time field. e.g. for Gregorian DAY_OF_MONTH,
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.
1059 virtual int32_t getMaximum(EDateFields field
) const;
1062 * Gets the maximum value for the given time field. e.g. for Gregorian DAY_OF_MONTH,
1065 * @param field The given time field.
1066 * @return The maximum value for the given time field.
1069 virtual int32_t getMaximum(UCalendarDateFields field
) const;
1072 * Gets the highest minimum value for the given field if varies. Otherwise same as
1073 * getMinimum(). For Gregorian, no difference.
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.
1079 virtual int32_t getGreatestMinimum(EDateFields field
) const;
1082 * Gets the highest minimum value for the given field if varies. Otherwise same as
1083 * getMinimum(). For Gregorian, no difference.
1085 * @param field The given time field.
1086 * @return The highest minimum value for the given time field.
1089 virtual int32_t getGreatestMinimum(UCalendarDateFields field
) const;
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.
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.
1099 virtual int32_t getLeastMaximum(EDateFields field
) const;
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.
1105 * @param field The given time field.
1106 * @return The lowest maximum value for the given time field.
1109 virtual int32_t getLeastMaximum(UCalendarDateFields field
) const;
1111 #ifndef U_HIDE_DEPRECATED_API
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().
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.
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.
1126 int32_t getActualMinimum(EDateFields field
, UErrorCode
& status
) const;
1127 #endif /* U_HIDE_DEPRECATED_API */
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().
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.
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
1143 virtual int32_t getActualMinimum(UCalendarDateFields field
, UErrorCode
& status
) const;
1145 #ifndef U_HIDE_DEPRECATED_API
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.
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.
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.
1162 int32_t getActualMaximum(EDateFields field
, UErrorCode
& status
) const;
1163 #endif /* U_HIDE_DEPRECATED_API */
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.
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.
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
1181 virtual int32_t getActualMaximum(UCalendarDateFields field
, UErrorCode
& status
) const;
1183 #ifndef U_HIDE_DEPRECATED_API
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.
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.
1197 int32_t get(EDateFields field
, UErrorCode
& status
) const;
1198 #endif /* U_HIDE_DEPRECATED_API */
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.
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.
1213 int32_t get(UCalendarDateFields field
, UErrorCode
& status
) const;
1215 #ifndef U_HIDE_DEPRECATED_API
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.
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.
1224 UBool
isSet(EDateFields field
) const;
1225 #endif /* U_HIDE_DEPRECATED_API */
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.
1231 * @param field The given time field.
1232 * @return True if the given time field has a value set; false otherwise.
1235 UBool
isSet(UCalendarDateFields field
) const;
1237 #ifndef U_HIDE_DEPRECATED_API
1239 * Sets the given time field with the given value.
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.
1245 void set(EDateFields field
, int32_t value
);
1246 #endif /* U_HIDE_DEPRECATED_API */
1249 * Sets the given time field with the given value.
1251 * @param field The given time field.
1252 * @param value The value to be set for the given time field.
1255 void set(UCalendarDateFields field
, int32_t value
);
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.
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.
1267 void set(int32_t year
, int32_t month
, int32_t date
);
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.
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.
1281 void set(int32_t year
, int32_t month
, int32_t date
, int32_t hour
, int32_t minute
);
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.
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.
1296 void set(int32_t year
, int32_t month
, int32_t date
, int32_t hour
, int32_t minute
, int32_t second
);
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.
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.
1315 #ifndef U_HIDE_DEPRECATED_API
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.
1321 * @param field The time field to be cleared.
1322 * @deprecated ICU 2.6. Use clear(UCalendarDateFields field) instead.
1324 void clear(EDateFields field
);
1325 #endif /* U_HIDE_DEPRECATED_API */
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.
1332 * @param field The time field to be cleared.
1335 void clear(UCalendarDateFields field
);
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.
1342 * Concrete subclasses of Calendar must implement getDynamicClassID() and also a
1343 * static method and data member:
1345 * static UClassID getStaticClassID() { return (UClassID)&fgClassID; }
1346 * static char fgClassID;
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.
1352 virtual UClassID
getDynamicClassID(void) const = 0;
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".
1359 * See type="old type name" for the calendar attribute of locale IDs
1360 * at http://www.unicode.org/reports/tr35/#Key_Type_Definitions
1362 * Sample code for getting the LDML/BCP 47 calendar key value:
1364 * const char *calType = cal->getType();
1365 * if (0 == strcmp(calType, "unknown")) {
1366 * // deal with unknown calendar type
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
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
1383 * @return legacy calendar type name string
1386 virtual const char * getType() const = 0;
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
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.
1404 virtual UCalendarWeekdayType
getDayOfWeekType(UCalendarDaysOfWeek dayOfWeek
, UErrorCode
&status
) const;
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.
1420 virtual int32_t getWeekendTransition(UCalendarDaysOfWeek dayOfWeek
, UErrorCode
&status
) const;
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.
1431 virtual UBool
isWeekend(UDate date
, UErrorCode
&status
) const;
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.
1440 virtual UBool
isWeekend(void) const;
1445 * Constructs a Calendar with the default time zone as returned by
1446 * TimeZone::createInstance(), and the default locale.
1448 * @param success Indicates the status of Calendar object construction. Returns
1449 * U_ZERO_ERROR if constructed successfully.
1452 Calendar(UErrorCode
& success
);
1457 * @param source Calendar object to be copied from
1460 Calendar(const Calendar
& source
);
1463 * Default assignment operator
1465 * @param right Calendar object to be copied
1468 Calendar
& operator=(const Calendar
& right
);
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.
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.
1480 Calendar(TimeZone
* zone
, const Locale
& aLocale
, UErrorCode
& success
);
1483 * Constructs a Calendar with the given time zone and locale.
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.
1491 Calendar(const TimeZone
& zone
, const Locale
& aLocale
, UErrorCode
& success
);
1494 * Converts Calendar's time field values to GMT as milliseconds.
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.
1501 virtual void computeTime(UErrorCode
& status
);
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().
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.
1514 virtual void computeFields(UErrorCode
& status
);
1517 * Gets this Calendar's current time as a long.
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.
1525 double getTimeInMillis(UErrorCode
& status
) const;
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.
1535 void setTimeInMillis( double millis
, UErrorCode
& status
);
1538 * Recomputes the current time from currently set fields, and then fills in any
1539 * unset fields in the time field list.
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.
1546 void complete(UErrorCode
& status
);
1548 #ifndef U_HIDE_DEPRECATED_API
1550 * Gets the value for a given time field. Subclasses can use this function to get
1551 * field values without forcing recomputation of time.
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.
1557 inline int32_t internalGet(EDateFields field
) const {return fFields
[field
];}
1558 #endif /* U_HIDE_DEPRECATED_API */
1560 #ifndef U_HIDE_INTERNAL_API
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.
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.
1571 inline int32_t internalGet(UCalendarDateFields field
, int32_t defaultValue
) const {return fStamp
[field
]>kUnset
? fFields
[field
] : defaultValue
;}
1574 * Gets the value for a given time field. Subclasses can use this function to get
1575 * field values without forcing recomputation of time.
1577 * @param field The given time field.
1578 * @return The value for the given time field.
1581 inline int32_t internalGet(UCalendarDateFields field
) const {return fFields
[field
];}
1582 #endif /* U_HIDE_INTERNAL_API */
1584 #ifndef U_HIDE_DEPRECATED_API
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
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.
1594 void internalSet(EDateFields field
, int32_t value
);
1595 #endif /* U_HIDE_DEPRECATED_API */
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
1602 * @param field The given time field.
1603 * @param value The value for the given time field.
1606 inline void internalSet(UCalendarDateFields field
, int32_t value
);
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.
1614 virtual void prepareGetActual(UCalendarDateFields field
, UBool isMinimum
, UErrorCode
&status
);
1617 * Limit enums. Not in sync with UCalendarLimitType (refers to internal fields).
1621 #ifndef U_HIDE_INTERNAL_API
1622 UCAL_LIMIT_MINIMUM
= 0,
1623 UCAL_LIMIT_GREATEST_MINIMUM
,
1624 UCAL_LIMIT_LEAST_MAXIMUM
,
1627 #endif /* U_HIDE_INTERNAL_API */
1631 * Subclass API for defining limits of different types.
1632 * Subclasses must implement this method to return limits for the
1639 * UCAL_WEEK_OF_MONTH
1640 * UCAL_DATE (DAY_OF_MONTH on Java)
1642 * UCAL_DAY_OF_WEEK_IN_MONTH
1644 * UCAL_EXTENDED_YEAR</pre>
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>
1651 virtual int32_t handleGetLimit(UCalendarDateFields field
, ELimitType limitType
) const = 0;
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
1660 virtual int32_t getLimit(UCalendarDateFields field
, ELimitType limitType
) const;
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
1672 * @return the Julian day number of the day before the first
1673 * day of the given month and year
1676 virtual int32_t handleComputeMonthStart(int32_t eyear
, int32_t month
,
1677 UBool useMonth
) const = 0;
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.
1686 virtual int32_t handleGetMonthLength(int32_t extendedYear
, int32_t month
) const ;
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.
1695 virtual int32_t handleGetYearLength(int32_t eyear
) const;
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
1703 * @return the extended year
1706 virtual int32_t handleGetExtendedYear() = 0;
1709 * Subclasses may override this. This method calls
1710 * handleGetMonthLength() to obtain the calendar-specific month
1712 * @param bestField which field to use to calculate the date
1713 * @return julian day specified by calendar fields.
1716 virtual int32_t handleComputeJulianDay(UCalendarDateFields bestField
);
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
1726 virtual int32_t handleGetExtendedYearFromWeekFields(int32_t yearWoy
, int32_t woy
);
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&)
1736 virtual void validateField(UCalendarDateFields field
, UErrorCode
&status
);
1738 #ifndef U_HIDE_INTERNAL_API
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
1745 int32_t computeJulianDay();
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.
1754 double computeMillisInDay();
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
1761 * @param ec Output param set to failure code on function return
1762 * when this function fails.
1765 int32_t computeZoneOffset(double millis
, double millisInDay
, UErrorCode
&ec
);
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
1776 int32_t newestStamp(UCalendarDateFields start
, UCalendarDateFields end
, int32_t bestSoFar
) const;
1779 * Values for field resolution tables
1780 * @see #resolveFields
1784 /** Marker for end of resolve set (row or group). */
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. */
1791 * Precedence table for Dates
1792 * @see #resolveFields
1795 static const UFieldResolutionTable kDatePrecedence
[];
1798 * Precedence table for Year
1799 * @see #resolveFields
1802 static const UFieldResolutionTable kYearPrecedence
[];
1805 * Precedence table for Day of Week
1806 * @see #resolveFields
1809 static const UFieldResolutionTable kDOWPrecedence
[];
1812 * Given a precedence table, return the newest field combination in
1813 * the table, or UCAL_FIELD_COUNT if none is found.
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.
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.
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.
1838 UCalendarDateFields
resolveFields(const UFieldResolutionTable
*precedenceTable
);
1839 #endif /* U_HIDE_INTERNAL_API */
1845 virtual const UFieldResolutionTable
* getFieldResolutionTable() const;
1847 #ifndef U_HIDE_INTERNAL_API
1849 * Return the field that is newer, either defaultField, or
1850 * alternateField. If neither is newer or neither is set, return defaultField.
1853 UCalendarDateFields
newerField(UCalendarDateFields defaultField
, UCalendarDateFields alternateField
) const;
1854 #endif /* U_HIDE_INTERNAL_API */
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
1866 int32_t getActualHelper(UCalendarDateFields field
, int32_t startValue
, int32_t endValue
, UErrorCode
&status
) const;
1871 * The flag which indicates if the current time is set in the calendar.
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
1882 * This should really be named areFieldsInSync, but the old name is retained
1883 * for backward compatibility.
1886 UBool fAreFieldsSet
;
1889 * True if all of the fields have been set. This is initially false, and set to
1890 * true by computeFields().
1893 UBool fAreAllFieldsSet
;
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.
1902 UBool fAreFieldsVirtuallySet
;
1905 * Get the current time without recomputing.
1907 * @return the current time without recomputing.
1910 UDate
internalGetTime(void) const { return fTime
; }
1913 * Set the current time without affecting flags or fields.
1915 * @param time The time to be set
1916 * @return the current time without recomputing.
1919 void internalSetTime(UDate time
) { fTime
= time
; }
1922 * The time fields containing values into which the millis is computed.
1925 int32_t fFields
[UCAL_FIELD_COUNT
];
1928 * The flags which tell if a specified time field for the calendar is set.
1929 * @deprecated ICU 2.8 use (fStamp[n]!=kUnset)
1931 UBool fIsSet
[UCAL_FIELD_COUNT
];
1933 /** Special values of stamp[]
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.
1948 int32_t fStamp
[UCAL_FIELD_COUNT
];
1951 * Subclasses may override this method to compute several fields
1952 * specific to each calendar system. These are:
1959 * <li>EXTENDED_YEAR</ul>
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.
1966 * <p>In addition, subclasses should compute any subclass-specific
1967 * fields, that is, fields from BASE_FIELD_COUNT to
1968 * getFieldCount() - 1.
1970 * <p>The default implementation in <code>Calendar</code> implements
1971 * a pure proleptic Gregorian calendar.
1974 virtual void handleComputeFields(int32_t julianDay
, UErrorCode
&status
);
1976 #ifndef U_HIDE_INTERNAL_API
1978 * Return the extended year on the Gregorian calendar as computed by
1979 * <code>computeGregorianFields()</code>.
1982 int32_t getGregorianYear() const {
1983 return fGregorianYear
;
1987 * Return the month (0-based) on the Gregorian calendar as computed by
1988 * <code>computeGregorianFields()</code>.
1991 int32_t getGregorianMonth() const {
1992 return fGregorianMonth
;
1996 * Return the day of year (1-based) on the Gregorian calendar as
1997 * computed by <code>computeGregorianFields()</code>.
2000 int32_t getGregorianDayOfYear() const {
2001 return fGregorianDayOfYear
;
2005 * Return the day of month (1-based) on the Gregorian calendar as
2006 * computed by <code>computeGregorianFields()</code>.
2009 int32_t getGregorianDayOfMonth() const {
2010 return fGregorianDayOfMonth
;
2012 #endif /* U_HIDE_INTERNAL_API */
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
2020 virtual int32_t getDefaultMonthInYear(int32_t eyear
) ;
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
2030 virtual int32_t getDefaultDayInMonth(int32_t eyear
, int32_t month
);
2032 //-------------------------------------------------------------------------
2033 // Protected utility methods for use by subclasses. These are very handy
2034 // for implementing add, roll, and computeFields.
2035 //-------------------------------------------------------------------------
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
2044 * <b>Subclassing:</b>
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}.
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.
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.
2062 * @see #getActualMinimum
2063 * @see #getActualMaximum
2066 virtual void pinField(UCalendarDateFields field
, UErrorCode
& status
);
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.
2078 * <b>Subclassing:</b>
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.
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.
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.
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.
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.
2104 * @return The week number (one-based), or zero if the day falls before
2105 * the first week because
2106 * {@link #getMinimalDaysInFirstWeek getMinimalDaysInFirstWeek}
2111 int32_t weekNumber(int32_t desiredDay
, int32_t dayOfPeriod
, int32_t dayOfWeek
);
2114 #ifndef U_HIDE_INTERNAL_API
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.
2124 * <b>Subclassing:</b>
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.
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.
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.
2139 * @return The week number (one-based), or zero if the day falls before
2140 * the first week because
2141 * {@link #getMinimalDaysInFirstWeek getMinimalDaysInFirstWeek}
2145 inline int32_t weekNumber(int32_t dayOfPeriod
, int32_t dayOfWeek
);
2148 * returns the local DOW, valid range 0..6
2151 int32_t getLocalDOW();
2152 #endif /* U_HIDE_INTERNAL_API */
2157 * The next available value for fStamp[]
2159 int32_t fNextStamp
;// = MINIMUM_USER_STAMP;
2162 * Recalculates the time stamp array (fStamp).
2163 * Resets fNextStamp to lowest next stamp value.
2165 void recalculateStamp();
2168 * The current time set for the calendar.
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.
2184 * Option for rpeated wall time
2185 * @see #setRepeatedWallTimeOption
2187 UCalendarWallTimeOption fRepeatedWallTime
;
2190 * Option for skipped wall time
2191 * @see #setSkippedWallTimeOption
2193 UCalendarWallTimeOption fSkippedWallTime
;
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.
2203 UCalendarDaysOfWeek fFirstDayOfWeek
;
2204 uint8_t fMinimalDaysInFirstWeek
;
2205 UCalendarDaysOfWeek fWeekendOnset
;
2206 int32_t fWeekendOnsetMillis
;
2207 UCalendarDaysOfWeek fWeekendCease
;
2208 int32_t fWeekendCeaseMillis
;
2211 * Sets firstDayOfWeek and minimalDaysInFirstWeek. Called at Calendar construction
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.
2220 void setWeekData(const Locale
& desiredLocale
, const char *type
, UErrorCode
& success
);
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.
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.
2231 void updateTime(UErrorCode
& status
);
2234 * The Gregorian year, as computed by computeGregorianFields() and
2235 * returned by getGregorianYear().
2236 * @see #computeGregorianFields
2238 int32_t fGregorianYear
;
2241 * The Gregorian month, as computed by computeGregorianFields() and
2242 * returned by getGregorianMonth().
2243 * @see #computeGregorianFields
2245 int32_t fGregorianMonth
;
2248 * The Gregorian day of the year, as computed by
2249 * computeGregorianFields() and returned by getGregorianDayOfYear().
2250 * @see #computeGregorianFields
2252 int32_t fGregorianDayOfYear
;
2255 * The Gregorian day of the month, as computed by
2256 * computeGregorianFields() and returned by getGregorianDayOfMonth().
2257 * @see #computeGregorianFields
2259 int32_t fGregorianDayOfMonth
;
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
2269 void computeGregorianAndDOWFields(int32_t julianDay
, UErrorCode
&ec
);
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.
2280 void computeGregorianFields(int32_t julianDay
, UErrorCode
&ec
);
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.
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.
2304 void computeWeekFields(UErrorCode
&ec
);
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.
2312 * @see #validateField(int, int&)
2315 void validateFields(UErrorCode
&status
);
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&)}.
2325 void validateField(UCalendarDateFields field
, int32_t min
, int32_t max
, UErrorCode
& status
);
2328 #ifndef U_HIDE_INTERNAL_API
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.
2334 * @param julian The given Julian date number.
2335 * @return Day number from 1..7 (SUN..SAT).
2338 static uint8_t julianDayToDayOfWeek(double julian
);
2339 #endif /* U_HIDE_INTERNAL_API */
2342 char validLocale
[ULOC_FULLNAME_CAPACITY
];
2343 char actualLocale
[ULOC_FULLNAME_CAPACITY
];
2346 #if !UCONFIG_NO_SERVICE
2348 * INTERNAL FOR 2.6 -- Registration.
2351 #ifndef U_HIDE_INTERNAL_API
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
2358 static StringEnumeration
* getAvailableLocales(void);
2361 * Register a new Calendar factory. The factory will be adopted.
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.
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
2373 static URegistryKey
registerFactory(ICUServiceFactory
* toAdopt
, UErrorCode
& status
);
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.
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.
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
2390 static UBool
unregister(URegistryKey key
, UErrorCode
& status
);
2391 #endif /* U_HIDE_INTERNAL_API */
2394 * Multiple Calendar Implementation
2397 friend class CalendarFactory
;
2400 * Multiple Calendar Implementation
2403 friend class CalendarService
;
2406 * Multiple Calendar Implementation
2409 friend class DefaultCalendarFactory
;
2410 #endif /* !UCONFIG_NO_SERVICE */
2413 * @return TRUE if this calendar has a default century (i.e. 03 -> 2003)
2416 virtual UBool
haveDefaultCentury() const = 0;
2419 * @return the start of the default century, as a UDate
2422 virtual UDate
defaultCenturyStart() const = 0;
2424 * @return the beginning year of the default century, as a year
2427 virtual int32_t defaultCenturyStartYear() const = 0;
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
2435 Locale
getLocale(ULocDataLocaleType type
, UErrorCode
&status
) const;
2438 * @return The related Gregorian year; will be obtained by modifying the value
2439 * obtained by get from UCAL_EXTENDED_YEAR field
2442 virtual int32_t getRelatedYear(UErrorCode
&status
) const;
2445 * @param year The related Gregorian year to set; will be modified as necessary then
2446 * set in UCAL_EXTENDED_YEAR field
2449 virtual void setRelatedYear(int32_t year
);
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
2458 const char* getLocaleID(ULocDataLocaleType type
, UErrorCode
&status
) const;
2459 #endif /* U_HIDE_INTERNAL_API */
2463 * Cast TimeZone used by this object to BasicTimeZone, or NULL if the TimeZone
2464 * is not an instance of BasicTimeZone.
2466 BasicTimeZone
* getBasicTimeZone() const;
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.
2475 UBool
getImmediatePreviousZoneTransition(UDate base
, UDate
*transitionTime
, UErrorCode
& status
) const;
2478 #ifndef U_HIDE_INTERNAL_API
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.
2487 static Calendar
* U_EXPORT2
makeInstance(
2488 const Locale
&locale
, UErrorCode
&status
);
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.
2500 static void U_EXPORT2
getCalendarTypeFromLocale(
2501 const Locale
&locale
,
2503 int32_t typeBufferSize
,
2504 UErrorCode
&status
);
2505 #endif /* U_HIDE_INTERNAL_API */
2508 // -------------------------------------
2511 Calendar::createInstance(TimeZone
* zone
, UErrorCode
& errorCode
)
2513 // since the Locale isn't specified, use the default locale
2514 return createInstance(zone
, Locale::getDefault(), errorCode
);
2517 // -------------------------------------
2520 Calendar::roll(UCalendarDateFields field
, UBool up
, UErrorCode
& status
)
2522 roll(field
, (int32_t)(up
? +1 : -1), status
);
2525 #ifndef U_HIDE_DEPRECATED_API
2527 Calendar::roll(EDateFields field
, UBool up
, UErrorCode
& status
)
2529 roll((UCalendarDateFields
) field
, up
, status
);
2531 #endif /* U_HIDE_DEPRECATED_API */
2534 // -------------------------------------
2537 * Fast method for subclasses. The caller must maintain fUserSetDSTOffset and
2538 * fUserSetZoneOffset, as well as the isSet[] array.
2542 Calendar::internalSet(UCalendarDateFields field
, int32_t value
)
2544 fFields
[field
] = value
;
2545 fStamp
[field
] = kInternallySet
;
2546 fIsSet
[field
] = TRUE
; // Remove later
2550 #ifndef U_HIDE_INTERNAL_API
2551 inline int32_t Calendar::weekNumber(int32_t dayOfPeriod
, int32_t dayOfWeek
)
2553 return weekNumber(dayOfPeriod
, dayOfPeriod
, dayOfWeek
);
2555 #endif /* U_HIDE_INTERNAL_API */
2558 #endif // U_SHOW_CPLUSPLUS_API
2560 #endif /* #if !UCONFIG_NO_FORMATTING */