2 ********************************************************************************
3 * Copyright (C) 1997-2012, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 ********************************************************************************
9 * Modification History:
11 * Date Name Description
12 * 04/22/97 aliu Expanded and corrected comments and other header
14 * 05/01/97 aliu Made equals(), before(), after() arguments const.
15 * 05/20/97 aliu Replaced fAreFieldsSet with fAreFieldsInSync and
17 * 07/27/98 stephen Sync up with JDK 1.2
18 * 11/15/99 weiv added YEAR_WOY and DOW_LOCAL
20 * 8/19/2002 srl Removed Javaisms
21 * 11/07/2003 srl Update, clean up documentation.
22 ********************************************************************************
28 #include "unicode/utypes.h"
32 * \brief C++ API: Calendar object
34 #if !UCONFIG_NO_FORMATTING
36 #include "unicode/uobject.h"
37 #include "unicode/locid.h"
38 #include "unicode/timezone.h"
39 #include "unicode/ucal.h"
40 #include "unicode/umisc.h"
44 class ICUServiceFactory
;
49 typedef int32_t UFieldResolutionTable
[12][8];
53 * <code>Calendar</code> is an abstract base class for converting between
54 * a <code>UDate</code> object and a set of integer fields such as
55 * <code>YEAR</code>, <code>MONTH</code>, <code>DAY</code>, <code>HOUR</code>,
56 * and so on. (A <code>UDate</code> object represents a specific instant in
57 * time with millisecond precision. See UDate
58 * for information about the <code>UDate</code> class.)
61 * Subclasses of <code>Calendar</code> interpret a <code>UDate</code>
62 * according to the rules of a specific calendar system.
63 * The most commonly used subclass of <code>Calendar</code> is
64 * <code>GregorianCalendar</code>. Other subclasses could represent
65 * the various types of lunar calendars in use in many parts of the world.
68 * <b>NOTE</b>: (ICU 2.6) The subclass interface should be considered unstable
72 * Like other locale-sensitive classes, <code>Calendar</code> provides a
73 * static method, <code>createInstance</code>, for getting a generally useful
74 * object of this type. <code>Calendar</code>'s <code>createInstance</code> method
75 * returns the appropriate <code>Calendar</code> subclass whose
76 * time fields have been initialized with the current date and time:
77 * \htmlonly<blockquote>\endhtmlonly
79 * Calendar *rightNow = Calendar::createInstance(errCode);
81 * \htmlonly</blockquote>\endhtmlonly
84 * A <code>Calendar</code> object can produce all the time field values
85 * needed to implement the date-time formatting for a particular language
86 * and calendar style (for example, Japanese-Gregorian, Japanese-Traditional).
89 * When computing a <code>UDate</code> from time fields, two special circumstances
90 * may arise: there may be insufficient information to compute the
91 * <code>UDate</code> (such as only year and month but no day in the month),
92 * or there may be inconsistent information (such as "Tuesday, July 15, 1996"
93 * -- July 15, 1996 is actually a Monday).
96 * <strong>Insufficient information.</strong> The calendar will use default
97 * information to specify the missing fields. This may vary by calendar; for
98 * the Gregorian calendar, the default for a field is the same as that of the
99 * start of the epoch: i.e., YEAR = 1970, MONTH = JANUARY, DATE = 1, etc.
102 * <strong>Inconsistent information.</strong> If fields conflict, the calendar
103 * will give preference to fields set more recently. For example, when
104 * determining the day, the calendar will look for one of the following
105 * combinations of fields. The most recent combination, as determined by the
106 * most recently set single field, will be used.
108 * \htmlonly<blockquote>\endhtmlonly
110 * MONTH + DAY_OF_MONTH
111 * MONTH + WEEK_OF_MONTH + DAY_OF_WEEK
112 * MONTH + DAY_OF_WEEK_IN_MONTH + DAY_OF_WEEK
114 * DAY_OF_WEEK + WEEK_OF_YEAR
116 * \htmlonly</blockquote>\endhtmlonly
118 * For the time of day:
120 * \htmlonly<blockquote>\endhtmlonly
125 * \htmlonly</blockquote>\endhtmlonly
128 * <strong>Note:</strong> for some non-Gregorian calendars, different
129 * fields may be necessary for complete disambiguation. For example, a full
130 * specification of the historial Arabic astronomical calendar requires year,
131 * month, day-of-month <em>and</em> day-of-week in some cases.
134 * <strong>Note:</strong> There are certain possible ambiguities in
135 * interpretation of certain singular times, which are resolved in the
138 * <li> 24:00:00 "belongs" to the following day. That is,
139 * 23:59 on Dec 31, 1969 < 24:00 on Jan 1, 1970 < 24:01:00 on Jan 1, 1970
141 * <li> Although historically not precise, midnight also belongs to "am",
142 * and noon belongs to "pm", so on the same day,
143 * 12:00 am (midnight) < 12:01 am, and 12:00 pm (noon) < 12:01 pm
147 * The date or time format strings are not part of the definition of a
148 * calendar, as those must be modifiable or overridable by the user at
149 * runtime. Use {@link DateFormat}
153 * <code>Calendar</code> provides an API for field "rolling", where fields
154 * can be incremented or decremented, but wrap around. For example, rolling the
155 * month up in the date <code>December 12, <b>1996</b></code> results in
156 * <code>January 12, <b>1996</b></code>.
159 * <code>Calendar</code> also provides a date arithmetic function for
160 * adding the specified (signed) amount of time to a particular time field.
161 * For example, subtracting 5 days from the date <code>September 12, 1996</code>
162 * results in <code>September 7, 1996</code>.
166 class U_I18N_API Calendar
: public UObject
{
170 * Field IDs for date and time. Used to specify date/time fields. ERA is calendar
171 * specific. Example ranges given are for illustration only; see specific Calendar
172 * subclasses for actual ranges.
173 * @deprecated ICU 2.6. Use C enum UCalendarDateFields defined in ucal.h
176 #ifndef U_HIDE_DEPRECATED_API
178 * ERA may be defined on other platforms. To avoid any potential problems undefined it here.
183 ERA
, // Example: 0..1
184 YEAR
, // Example: 1..big number
185 MONTH
, // Example: 0..11
186 WEEK_OF_YEAR
, // Example: 1..53
187 WEEK_OF_MONTH
, // Example: 1..4
188 DATE
, // Example: 1..31
189 DAY_OF_YEAR
, // Example: 1..365
190 DAY_OF_WEEK
, // Example: 1..7
191 DAY_OF_WEEK_IN_MONTH
, // Example: 1..4, may be specified as -1
192 AM_PM
, // Example: 0..1
193 HOUR
, // Example: 0..11
194 HOUR_OF_DAY
, // Example: 0..23
195 MINUTE
, // Example: 0..59
196 SECOND
, // Example: 0..59
197 MILLISECOND
, // Example: 0..999
198 ZONE_OFFSET
, // Example: -12*U_MILLIS_PER_HOUR..12*U_MILLIS_PER_HOUR
199 DST_OFFSET
, // Example: 0 or U_MILLIS_PER_HOUR
200 YEAR_WOY
, // 'Y' Example: 1..big number - Year of Week of Year
201 DOW_LOCAL
, // 'e' Example: 1..7 - Day of Week / Localized
208 FIELD_COUNT
= UCAL_FIELD_COUNT
// See ucal.h for other fields.
209 #endif /* U_HIDE_DEPRECATED_API */
212 #ifndef U_HIDE_DEPRECATED_API
214 * Useful constant for days of week. Note: Calendar day-of-week is 1-based. Clients
215 * who create locale resources for the field of first-day-of-week should be aware of
216 * this. For instance, in US locale, first-day-of-week is set to 1, i.e., SUNDAY.
217 * @deprecated ICU 2.6. Use C enum UCalendarDaysOfWeek defined in ucal.h
230 * Useful constants for month. Note: Calendar month is 0-based.
231 * @deprecated ICU 2.6. Use C enum UCalendarMonths defined in ucal.h
250 * Useful constants for hour in 12-hour clock. Used in GregorianCalendar.
251 * @deprecated ICU 2.6. Use C enum UCalendarAMPMs defined in ucal.h
257 #endif /* U_HIDE_DEPRECATED_API */
266 * Create and return a polymorphic copy of this calendar.
268 * @return a polymorphic copy of this calendar.
271 virtual Calendar
* clone(void) const = 0;
274 * Creates a Calendar using the default timezone and locale. Clients are responsible
275 * for deleting the object returned.
277 * @param success Indicates the success/failure of Calendar creation. Filled in
278 * with U_ZERO_ERROR if created successfully, set to a failure result
279 * otherwise. U_MISSING_RESOURCE_ERROR will be returned if the resource data
280 * requests a calendar type which has not been installed.
281 * @return A Calendar if created successfully. NULL otherwise.
284 static Calendar
* U_EXPORT2
createInstance(UErrorCode
& success
);
287 * Creates a Calendar using the given timezone and the default locale.
288 * The Calendar takes ownership of zoneToAdopt; the
289 * client must not delete it.
291 * @param zoneToAdopt The given timezone to be adopted.
292 * @param success Indicates the success/failure of Calendar creation. Filled in
293 * with U_ZERO_ERROR if created successfully, set to a failure result
295 * @return A Calendar if created successfully. NULL otherwise.
298 static Calendar
* U_EXPORT2
createInstance(TimeZone
* zoneToAdopt
, UErrorCode
& success
);
301 * Creates a Calendar using the given timezone and the default locale. The TimeZone
302 * is _not_ adopted; the client is still responsible for deleting it.
304 * @param zone The timezone.
305 * @param success Indicates the success/failure of Calendar creation. Filled in
306 * with U_ZERO_ERROR if created successfully, set to a failure result
308 * @return A Calendar if created successfully. NULL otherwise.
311 static Calendar
* U_EXPORT2
createInstance(const TimeZone
& zone
, UErrorCode
& success
);
314 * Creates a Calendar using the default timezone and the given locale.
316 * @param aLocale The given locale.
317 * @param success Indicates the success/failure of Calendar creation. Filled in
318 * with U_ZERO_ERROR if created successfully, set to a failure result
320 * @return A Calendar if created successfully. NULL otherwise.
323 static Calendar
* U_EXPORT2
createInstance(const Locale
& aLocale
, UErrorCode
& success
);
326 * Creates a Calendar using the given timezone and given locale.
327 * The Calendar takes ownership of zoneToAdopt; the
328 * client must not delete it.
330 * @param zoneToAdopt The given timezone to be adopted.
331 * @param aLocale The given locale.
332 * @param success Indicates the success/failure of Calendar creation. Filled in
333 * with U_ZERO_ERROR if created successfully, set to a failure result
335 * @return A Calendar if created successfully. NULL otherwise.
338 static Calendar
* U_EXPORT2
createInstance(TimeZone
* zoneToAdopt
, const Locale
& aLocale
, UErrorCode
& success
);
341 * Gets a Calendar using the given timezone and given locale. The TimeZone
342 * is _not_ adopted; the client is still responsible for deleting it.
344 * @param zoneToAdopt The given timezone to be adopted.
345 * @param aLocale The given locale.
346 * @param success Indicates the success/failure of Calendar creation. Filled in
347 * with U_ZERO_ERROR if created successfully, set to a failure result
349 * @return A Calendar if created successfully. NULL otherwise.
352 static Calendar
* U_EXPORT2
createInstance(const TimeZone
& zoneToAdopt
, const Locale
& aLocale
, UErrorCode
& success
);
355 * Returns a list of the locales for which Calendars are installed.
357 * @param count Number of locales returned.
358 * @return An array of Locale objects representing the set of locales for which
359 * Calendars are installed. The system retains ownership of this list;
360 * the caller must NOT delete it. Does not include user-registered Calendars.
363 static const Locale
* U_EXPORT2
getAvailableLocales(int32_t& count
);
367 * Given a key and a locale, returns an array of string values in a preferred
368 * order that would make a difference. These are all and only those values where
369 * the open (creation) of the service with the locale formed from the input locale
370 * plus input keyword and that value has different behavior than creation with the
371 * input locale alone.
372 * @param key one of the keys supported by this service. For now, only
373 * "calendar" is supported.
374 * @param locale the locale
375 * @param commonlyUsed if set to true it will return only commonly used values
376 * with the given locale in preferred order. Otherwise,
377 * it will return all the available values for the locale.
378 * @param status ICU Error Code
379 * @return a string enumeration over keyword values for the given key and the locale.
382 static StringEnumeration
* U_EXPORT2
getKeywordValuesForLocale(const char* key
,
383 const Locale
& locale
, UBool commonlyUsed
, UErrorCode
& status
);
386 * Returns the current UTC (GMT) time measured in milliseconds since 0:00:00 on 1/1/70
387 * (derived from the system time).
389 * @return The current UTC time in milliseconds.
392 static UDate U_EXPORT2
getNow(void);
395 * Gets this Calendar's time as milliseconds. May involve recalculation of time due
396 * to previous calls to set time field values. The time specified is non-local UTC
397 * (GMT) time. Although this method is const, this object may actually be changed
398 * (semantically const).
400 * @param status Output param set to success/failure code on exit. If any value
401 * previously set in the time field is invalid or restricted by
402 * leniency, this will be set to an error status.
403 * @return The current time in UTC (GMT) time, or zero if the operation
407 inline UDate
getTime(UErrorCode
& status
) const { return getTimeInMillis(status
); }
410 * Sets this Calendar's current time with the given UDate. The time specified should
411 * be in non-local UTC (GMT) time.
413 * @param date The given UDate in UTC (GMT) time.
414 * @param status Output param set to success/failure code on exit. If any value
415 * set in the time field is invalid or restricted by
416 * leniency, this will be set to an error status.
419 inline void setTime(UDate date
, UErrorCode
& status
) { setTimeInMillis(date
, status
); }
422 * Compares the equality of two Calendar objects. Objects of different subclasses
423 * are considered unequal. This comparison is very exacting; two Calendar objects
424 * must be in exactly the same state to be considered equal. To compare based on the
425 * represented time, use equals() instead.
427 * @param that The Calendar object to be compared with.
428 * @return True if the given Calendar is the same as this Calendar; false
432 virtual UBool
operator==(const Calendar
& that
) const;
435 * Compares the inequality of two Calendar objects.
437 * @param that The Calendar object to be compared with.
438 * @return True if the given Calendar is not the same as this Calendar; false
442 UBool
operator!=(const Calendar
& that
) const {return !operator==(that
);}
445 * Returns TRUE if the given Calendar object is equivalent to this
446 * one. An equivalent Calendar will behave exactly as this one
447 * does, but it may be set to a different time. By contrast, for
448 * the operator==() method to return TRUE, the other Calendar must
449 * be set to the same time.
451 * @param other the Calendar to be compared with this Calendar
454 virtual UBool
isEquivalentTo(const Calendar
& other
) const;
457 * Compares the Calendar time, whereas Calendar::operator== compares the equality of
460 * @param when The Calendar to be compared with this Calendar. Although this is a
461 * const parameter, the object may be modified physically
462 * (semantically const).
463 * @param status Output param set to success/failure code on exit. If any value
464 * previously set in the time field is invalid or restricted by
465 * leniency, this will be set to an error status.
466 * @return True if the current time of this Calendar is equal to the time of
467 * Calendar when; false otherwise.
470 UBool
equals(const Calendar
& when
, UErrorCode
& status
) const;
473 * Returns true if this Calendar's current time is before "when"'s current time.
475 * @param when The Calendar to be compared with this Calendar. Although this is a
476 * const parameter, the object may be modified physically
477 * (semantically const).
478 * @param status Output param set to success/failure code on exit. If any value
479 * previously set in the time field is invalid or restricted by
480 * leniency, this will be set to an error status.
481 * @return True if the current time of this Calendar is before the time of
482 * Calendar when; false otherwise.
485 UBool
before(const Calendar
& when
, UErrorCode
& status
) const;
488 * Returns true if this Calendar's current time is after "when"'s current time.
490 * @param when The Calendar to be compared with this Calendar. Although this is a
491 * const parameter, the object may be modified physically
492 * (semantically const).
493 * @param status Output param set to success/failure code on exit. If any value
494 * previously set in the time field is invalid or restricted by
495 * leniency, this will be set to an error status.
496 * @return True if the current time of this Calendar is after the time of
497 * Calendar when; false otherwise.
500 UBool
after(const Calendar
& when
, UErrorCode
& status
) const;
503 * UDate Arithmetic function. Adds the specified (signed) amount of time to the given
504 * time field, based on the calendar's rules. For example, to subtract 5 days from
505 * the current time of the calendar, call add(Calendar::DATE, -5). When adding on
506 * the month or Calendar::MONTH field, other fields like date might conflict and
507 * need to be changed. For instance, adding 1 month on the date 01/31/96 will result
510 * @param field Specifies which date field to modify.
511 * @param amount The amount of time to be added to the field, in the natural unit
512 * for that field (e.g., days for the day fields, hours for the hour
514 * @param status Output param set to success/failure code on exit. If any value
515 * previously set in the time field is invalid or restricted by
516 * leniency, this will be set to an error status.
517 * @deprecated ICU 2.6. use add(UCalendarDateFields field, int32_t amount, UErrorCode& status) instead.
519 virtual void add(EDateFields field
, int32_t amount
, UErrorCode
& status
);
522 * UDate Arithmetic function. Adds the specified (signed) amount of time to the given
523 * time field, based on the calendar's rules. For example, to subtract 5 days from
524 * the current time of the calendar, call add(Calendar::DATE, -5). When adding on
525 * the month or Calendar::MONTH field, other fields like date might conflict and
526 * need to be changed. For instance, adding 1 month on the date 01/31/96 will result
529 * @param field Specifies which date field to modify.
530 * @param amount The amount of time to be added to the field, in the natural unit
531 * for that field (e.g., days for the day fields, hours for the hour
533 * @param status Output param set to success/failure code on exit. If any value
534 * previously set in the time field is invalid or restricted by
535 * leniency, this will be set to an error status.
538 virtual void add(UCalendarDateFields field
, int32_t amount
, UErrorCode
& status
);
540 #ifndef U_HIDE_DEPRECATED_API
542 * Time Field Rolling function. Rolls (up/down) a single unit of time on the given
543 * time field. For example, to roll the current date up by one day, call
544 * roll(Calendar::DATE, true). When rolling on the year or Calendar::YEAR field, it
545 * will roll the year value in the range between getMinimum(Calendar::YEAR) and the
546 * value returned by getMaximum(Calendar::YEAR). When rolling on the month or
547 * Calendar::MONTH field, other fields like date might conflict and, need to be
548 * changed. For instance, rolling the month up on the date 01/31/96 will result in
549 * 02/29/96. Rolling up always means rolling forward in time; e.g., rolling the year
550 * up on "100 BC" will result in "99 BC", for Gregorian calendar. When rolling on the
551 * hour-in-day or Calendar::HOUR_OF_DAY field, it will roll the hour value in the range
552 * between 0 and 23, which is zero-based.
554 * NOTE: Do not use this method -- use roll(EDateFields, int, UErrorCode&) instead.
556 * @param field The time field.
557 * @param up Indicates if the value of the specified time field is to be rolled
558 * up or rolled down. Use true if rolling up, false otherwise.
559 * @param status Output param set to success/failure code on exit. If any value
560 * previously set in the time field is invalid or restricted by
561 * leniency, this will be set to an error status.
562 * @deprecated ICU 2.6. Use roll(UCalendarDateFields field, UBool up, UErrorCode& status) instead.
564 inline void roll(EDateFields field
, UBool up
, UErrorCode
& status
);
565 #endif /* U_HIDE_DEPRECATED_API */
568 * Time Field Rolling function. Rolls (up/down) a single unit of time on the given
569 * time field. For example, to roll the current date up by one day, call
570 * roll(Calendar::DATE, true). When rolling on the year or Calendar::YEAR field, it
571 * will roll the year value in the range between getMinimum(Calendar::YEAR) and the
572 * value returned by getMaximum(Calendar::YEAR). When rolling on the month or
573 * Calendar::MONTH field, other fields like date might conflict and, need to be
574 * changed. For instance, rolling the month up on the date 01/31/96 will result in
575 * 02/29/96. Rolling up always means rolling forward in time; e.g., rolling the year
576 * up on "100 BC" will result in "99 BC", for Gregorian calendar. When rolling on the
577 * hour-in-day or Calendar::HOUR_OF_DAY field, it will roll the hour value in the range
578 * between 0 and 23, which is zero-based.
580 * NOTE: Do not use this method -- use roll(UCalendarDateFields, int, UErrorCode&) instead.
582 * @param field The time field.
583 * @param up Indicates if the value of the specified time field is to be rolled
584 * up or rolled down. Use true if rolling up, false otherwise.
585 * @param status Output param set to success/failure code on exit. If any value
586 * previously set in the time field is invalid or restricted by
587 * leniency, this will be set to an error status.
590 inline void roll(UCalendarDateFields field
, UBool up
, UErrorCode
& status
);
593 * Time Field Rolling function. Rolls by the given amount on the given
594 * time field. For example, to roll the current date up by one day, call
595 * roll(Calendar::DATE, +1, status). When rolling on the month or
596 * Calendar::MONTH field, other fields like date might conflict and, need to be
597 * changed. For instance, rolling the month up on the date 01/31/96 will result in
598 * 02/29/96. Rolling by a positive value always means rolling forward in time;
599 * e.g., rolling the year by +1 on "100 BC" will result in "99 BC", for Gregorian
600 * calendar. When rolling on the hour-in-day or Calendar::HOUR_OF_DAY field, it will
601 * roll the hour value in the range between 0 and 23, which is zero-based.
603 * The only difference between roll() and add() is that roll() does not change
604 * the value of more significant fields when it reaches the minimum or maximum
605 * of its range, whereas add() does.
607 * @param field The time field.
608 * @param amount Indicates amount to roll.
609 * @param status Output param set to success/failure code on exit. If any value
610 * previously set in the time field is invalid, this will be set to
612 * @deprecated ICU 2.6. Use roll(UCalendarDateFields field, int32_t amount, UErrorCode& status) instead.
614 virtual void roll(EDateFields field
, int32_t amount
, UErrorCode
& status
);
617 * Time Field Rolling function. Rolls by the given amount on the given
618 * time field. For example, to roll the current date up by one day, call
619 * roll(Calendar::DATE, +1, status). When rolling on the month or
620 * Calendar::MONTH field, other fields like date might conflict and, need to be
621 * changed. For instance, rolling the month up on the date 01/31/96 will result in
622 * 02/29/96. Rolling by a positive value always means rolling forward in time;
623 * e.g., rolling the year by +1 on "100 BC" will result in "99 BC", for Gregorian
624 * calendar. When rolling on the hour-in-day or Calendar::HOUR_OF_DAY field, it will
625 * roll the hour value in the range between 0 and 23, which is zero-based.
627 * The only difference between roll() and add() is that roll() does not change
628 * the value of more significant fields when it reaches the minimum or maximum
629 * of its range, whereas add() does.
631 * @param field The time field.
632 * @param amount Indicates amount to roll.
633 * @param status Output param set to success/failure code on exit. If any value
634 * previously set in the time field is invalid, this will be set to
638 virtual void roll(UCalendarDateFields field
, int32_t amount
, UErrorCode
& status
);
641 * Return the difference between the given time and the time this
642 * calendar object is set to. If this calendar is set
643 * <em>before</em> the given time, the returned value will be
644 * positive. If this calendar is set <em>after</em> the given
645 * time, the returned value will be negative. The
646 * <code>field</code> parameter specifies the units of the return
647 * value. For example, if <code>fieldDifference(when,
648 * Calendar::MONTH)</code> returns 3, then this calendar is set to
649 * 3 months before <code>when</code>, and possibly some addition
650 * time less than one month.
652 * <p>As a side effect of this call, this calendar is advanced
653 * toward <code>when</code> by the given amount. That is, calling
654 * this method has the side effect of calling <code>add(field,
655 * n)</code>, where <code>n</code> is the return value.
657 * <p>Usage: To use this method, call it first with the largest
658 * field of interest, then with progressively smaller fields. For
662 * int y = cal->fieldDifference(when, Calendar::YEAR, err);
663 * int m = cal->fieldDifference(when, Calendar::MONTH, err);
664 * int d = cal->fieldDifference(when, Calendar::DATE, err);</pre>
666 * computes the difference between <code>cal</code> and
667 * <code>when</code> in years, months, and days.
669 * <p>Note: <code>fieldDifference()</code> is
670 * <em>asymmetrical</em>. That is, in the following code:
673 * cal->setTime(date1, err);
674 * int m1 = cal->fieldDifference(date2, Calendar::MONTH, err);
675 * int d1 = cal->fieldDifference(date2, Calendar::DATE, err);
676 * cal->setTime(date2, err);
677 * int m2 = cal->fieldDifference(date1, Calendar::MONTH, err);
678 * int d2 = cal->fieldDifference(date1, Calendar::DATE, err);</pre>
680 * one might expect that <code>m1 == -m2 && d1 == -d2</code>.
681 * However, this is not generally the case, because of
682 * irregularities in the underlying calendar system (e.g., the
683 * Gregorian calendar has a varying number of days per month).
685 * @param when the date to compare this calendar's time to
686 * @param field the field in which to compute the result
687 * @param status Output param set to success/failure code on exit. If any value
688 * previously set in the time field is invalid, this will be set to
690 * @return the difference, either positive or negative, between
691 * this calendar's time and <code>when</code>, in terms of
692 * <code>field</code>.
693 * @deprecated ICU 2.6. Use fieldDifference(UDate when, UCalendarDateFields field, UErrorCode& status).
695 virtual int32_t fieldDifference(UDate when
, EDateFields field
, UErrorCode
& status
);
698 * Return the difference between the given time and the time this
699 * calendar object is set to. If this calendar is set
700 * <em>before</em> the given time, the returned value will be
701 * positive. If this calendar is set <em>after</em> the given
702 * time, the returned value will be negative. The
703 * <code>field</code> parameter specifies the units of the return
704 * value. For example, if <code>fieldDifference(when,
705 * Calendar::MONTH)</code> returns 3, then this calendar is set to
706 * 3 months before <code>when</code>, and possibly some addition
707 * time less than one month.
709 * <p>As a side effect of this call, this calendar is advanced
710 * toward <code>when</code> by the given amount. That is, calling
711 * this method has the side effect of calling <code>add(field,
712 * n)</code>, where <code>n</code> is the return value.
714 * <p>Usage: To use this method, call it first with the largest
715 * field of interest, then with progressively smaller fields. For
719 * int y = cal->fieldDifference(when, Calendar::YEAR, err);
720 * int m = cal->fieldDifference(when, Calendar::MONTH, err);
721 * int d = cal->fieldDifference(when, Calendar::DATE, err);</pre>
723 * computes the difference between <code>cal</code> and
724 * <code>when</code> in years, months, and days.
726 * <p>Note: <code>fieldDifference()</code> is
727 * <em>asymmetrical</em>. That is, in the following code:
730 * cal->setTime(date1, err);
731 * int m1 = cal->fieldDifference(date2, Calendar::MONTH, err);
732 * int d1 = cal->fieldDifference(date2, Calendar::DATE, err);
733 * cal->setTime(date2, err);
734 * int m2 = cal->fieldDifference(date1, Calendar::MONTH, err);
735 * int d2 = cal->fieldDifference(date1, Calendar::DATE, err);</pre>
737 * one might expect that <code>m1 == -m2 && d1 == -d2</code>.
738 * However, this is not generally the case, because of
739 * irregularities in the underlying calendar system (e.g., the
740 * Gregorian calendar has a varying number of days per month).
742 * @param when the date to compare this calendar's time to
743 * @param field the field in which to compute the result
744 * @param status Output param set to success/failure code on exit. If any value
745 * previously set in the time field is invalid, this will be set to
747 * @return the difference, either positive or negative, between
748 * this calendar's time and <code>when</code>, in terms of
749 * <code>field</code>.
752 virtual int32_t fieldDifference(UDate when
, UCalendarDateFields field
, UErrorCode
& status
);
755 * Sets the calendar's time zone to be the one passed in. The Calendar takes ownership
756 * of the TimeZone; the caller is no longer responsible for deleting it. If the
757 * given time zone is NULL, this function has no effect.
759 * @param value The given time zone.
762 void adoptTimeZone(TimeZone
* value
);
765 * Sets the calendar's time zone to be the same as the one passed in. The TimeZone
766 * passed in is _not_ adopted; the client is still responsible for deleting it.
768 * @param zone The given time zone.
771 void setTimeZone(const TimeZone
& zone
);
774 * Returns a reference to the time zone owned by this calendar. The returned reference
775 * is only valid until clients make another call to adoptTimeZone or setTimeZone,
776 * or this Calendar is destroyed.
778 * @return The time zone object associated with this calendar.
781 const TimeZone
& getTimeZone(void) const;
784 * Returns the time zone owned by this calendar. The caller owns the returned object
785 * and must delete it when done. After this call, the new time zone associated
786 * with this Calendar is the default TimeZone as returned by TimeZone::createDefault().
788 * @return The time zone object which was associated with this calendar.
791 TimeZone
* orphanTimeZone(void);
794 * Queries if the current date for this Calendar is in Daylight Savings Time.
796 * @param status Fill-in parameter which receives the status of this operation.
797 * @return True if the current date for this Calendar is in Daylight Savings Time,
801 virtual UBool
inDaylightTime(UErrorCode
& status
) const = 0;
804 * Specifies whether or not date/time interpretation is to be lenient. With lenient
805 * interpretation, a date such as "February 942, 1996" will be treated as being
806 * equivalent to the 941st day after February 1, 1996. With strict interpretation,
807 * such dates will cause an error when computing time from the time field values
808 * representing the dates.
810 * @param lenient True specifies date/time interpretation to be lenient.
812 * @see DateFormat#setLenient
815 void setLenient(UBool lenient
);
818 * Tells whether date/time interpretation is to be lenient.
820 * @return True tells that date/time interpretation is to be lenient.
823 UBool
isLenient(void) const;
825 #ifndef U_HIDE_DRAFT_API
827 * Sets the behavior for handling wall time repeating multiple times
828 * at negative time zone offset transitions. For example, 1:30 AM on
829 * November 6, 2011 in US Eastern time (Ameirca/New_York) occurs twice;
830 * 1:30 AM EDT, then 1:30 AM EST one hour later. When <code>UCAL_WALLTIME_FIRST</code>
831 * is used, the wall time 1:30AM in this example will be interpreted as 1:30 AM EDT
832 * (first occurrence). When <code>UCAL_WALLTIME_LAST</code> is used, it will be
833 * interpreted as 1:30 AM EST (last occurrence). The default value is
834 * <code>UCAL_WALLTIME_LAST</code>.
836 * <b>Note:</b>When <code>UCAL_WALLTIME_NEXT_VALID</code> is not a valid
837 * option for this. When the argument is neither <code>UCAL_WALLTIME_FIRST</code>
838 * nor <code>UCAL_WALLTIME_LAST</code>, this method has no effect and will keep
839 * the current setting.
841 * @param option the behavior for handling repeating wall time, either
842 * <code>UCAL_WALLTIME_FIRST</code> or <code>UCAL_WALLTIME_LAST</code>.
843 * @see #getRepeatedWallTimeOption
846 void setRepeatedWallTimeOption(UCalendarWallTimeOption option
);
849 * Gets the behavior for handling wall time repeating multiple times
850 * at negative time zone offset transitions.
852 * @return the behavior for handling repeating wall time, either
853 * <code>UCAL_WALLTIME_FIRST</code> or <code>UCAL_WALLTIME_LAST</code>.
854 * @see #setRepeatedWallTimeOption
857 UCalendarWallTimeOption
getRepeatedWallTimeOption(void) const;
860 * Sets the behavior for handling skipped wall time at positive time zone offset
861 * transitions. For example, 2:30 AM on March 13, 2011 in US Eastern time (America/New_York)
862 * does not exist because the wall time jump from 1:59 AM EST to 3:00 AM EDT. When
863 * <code>UCAL_WALLTIME_FIRST</code> is used, 2:30 AM is interpreted as 30 minutes before 3:00 AM
864 * EDT, therefore, it will be resolved as 1:30 AM EST. When <code>UCAL_WALLTIME_LAST</code>
865 * is used, 2:30 AM is interpreted as 31 minutes after 1:59 AM EST, therefore, it will be
866 * resolved as 3:30 AM EDT. When <code>UCAL_WALLTIME_NEXT_VALID</code> is used, 2:30 AM will
867 * be resolved as next valid wall time, that is 3:00 AM EDT. The default value is
868 * <code>UCAL_WALLTIME_LAST</code>.
870 * <b>Note:</b>This option is effective only when this calendar is lenient.
871 * When the calendar is strict, such non-existing wall time will cause an error.
873 * @param option the behavior for handling skipped wall time at positive time zone
874 * offset transitions, one of <code>UCAL_WALLTIME_FIRST</code>, <code>UCAL_WALLTIME_LAST</code> and
875 * <code>UCAL_WALLTIME_NEXT_VALID</code>.
876 * @see #getSkippedWallTimeOption
880 void setSkippedWallTimeOption(UCalendarWallTimeOption option
);
883 * Gets the behavior for handling skipped wall time at positive time zone offset
886 * @return the behavior for handling skipped wall time, one of
887 * <code>UCAL_WALLTIME_FIRST</code>, <code>UCAL_WALLTIME_LAST</code>
888 * and <code>UCAL_WALLTIME_NEXT_VALID</code>.
889 * @see #setSkippedWallTimeOption
892 UCalendarWallTimeOption
getSkippedWallTimeOption(void) const;
893 #endif /* U_HIDE_DRAFT_API */
895 #ifndef U_HIDE_DEPRECATED_API
897 * Sets what the first day of the week is; e.g., Sunday in US, Monday in France.
899 * @param value The given first day of the week.
900 * @deprecated ICU 2.6. Use setFirstDayOfWeek(UCalendarDaysOfWeek value) instead.
902 void setFirstDayOfWeek(EDaysOfWeek value
);
903 #endif /* U_HIDE_DEPRECATED_API */
906 * Sets what the first day of the week is; e.g., Sunday in US, Monday in France.
908 * @param value The given first day of the week.
911 void setFirstDayOfWeek(UCalendarDaysOfWeek value
);
913 #ifndef U_HIDE_DEPRECATED_API
915 * Gets what the first day of the week is; e.g., Sunday in US, Monday in France.
917 * @return The first day of the week.
918 * @deprecated ICU 2.6 use the overload with error code
920 EDaysOfWeek
getFirstDayOfWeek(void) const;
921 #endif /* U_HIDE_DEPRECATED_API */
924 * Gets what the first day of the week is; e.g., Sunday in US, Monday in France.
926 * @param status error code
927 * @return The first day of the week.
930 UCalendarDaysOfWeek
getFirstDayOfWeek(UErrorCode
&status
) const;
933 * Sets what the minimal days required in the first week of the year are; For
934 * example, if the first week is defined as one that contains the first day of the
935 * first month of a year, call the method with value 1. If it must be a full week,
938 * @param value The given minimal days required in the first week of the year.
941 void setMinimalDaysInFirstWeek(uint8_t value
);
944 * Gets what the minimal days required in the first week of the year are; e.g., if
945 * the first week is defined as one that contains the first day of the first month
946 * of a year, getMinimalDaysInFirstWeek returns 1. If the minimal days required must
947 * be a full week, getMinimalDaysInFirstWeek returns 7.
949 * @return The minimal days required in the first week of the year.
952 uint8_t getMinimalDaysInFirstWeek(void) const;
955 * Gets the minimum value for the given time field. e.g., for Gregorian
958 * @param field The given time field.
959 * @return The minimum value for the given time field.
960 * @deprecated ICU 2.6. Use getMinimum(UCalendarDateFields field) instead.
962 virtual int32_t getMinimum(EDateFields field
) const;
965 * Gets the minimum value for the given time field. e.g., for Gregorian
968 * @param field The given time field.
969 * @return The minimum value for the given time field.
972 virtual int32_t getMinimum(UCalendarDateFields field
) const;
975 * Gets the maximum value for the given time field. e.g. for Gregorian DAY_OF_MONTH,
978 * @param field The given time field.
979 * @return The maximum value for the given time field.
980 * @deprecated ICU 2.6. Use getMaximum(UCalendarDateFields field) instead.
982 virtual int32_t getMaximum(EDateFields field
) const;
985 * Gets the maximum value for the given time field. e.g. for Gregorian DAY_OF_MONTH,
988 * @param field The given time field.
989 * @return The maximum value for the given time field.
992 virtual int32_t getMaximum(UCalendarDateFields field
) const;
995 * Gets the highest minimum value for the given field if varies. Otherwise same as
996 * getMinimum(). For Gregorian, no difference.
998 * @param field The given time field.
999 * @return The highest minimum value for the given time field.
1000 * @deprecated ICU 2.6. Use getGreatestMinimum(UCalendarDateFields field) instead.
1002 virtual int32_t getGreatestMinimum(EDateFields field
) const;
1005 * Gets the highest minimum value for the given field if varies. Otherwise same as
1006 * getMinimum(). For Gregorian, no difference.
1008 * @param field The given time field.
1009 * @return The highest minimum value for the given time field.
1012 virtual int32_t getGreatestMinimum(UCalendarDateFields field
) const;
1015 * Gets the lowest maximum value for the given field if varies. Otherwise same as
1016 * getMaximum(). e.g., for Gregorian DAY_OF_MONTH, 28.
1018 * @param field The given time field.
1019 * @return The lowest maximum value for the given time field.
1020 * @deprecated ICU 2.6. Use getLeastMaximum(UCalendarDateFields field) instead.
1022 virtual int32_t getLeastMaximum(EDateFields field
) const;
1025 * Gets the lowest maximum value for the given field if varies. Otherwise same as
1026 * getMaximum(). e.g., for Gregorian DAY_OF_MONTH, 28.
1028 * @param field The given time field.
1029 * @return The lowest maximum value for the given time field.
1032 virtual int32_t getLeastMaximum(UCalendarDateFields field
) const;
1034 #ifndef U_HIDE_DEPRECATED_API
1036 * Return the minimum value that this field could have, given the current date.
1037 * For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum().
1039 * The version of this function on Calendar uses an iterative algorithm to determine the
1040 * actual minimum value for the field. There is almost always a more efficient way to
1041 * accomplish this (in most cases, you can simply return getMinimum()). GregorianCalendar
1042 * overrides this function with a more efficient implementation.
1044 * @param field the field to determine the minimum of
1045 * @param status Fill-in parameter which receives the status of this operation.
1046 * @return the minimum of the given field for the current date of this Calendar
1047 * @deprecated ICU 2.6. Use getActualMinimum(UCalendarDateFields field, UErrorCode& status) instead.
1049 int32_t getActualMinimum(EDateFields field
, UErrorCode
& status
) const;
1050 #endif /* U_HIDE_DEPRECATED_API */
1053 * Return the minimum value that this field could have, given the current date.
1054 * For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum().
1056 * The version of this function on Calendar uses an iterative algorithm to determine the
1057 * actual minimum value for the field. There is almost always a more efficient way to
1058 * accomplish this (in most cases, you can simply return getMinimum()). GregorianCalendar
1059 * overrides this function with a more efficient implementation.
1061 * @param field the field to determine the minimum of
1062 * @param status Fill-in parameter which receives the status of this operation.
1063 * @return the minimum of the given field for the current date of this Calendar
1066 virtual int32_t getActualMinimum(UCalendarDateFields field
, UErrorCode
& status
) const;
1068 #ifndef U_HIDE_DEPRECATED_API
1070 * Return the maximum value that this field could have, given the current date.
1071 * For example, with the date "Feb 3, 1997" and the DAY_OF_MONTH field, the actual
1072 * maximum would be 28; for "Feb 3, 1996" it s 29. Similarly for a Hebrew calendar,
1073 * for some years the actual maximum for MONTH is 12, and for others 13.
1075 * The version of this function on Calendar uses an iterative algorithm to determine the
1076 * actual maximum value for the field. There is almost always a more efficient way to
1077 * accomplish this (in most cases, you can simply return getMaximum()). GregorianCalendar
1078 * overrides this function with a more efficient implementation.
1080 * @param field the field to determine the maximum of
1081 * @param status Fill-in parameter which receives the status of this operation.
1082 * @return the maximum of the given field for the current date of this Calendar
1083 * @deprecated ICU 2.6. Use getActualMaximum(UCalendarDateFields field, UErrorCode& status) instead.
1085 int32_t getActualMaximum(EDateFields field
, UErrorCode
& status
) const;
1086 #endif /* U_HIDE_DEPRECATED_API */
1089 * Return the maximum value that this field could have, given the current date.
1090 * For example, with the date "Feb 3, 1997" and the DAY_OF_MONTH field, the actual
1091 * maximum would be 28; for "Feb 3, 1996" it s 29. Similarly for a Hebrew calendar,
1092 * for some years the actual maximum for MONTH is 12, and for others 13.
1094 * The version of this function on Calendar uses an iterative algorithm to determine the
1095 * actual maximum value for the field. There is almost always a more efficient way to
1096 * accomplish this (in most cases, you can simply return getMaximum()). GregorianCalendar
1097 * overrides this function with a more efficient implementation.
1099 * @param field the field to determine the maximum of
1100 * @param status Fill-in parameter which receives the status of this operation.
1101 * @return the maximum of the given field for the current date of this Calendar
1104 virtual int32_t getActualMaximum(UCalendarDateFields field
, UErrorCode
& status
) const;
1106 #ifndef U_HIDE_DEPRECATED_API
1108 * Gets the value for a given time field. Recalculate the current time field values
1109 * if the time value has been changed by a call to setTime(). Return zero for unset
1110 * fields if any fields have been explicitly set by a call to set(). To force a
1111 * recomputation of all fields regardless of the previous state, call complete().
1112 * This method is semantically const, but may alter the object in memory.
1114 * @param field The given time field.
1115 * @param status Fill-in parameter which receives the status of the operation.
1116 * @return The value for the given time field, or zero if the field is unset,
1117 * and set() has been called for any other field.
1118 * @deprecated ICU 2.6. Use get(UCalendarDateFields field, UErrorCode& status) instead.
1120 int32_t get(EDateFields field
, UErrorCode
& status
) const;
1121 #endif /* U_HIDE_DEPRECATED_API */
1124 * Gets the value for a given time field. Recalculate the current time field values
1125 * if the time value has been changed by a call to setTime(). Return zero for unset
1126 * fields if any fields have been explicitly set by a call to set(). To force a
1127 * recomputation of all fields regardless of the previous state, call complete().
1128 * This method is semantically const, but may alter the object in memory.
1130 * @param field The given time field.
1131 * @param status Fill-in parameter which receives the status of the operation.
1132 * @return The value for the given time field, or zero if the field is unset,
1133 * and set() has been called for any other field.
1136 int32_t get(UCalendarDateFields field
, UErrorCode
& status
) const;
1138 #ifndef U_HIDE_DEPRECATED_API
1140 * Determines if the given time field has a value set. This can affect in the
1141 * resolving of time in Calendar. Unset fields have a value of zero, by definition.
1143 * @param field The given time field.
1144 * @return True if the given time field has a value set; false otherwise.
1145 * @deprecated ICU 2.6. Use isSet(UCalendarDateFields field) instead.
1147 UBool
isSet(EDateFields field
) const;
1148 #endif /* U_HIDE_DEPRECATED_API */
1151 * Determines if the given time field has a value set. This can affect in the
1152 * resolving of time in Calendar. Unset fields have a value of zero, by definition.
1154 * @param field The given time field.
1155 * @return True if the given time field has a value set; false otherwise.
1158 UBool
isSet(UCalendarDateFields field
) const;
1160 #ifndef U_HIDE_DEPRECATED_API
1162 * Sets the given time field with the given value.
1164 * @param field The given time field.
1165 * @param value The value to be set for the given time field.
1166 * @deprecated ICU 2.6. Use set(UCalendarDateFields field, int32_t value) instead.
1168 void set(EDateFields field
, int32_t value
);
1169 #endif /* U_HIDE_DEPRECATED_API */
1172 * Sets the given time field with the given value.
1174 * @param field The given time field.
1175 * @param value The value to be set for the given time field.
1178 void set(UCalendarDateFields field
, int32_t value
);
1181 * Sets the values for the fields YEAR, MONTH, and DATE. Other field values are
1182 * retained; call clear() first if this is not desired.
1184 * @param year The value used to set the YEAR time field.
1185 * @param month The value used to set the MONTH time field. Month value is 0-based.
1186 * e.g., 0 for January.
1187 * @param date The value used to set the DATE time field.
1190 void set(int32_t year
, int32_t month
, int32_t date
);
1193 * Sets the values for the fields YEAR, MONTH, DATE, HOUR_OF_DAY, and MINUTE. Other
1194 * field values are retained; call clear() first if this is not desired.
1196 * @param year The value used to set the YEAR time field.
1197 * @param month The value used to set the MONTH time field. Month value is
1198 * 0-based. E.g., 0 for January.
1199 * @param date The value used to set the DATE time field.
1200 * @param hour The value used to set the HOUR_OF_DAY time field.
1201 * @param minute The value used to set the MINUTE time field.
1204 void set(int32_t year
, int32_t month
, int32_t date
, int32_t hour
, int32_t minute
);
1207 * Sets the values for the fields YEAR, MONTH, DATE, HOUR_OF_DAY, MINUTE, and SECOND.
1208 * Other field values are retained; call clear() first if this is not desired.
1210 * @param year The value used to set the YEAR time field.
1211 * @param month The value used to set the MONTH time field. Month value is
1212 * 0-based. E.g., 0 for January.
1213 * @param date The value used to set the DATE time field.
1214 * @param hour The value used to set the HOUR_OF_DAY time field.
1215 * @param minute The value used to set the MINUTE time field.
1216 * @param second The value used to set the SECOND time field.
1219 void set(int32_t year
, int32_t month
, int32_t date
, int32_t hour
, int32_t minute
, int32_t second
);
1222 * Clears the values of all the time fields, making them both unset and assigning
1223 * them a value of zero. The field values will be determined during the next
1224 * resolving of time into time fields.
1229 #ifndef U_HIDE_DEPRECATED_API
1231 * Clears the value in the given time field, both making it unset and assigning it a
1232 * value of zero. This field value will be determined during the next resolving of
1233 * time into time fields.
1235 * @param field The time field to be cleared.
1236 * @deprecated ICU 2.6. Use clear(UCalendarDateFields field) instead.
1238 void clear(EDateFields field
);
1239 #endif /* U_HIDE_DEPRECATED_API */
1242 * Clears the value in the given time field, both making it unset and assigning it a
1243 * value of zero. This field value will be determined during the next resolving of
1244 * time into time fields.
1246 * @param field The time field to be cleared.
1249 void clear(UCalendarDateFields field
);
1252 * Returns a unique class ID POLYMORPHICALLY. Pure virtual method. This method is to
1253 * implement a simple version of RTTI, since not all C++ compilers support genuine
1254 * RTTI. Polymorphic operator==() and clone() methods call this method.
1256 * Concrete subclasses of Calendar must implement getDynamicClassID() and also a
1257 * static method and data member:
1259 * static UClassID getStaticClassID() { return (UClassID)&fgClassID; }
1260 * static char fgClassID;
1262 * @return The class ID for this object. All objects of a given class have the
1263 * same class ID. Objects of other classes have different class IDs.
1266 virtual UClassID
getDynamicClassID(void) const = 0;
1269 * Returns the calendar type name string for this Calendar object.
1270 * The returned string is the legacy ICU calendar attribute value,
1271 * for example, "gregorian" or "japanese".
1273 * See type="old type name" for the calendar attribute of locale IDs
1274 * at http://www.unicode.org/reports/tr35/#Key_Type_Definitions
1276 * Sample code for getting the LDML/BCP 47 calendar key value:
1278 * const char *calType = cal->getType();
1279 * if (0 == strcmp(calType, "unknown")) {
1280 * // deal with unknown calendar type
1282 * string localeID("root@calendar=");
1283 * localeID.append(calType);
1284 * char langTag[100];
1285 * UErrorCode errorCode = U_ZERO_ERROR;
1286 * int32_t length = uloc_toLanguageTag(localeID.c_str(), langTag, (int32_t)sizeof(langTag), TRUE, &errorCode);
1287 * if (U_FAILURE(errorCode)) {
1288 * // deal with errors & overflow
1290 * string lang(langTag, length);
1291 * size_t caPos = lang.find("-ca-");
1292 * lang.erase(0, caPos + 4);
1293 * // lang now contains the LDML calendar type
1297 * @return legacy calendar type name string
1300 virtual const char * getType() const = 0;
1303 * Returns whether the given day of the week is a weekday, a
1304 * weekend day, or a day that transitions from one to the other,
1305 * in this calendar system. If a transition occurs at midnight,
1306 * then the days before and after the transition will have the
1307 * type UCAL_WEEKDAY or UCAL_WEEKEND. If a transition occurs at a time
1308 * other than midnight, then the day of the transition will have
1309 * the type UCAL_WEEKEND_ONSET or UCAL_WEEKEND_CEASE. In this case, the
1310 * method getWeekendTransition() will return the point of
1312 * @param dayOfWeek The day of the week whose type is desired (UCAL_SUNDAY..UCAL_SATURDAY).
1313 * @param status The error code for the operation.
1314 * @return The UCalendarWeekdayType for the day of the week.
1317 virtual UCalendarWeekdayType
getDayOfWeekType(UCalendarDaysOfWeek dayOfWeek
, UErrorCode
&status
) const;
1320 * Returns the time during the day at which the weekend begins or ends in
1321 * this calendar system. If getDayOfWeekType() rerturns UCAL_WEEKEND_ONSET
1322 * for the specified dayOfWeek, return the time at which the weekend begins.
1323 * If getDayOfWeekType() returns UCAL_WEEKEND_CEASE for the specified dayOfWeek,
1324 * return the time at which the weekend ends. If getDayOfWeekType() returns
1325 * some other UCalendarWeekdayType for the specified dayOfWeek, is it an error condition
1326 * (U_ILLEGAL_ARGUMENT_ERROR).
1327 * @param dayOfWeek The day of the week for which the weekend transition time is
1328 * desired (UCAL_SUNDAY..UCAL_SATURDAY).
1329 * @param status The error code for the operation.
1330 * @return The milliseconds after midnight at which the weekend begins or ends.
1333 virtual int32_t getWeekendTransition(UCalendarDaysOfWeek dayOfWeek
, UErrorCode
&status
) const;
1336 * Returns TRUE if the given UDate is in the weekend in
1337 * this calendar system.
1338 * @param date The UDate in question.
1339 * @param status The error code for the operation.
1340 * @return TRUE if the given UDate is in the weekend in
1341 * this calendar system, FALSE otherwise.
1344 virtual UBool
isWeekend(UDate date
, UErrorCode
&status
) const;
1347 * Returns TRUE if this Calendar's current date-time is in the weekend in
1348 * this calendar system.
1349 * @return TRUE if this Calendar's current date-time is in the weekend in
1350 * this calendar system, FALSE otherwise.
1353 virtual UBool
isWeekend(void) const;
1358 * Constructs a Calendar with the default time zone as returned by
1359 * TimeZone::createInstance(), and the default locale.
1361 * @param success Indicates the status of Calendar object construction. Returns
1362 * U_ZERO_ERROR if constructed successfully.
1365 Calendar(UErrorCode
& success
);
1370 * @param source Calendar object to be copied from
1373 Calendar(const Calendar
& source
);
1376 * Default assignment operator
1378 * @param right Calendar object to be copied
1381 Calendar
& operator=(const Calendar
& right
);
1384 * Constructs a Calendar with the given time zone and locale. Clients are no longer
1385 * responsible for deleting the given time zone object after it's adopted.
1387 * @param zone The given time zone.
1388 * @param aLocale The given locale.
1389 * @param success Indicates the status of Calendar object construction. Returns
1390 * U_ZERO_ERROR if constructed successfully.
1393 Calendar(TimeZone
* zone
, const Locale
& aLocale
, UErrorCode
& success
);
1396 * Constructs a Calendar with the given time zone and locale.
1398 * @param zone The given time zone.
1399 * @param aLocale The given locale.
1400 * @param success Indicates the status of Calendar object construction. Returns
1401 * U_ZERO_ERROR if constructed successfully.
1404 Calendar(const TimeZone
& zone
, const Locale
& aLocale
, UErrorCode
& success
);
1407 * Converts Calendar's time field values to GMT as milliseconds.
1409 * @param status Output param set to success/failure code on exit. If any value
1410 * previously set in the time field is invalid or restricted by
1411 * leniency, this will be set to an error status.
1414 virtual void computeTime(UErrorCode
& status
);
1417 * Converts GMT as milliseconds to time field values. This allows you to sync up the
1418 * time field values with a new time that is set for the calendar. This method
1419 * does NOT recompute the time first; to recompute the time, then the fields, use
1420 * the method complete().
1422 * @param status Output param set to success/failure code on exit. If any value
1423 * previously set in the time field is invalid or restricted by
1424 * leniency, this will be set to an error status.
1427 virtual void computeFields(UErrorCode
& status
);
1430 * Gets this Calendar's current time as a long.
1432 * @param status Output param set to success/failure code on exit. If any value
1433 * previously set in the time field is invalid or restricted by
1434 * leniency, this will be set to an error status.
1435 * @return the current time as UTC milliseconds from the epoch.
1438 double getTimeInMillis(UErrorCode
& status
) const;
1441 * Sets this Calendar's current time from the given long value.
1442 * @param millis the new time in UTC milliseconds from the epoch.
1443 * @param status Output param set to success/failure code on exit. If any value
1444 * previously set in the time field is invalid or restricted by
1445 * leniency, this will be set to an error status.
1448 void setTimeInMillis( double millis
, UErrorCode
& status
);
1451 * Recomputes the current time from currently set fields, and then fills in any
1452 * unset fields in the time field list.
1454 * @param status Output param set to success/failure code on exit. If any value
1455 * previously set in the time field is invalid or restricted by
1456 * leniency, this will be set to an error status.
1459 void complete(UErrorCode
& status
);
1461 #ifndef U_HIDE_DEPRECATED_API
1463 * Gets the value for a given time field. Subclasses can use this function to get
1464 * field values without forcing recomputation of time.
1466 * @param field The given time field.
1467 * @return The value for the given time field.
1468 * @deprecated ICU 2.6. Use internalGet(UCalendarDateFields field) instead.
1470 inline int32_t internalGet(EDateFields field
) const {return fFields
[field
];}
1471 #endif /* U_HIDE_DEPRECATED_API */
1473 #ifndef U_HIDE_INTERNAL_API
1475 * Gets the value for a given time field. Subclasses can use this function to get
1476 * field values without forcing recomputation of time. If the field's stamp is UNSET,
1477 * the defaultValue is used.
1479 * @param field The given time field.
1480 * @param defaultValue a default value used if the field is unset.
1481 * @return The value for the given time field.
1484 inline int32_t internalGet(UCalendarDateFields field
, int32_t defaultValue
) const {return fStamp
[field
]>kUnset
? fFields
[field
] : defaultValue
;}
1487 * Gets the value for a given time field. Subclasses can use this function to get
1488 * field values without forcing recomputation of time.
1490 * @param field The given time field.
1491 * @return The value for the given time field.
1494 inline int32_t internalGet(UCalendarDateFields field
) const {return fFields
[field
];}
1495 #endif /* U_HIDE_INTERNAL_API */
1497 #ifndef U_HIDE_DEPRECATED_API
1499 * Sets the value for a given time field. This is a fast internal method for
1500 * subclasses. It does not affect the areFieldsInSync, isTimeSet, or areAllFieldsSet
1503 * @param field The given time field.
1504 * @param value The value for the given time field.
1505 * @deprecated ICU 2.6. Use internalSet(UCalendarDateFields field, int32_t value) instead.
1507 void internalSet(EDateFields field
, int32_t value
);
1508 #endif /* U_HIDE_DEPRECATED_API */
1511 * Sets the value for a given time field. This is a fast internal method for
1512 * subclasses. It does not affect the areFieldsInSync, isTimeSet, or areAllFieldsSet
1515 * @param field The given time field.
1516 * @param value The value for the given time field.
1519 inline void internalSet(UCalendarDateFields field
, int32_t value
);
1522 * Prepare this calendar for computing the actual minimum or maximum.
1523 * This method modifies this calendar's fields; it is called on a
1524 * temporary calendar.
1527 virtual void prepareGetActual(UCalendarDateFields field
, UBool isMinimum
, UErrorCode
&status
);
1530 * Limit enums. Not in sync with UCalendarLimitType (refers to internal fields).
1534 UCAL_LIMIT_MINIMUM
= 0,
1535 UCAL_LIMIT_GREATEST_MINIMUM
,
1536 UCAL_LIMIT_LEAST_MAXIMUM
,
1542 * Subclass API for defining limits of different types.
1543 * Subclasses must implement this method to return limits for the
1550 * UCAL_WEEK_OF_MONTH
1551 * UCAL_DATE (DAY_OF_MONTH on Java)
1553 * UCAL_DAY_OF_WEEK_IN_MONTH
1555 * UCAL_EXTENDED_YEAR</pre>
1557 * @param field one of the above field numbers
1558 * @param limitType one of <code>MINIMUM</code>, <code>GREATEST_MINIMUM</code>,
1559 * <code>LEAST_MAXIMUM</code>, or <code>MAXIMUM</code>
1562 virtual int32_t handleGetLimit(UCalendarDateFields field
, ELimitType limitType
) const = 0;
1565 * Return a limit for a field.
1566 * @param field the field, from <code>0..UCAL_MAX_FIELD</code>
1567 * @param limitType the type specifier for the limit
1571 virtual int32_t getLimit(UCalendarDateFields field
, ELimitType limitType
) const;
1575 * Return the Julian day number of day before the first day of the
1576 * given month in the given extended year. Subclasses should override
1577 * this method to implement their calendar system.
1578 * @param eyear the extended year
1579 * @param month the zero-based month, or 0 if useMonth is false
1580 * @param useMonth if false, compute the day before the first day of
1581 * the given year, otherwise, compute the day before the first day of
1583 * @return the Julian day number of the day before the first
1584 * day of the given month and year
1587 virtual int32_t handleComputeMonthStart(int32_t eyear
, int32_t month
,
1588 UBool useMonth
) const = 0;
1591 * Return the number of days in the given month of the given extended
1592 * year of this calendar system. Subclasses should override this
1593 * method if they can provide a more correct or more efficient
1594 * implementation than the default implementation in Calendar.
1597 virtual int32_t handleGetMonthLength(int32_t extendedYear
, int32_t month
) const ;
1600 * Return the number of days in the given extended year of this
1601 * calendar system. Subclasses should override this method if they can
1602 * provide a more correct or more efficient implementation than the
1603 * default implementation in Calendar.
1606 virtual int32_t handleGetYearLength(int32_t eyear
) const;
1610 * Return the extended year defined by the current fields. This will
1611 * use the UCAL_EXTENDED_YEAR field or the UCAL_YEAR and supra-year fields (such
1612 * as UCAL_ERA) specific to the calendar system, depending on which set of
1614 * @return the extended year
1617 virtual int32_t handleGetExtendedYear() = 0;
1620 * Subclasses may override this. This method calls
1621 * handleGetMonthLength() to obtain the calendar-specific month
1623 * @param bestField which field to use to calculate the date
1624 * @return julian day specified by calendar fields.
1627 virtual int32_t handleComputeJulianDay(UCalendarDateFields bestField
);
1630 * Subclasses must override this to convert from week fields
1631 * (YEAR_WOY and WEEK_OF_YEAR) to an extended year in the case
1632 * where YEAR, EXTENDED_YEAR are not set.
1633 * The Calendar implementation assumes yearWoy is in extended gregorian form
1635 * @return the extended year, UCAL_EXTENDED_YEAR
1637 virtual int32_t handleGetExtendedYearFromWeekFields(int32_t yearWoy
, int32_t woy
);
1639 #ifndef U_HIDE_INTERNAL_API
1641 * Compute the Julian day from fields. Will determine whether to use
1642 * the JULIAN_DAY field directly, or other fields.
1643 * @return the julian day
1646 int32_t computeJulianDay();
1649 * Compute the milliseconds in the day from the fields. This is a
1650 * value from 0 to 23:59:59.999 inclusive, unless fields are out of
1651 * range, in which case it can be an arbitrary value. This value
1652 * reflects local zone wall time.
1655 int32_t computeMillisInDay();
1658 * This method can assume EXTENDED_YEAR has been set.
1659 * @param millis milliseconds of the date fields
1660 * @param millisInDay milliseconds of the time fields; may be out
1662 * @param ec Output param set to failure code on function return
1663 * when this function fails.
1666 int32_t computeZoneOffset(double millis
, int32_t millisInDay
, UErrorCode
&ec
);
1670 * Determine the best stamp in a range.
1671 * @param start first enum to look at
1672 * @param end last enum to look at
1673 * @param bestSoFar stamp prior to function call
1674 * @return the stamp value of the best stamp
1677 int32_t newestStamp(UCalendarDateFields start
, UCalendarDateFields end
, int32_t bestSoFar
) const;
1680 * Values for field resolution tables
1681 * @see #resolveFields
1685 /** Marker for end of resolve set (row or group). */
1687 /** 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. */
1692 * Precedence table for Dates
1693 * @see #resolveFields
1696 static const UFieldResolutionTable kDatePrecedence
[];
1699 * Precedence table for Year
1700 * @see #resolveFields
1703 static const UFieldResolutionTable kYearPrecedence
[];
1706 * Precedence table for Day of Week
1707 * @see #resolveFields
1710 static const UFieldResolutionTable kDOWPrecedence
[];
1713 * Given a precedence table, return the newest field combination in
1714 * the table, or UCAL_FIELD_COUNT if none is found.
1716 * <p>The precedence table is a 3-dimensional array of integers. It
1717 * may be thought of as an array of groups. Each group is an array of
1718 * lines. Each line is an array of field numbers. Within a line, if
1719 * all fields are set, then the time stamp of the line is taken to be
1720 * the stamp of the most recently set field. If any field of a line is
1721 * unset, then the line fails to match. Within a group, the line with
1722 * the newest time stamp is selected. The first field of the line is
1723 * returned to indicate which line matched.
1725 * <p>In some cases, it may be desirable to map a line to field that
1726 * whose stamp is NOT examined. For example, if the best field is
1727 * DAY_OF_WEEK then the DAY_OF_WEEK_IN_MONTH algorithm may be used. In
1728 * order to do this, insert the value <code>kResolveRemap | F</code> at
1729 * the start of the line, where <code>F</code> is the desired return
1730 * field value. This field will NOT be examined; it only determines
1731 * the return value if the other fields in the line are the newest.
1733 * <p>If all lines of a group contain at least one unset field, then no
1734 * line will match, and the group as a whole will fail to match. In
1735 * that case, the next group will be processed. If all groups fail to
1736 * match, then UCAL_FIELD_COUNT is returned.
1739 UCalendarDateFields
resolveFields(const UFieldResolutionTable
*precedenceTable
);
1740 #endif /* U_HIDE_INTERNAL_API */
1746 virtual const UFieldResolutionTable
* getFieldResolutionTable() const;
1748 #ifndef U_HIDE_INTERNAL_API
1750 * Return the field that is newer, either defaultField, or
1751 * alternateField. If neither is newer or neither is set, return defaultField.
1754 UCalendarDateFields
newerField(UCalendarDateFields defaultField
, UCalendarDateFields alternateField
) const;
1755 #endif /* U_HIDE_INTERNAL_API */
1760 * Helper function for calculating limits by trial and error
1761 * @param field The field being investigated
1762 * @param startValue starting (least max) value of field
1763 * @param endValue ending (greatest max) value of field
1764 * @param status return type
1767 int32_t getActualHelper(UCalendarDateFields field
, int32_t startValue
, int32_t endValue
, UErrorCode
&status
) const;
1772 * The flag which indicates if the current time is set in the calendar.
1778 * True if the fields are in sync with the currently set time of this Calendar.
1779 * If false, then the next attempt to get the value of a field will
1780 * force a recomputation of all fields from the current value of the time
1783 * This should really be named areFieldsInSync, but the old name is retained
1784 * for backward compatibility.
1787 UBool fAreFieldsSet
;
1790 * True if all of the fields have been set. This is initially false, and set to
1791 * true by computeFields().
1794 UBool fAreAllFieldsSet
;
1797 * True if all fields have been virtually set, but have not yet been
1798 * computed. This occurs only in setTimeInMillis(). A calendar set
1799 * to this state will compute all fields from the time if it becomes
1800 * necessary, but otherwise will delay such computation.
1803 UBool fAreFieldsVirtuallySet
;
1806 * Get the current time without recomputing.
1808 * @return the current time without recomputing.
1811 UDate
internalGetTime(void) const { return fTime
; }
1814 * Set the current time without affecting flags or fields.
1816 * @param time The time to be set
1817 * @return the current time without recomputing.
1820 void internalSetTime(UDate time
) { fTime
= time
; }
1823 * The time fields containing values into which the millis is computed.
1826 int32_t fFields
[UCAL_FIELD_COUNT
];
1829 * The flags which tell if a specified time field for the calendar is set.
1830 * @deprecated ICU 2.8 use (fStamp[n]!=kUnset)
1832 UBool fIsSet
[UCAL_FIELD_COUNT
];
1834 /** Special values of stamp[]
1844 * Pseudo-time-stamps which specify when each field was set. There
1845 * are two special values, UNSET and INTERNALLY_SET. Values from
1846 * MINIMUM_USER_SET to Integer.MAX_VALUE are legal user set values.
1849 int32_t fStamp
[UCAL_FIELD_COUNT
];
1852 * Subclasses may override this method to compute several fields
1853 * specific to each calendar system. These are:
1860 * <li>EXTENDED_YEAR</ul>
1862 * Subclasses can refer to the DAY_OF_WEEK and DOW_LOCAL fields, which
1863 * will be set when this method is called. Subclasses can also call
1864 * the getGregorianXxx() methods to obtain Gregorian calendar
1865 * equivalents for the given Julian day.
1867 * <p>In addition, subclasses should compute any subclass-specific
1868 * fields, that is, fields from BASE_FIELD_COUNT to
1869 * getFieldCount() - 1.
1871 * <p>The default implementation in <code>Calendar</code> implements
1872 * a pure proleptic Gregorian calendar.
1875 virtual void handleComputeFields(int32_t julianDay
, UErrorCode
&status
);
1877 #ifndef U_HIDE_INTERNAL_API
1879 * Return the extended year on the Gregorian calendar as computed by
1880 * <code>computeGregorianFields()</code>.
1883 int32_t getGregorianYear() const {
1884 return fGregorianYear
;
1888 * Return the month (0-based) on the Gregorian calendar as computed by
1889 * <code>computeGregorianFields()</code>.
1892 int32_t getGregorianMonth() const {
1893 return fGregorianMonth
;
1897 * Return the day of year (1-based) on the Gregorian calendar as
1898 * computed by <code>computeGregorianFields()</code>.
1901 int32_t getGregorianDayOfYear() const {
1902 return fGregorianDayOfYear
;
1906 * Return the day of month (1-based) on the Gregorian calendar as
1907 * computed by <code>computeGregorianFields()</code>.
1910 int32_t getGregorianDayOfMonth() const {
1911 return fGregorianDayOfMonth
;
1913 #endif /* U_HIDE_INTERNAL_API */
1916 * Called by computeJulianDay. Returns the default month (0-based) for the year,
1917 * taking year and era into account. Defaults to 0 for Gregorian, which doesn't care.
1918 * @param eyear The extended year
1921 virtual int32_t getDefaultMonthInYear(int32_t eyear
) ;
1925 * Called by computeJulianDay. Returns the default day (1-based) for the month,
1926 * taking currently-set year and era into account. Defaults to 1 for Gregorian.
1927 * @param eyear the extended year
1928 * @param month the month in the year
1931 virtual int32_t getDefaultDayInMonth(int32_t eyear
, int32_t month
);
1933 //-------------------------------------------------------------------------
1934 // Protected utility methods for use by subclasses. These are very handy
1935 // for implementing add, roll, and computeFields.
1936 //-------------------------------------------------------------------------
1939 * Adjust the specified field so that it is within
1940 * the allowable range for the date to which this calendar is set.
1941 * For example, in a Gregorian calendar pinning the {@link #UCalendarDateFields DAY_OF_MONTH}
1942 * field for a calendar set to April 31 would cause it to be set
1945 * <b>Subclassing:</b>
1947 * This utility method is intended for use by subclasses that need to implement
1948 * their own overrides of {@link #roll roll} and {@link #add add}.
1951 * <code>pinField</code> is implemented in terms of
1952 * {@link #getActualMinimum getActualMinimum}
1953 * and {@link #getActualMaximum getActualMaximum}. If either of those methods uses
1954 * a slow, iterative algorithm for a particular field, it would be
1955 * unwise to attempt to call <code>pinField</code> for that field. If you
1956 * really do need to do so, you should override this method to do
1957 * something more efficient for that field.
1959 * @param field The calendar field whose value should be pinned.
1960 * @param status Output param set to failure code on function return
1961 * when this function fails.
1963 * @see #getActualMinimum
1964 * @see #getActualMaximum
1967 virtual void pinField(UCalendarDateFields field
, UErrorCode
& status
);
1970 * Return the week number of a day, within a period. This may be the week number in
1971 * a year or the week number in a month. Usually this will be a value >= 1, but if
1972 * some initial days of the period are excluded from week 1, because
1973 * {@link #getMinimalDaysInFirstWeek getMinimalDaysInFirstWeek} is > 1, then
1974 * the week number will be zero for those
1975 * initial days. This method requires the day number and day of week for some
1976 * known date in the period in order to determine the day of week
1977 * on the desired day.
1979 * <b>Subclassing:</b>
1981 * This method is intended for use by subclasses in implementing their
1982 * {@link #computeTime computeTime} and/or {@link #computeFields computeFields} methods.
1983 * It is often useful in {@link #getActualMinimum getActualMinimum} and
1984 * {@link #getActualMaximum getActualMaximum} as well.
1986 * This variant is handy for computing the week number of some other
1987 * day of a period (often the first or last day of the period) when its day
1988 * of the week is not known but the day number and day of week for some other
1989 * day in the period (e.g. the current date) <em>is</em> known.
1991 * @param desiredDay The {@link #UCalendarDateFields DAY_OF_YEAR} or
1992 * {@link #UCalendarDateFields DAY_OF_MONTH} whose week number is desired.
1993 * Should be 1 for the first day of the period.
1995 * @param dayOfPeriod The {@link #UCalendarDateFields DAY_OF_YEAR}
1996 * or {@link #UCalendarDateFields DAY_OF_MONTH} for a day in the period whose
1997 * {@link #UCalendarDateFields DAY_OF_WEEK} is specified by the
1998 * <code>knownDayOfWeek</code> parameter.
1999 * Should be 1 for first day of period.
2001 * @param dayOfWeek The {@link #UCalendarDateFields DAY_OF_WEEK} for the day
2002 * corresponding to the <code>knownDayOfPeriod</code> parameter.
2003 * 1-based with 1=Sunday.
2005 * @return The week number (one-based), or zero if the day falls before
2006 * the first week because
2007 * {@link #getMinimalDaysInFirstWeek getMinimalDaysInFirstWeek}
2012 int32_t weekNumber(int32_t desiredDay
, int32_t dayOfPeriod
, int32_t dayOfWeek
);
2015 #ifndef U_HIDE_INTERNAL_API
2017 * Return the week number of a day, within a period. This may be the week number in
2018 * a year, or the week number in a month. Usually this will be a value >= 1, but if
2019 * some initial days of the period are excluded from week 1, because
2020 * {@link #getMinimalDaysInFirstWeek getMinimalDaysInFirstWeek} is > 1,
2021 * then the week number will be zero for those
2022 * initial days. This method requires the day of week for the given date in order to
2023 * determine the result.
2025 * <b>Subclassing:</b>
2027 * This method is intended for use by subclasses in implementing their
2028 * {@link #computeTime computeTime} and/or {@link #computeFields computeFields} methods.
2029 * It is often useful in {@link #getActualMinimum getActualMinimum} and
2030 * {@link #getActualMaximum getActualMaximum} as well.
2032 * @param dayOfPeriod The {@link #UCalendarDateFields DAY_OF_YEAR} or
2033 * {@link #UCalendarDateFields DAY_OF_MONTH} whose week number is desired.
2034 * Should be 1 for the first day of the period.
2036 * @param dayOfWeek The {@link #UCalendarDateFields DAY_OF_WEEK} for the day
2037 * corresponding to the <code>dayOfPeriod</code> parameter.
2038 * 1-based with 1=Sunday.
2040 * @return The week number (one-based), or zero if the day falls before
2041 * the first week because
2042 * {@link #getMinimalDaysInFirstWeek getMinimalDaysInFirstWeek}
2046 inline int32_t weekNumber(int32_t dayOfPeriod
, int32_t dayOfWeek
);
2049 * returns the local DOW, valid range 0..6
2052 int32_t getLocalDOW();
2053 #endif /* U_HIDE_INTERNAL_API */
2058 * The next available value for fStamp[]
2060 int32_t fNextStamp
;// = MINIMUM_USER_STAMP;
2063 * Recalculates the time stamp array (fStamp).
2064 * Resets fNextStamp to lowest next stamp value.
2066 void recalculateStamp();
2069 * The current time set for the calendar.
2079 * Time zone affects the time calculation done by Calendar. Calendar subclasses use
2080 * the time zone data to produce the local time.
2085 * Option for rpeated wall time
2086 * @see #setRepeatedWallTimeOption
2088 UCalendarWallTimeOption fRepeatedWallTime
;
2091 * Option for skipped wall time
2092 * @see #setSkippedWallTimeOption
2094 UCalendarWallTimeOption fSkippedWallTime
;
2097 * Both firstDayOfWeek and minimalDaysInFirstWeek are locale-dependent. They are
2098 * used to figure out the week count for a specific date for a given locale. These
2099 * must be set when a Calendar is constructed. For example, in US locale,
2100 * firstDayOfWeek is SUNDAY; minimalDaysInFirstWeek is 1. They are used to figure
2101 * out the week count for a specific date for a given locale. These must be set when
2102 * a Calendar is constructed.
2104 UCalendarDaysOfWeek fFirstDayOfWeek
;
2105 uint8_t fMinimalDaysInFirstWeek
;
2106 UCalendarDaysOfWeek fWeekendOnset
;
2107 int32_t fWeekendOnsetMillis
;
2108 UCalendarDaysOfWeek fWeekendCease
;
2109 int32_t fWeekendCeaseMillis
;
2112 * Sets firstDayOfWeek and minimalDaysInFirstWeek. Called at Calendar construction
2115 * @param desiredLocale The given locale.
2116 * @param type The calendar type identifier, e.g: gregorian, buddhist, etc.
2117 * @param success Indicates the status of setting the week count data from
2118 * the resource for the given locale. Returns U_ZERO_ERROR if
2119 * constructed successfully.
2121 void setWeekData(const Locale
& desiredLocale
, const char *type
, UErrorCode
& success
);
2124 * Recompute the time and update the status fields isTimeSet
2125 * and areFieldsSet. Callers should check isTimeSet and only
2126 * call this method if isTimeSet is false.
2128 * @param status Output param set to success/failure code on exit. If any value
2129 * previously set in the time field is invalid or restricted by
2130 * leniency, this will be set to an error status.
2132 void updateTime(UErrorCode
& status
);
2135 * The Gregorian year, as computed by computeGregorianFields() and
2136 * returned by getGregorianYear().
2137 * @see #computeGregorianFields
2139 int32_t fGregorianYear
;
2142 * The Gregorian month, as computed by computeGregorianFields() and
2143 * returned by getGregorianMonth().
2144 * @see #computeGregorianFields
2146 int32_t fGregorianMonth
;
2149 * The Gregorian day of the year, as computed by
2150 * computeGregorianFields() and returned by getGregorianDayOfYear().
2151 * @see #computeGregorianFields
2153 int32_t fGregorianDayOfYear
;
2156 * The Gregorian day of the month, as computed by
2157 * computeGregorianFields() and returned by getGregorianDayOfMonth().
2158 * @see #computeGregorianFields
2160 int32_t fGregorianDayOfMonth
;
2165 * Compute the Gregorian calendar year, month, and day of month from
2166 * the given Julian day. These values are not stored in fields, but in
2167 * member variables gregorianXxx. Also compute the DAY_OF_WEEK and
2170 void computeGregorianAndDOWFields(int32_t julianDay
, UErrorCode
&ec
);
2175 * Compute the Gregorian calendar year, month, and day of month from the
2176 * Julian day. These values are not stored in fields, but in member
2177 * variables gregorianXxx. They are used for time zone computations and by
2178 * subclasses that are Gregorian derivatives. Subclasses may call this
2179 * method to perform a Gregorian calendar millis->fields computation.
2181 void computeGregorianFields(int32_t julianDay
, UErrorCode
&ec
);
2186 * Compute the fields WEEK_OF_YEAR, YEAR_WOY, WEEK_OF_MONTH,
2187 * DAY_OF_WEEK_IN_MONTH, and DOW_LOCAL from EXTENDED_YEAR, YEAR,
2188 * DAY_OF_WEEK, and DAY_OF_YEAR. The latter fields are computed by the
2189 * subclass based on the calendar system.
2191 * <p>The YEAR_WOY field is computed simplistically. It is equal to YEAR
2192 * most of the time, but at the year boundary it may be adjusted to YEAR-1
2193 * or YEAR+1 to reflect the overlap of a week into an adjacent year. In
2194 * this case, a simple increment or decrement is performed on YEAR, even
2195 * though this may yield an invalid YEAR value. For instance, if the YEAR
2196 * is part of a calendar system with an N-year cycle field CYCLE, then
2197 * incrementing the YEAR may involve incrementing CYCLE and setting YEAR
2198 * back to 0 or 1. This is not handled by this code, and in fact cannot be
2199 * simply handled without having subclasses define an entire parallel set of
2200 * fields for fields larger than or equal to a year. This additional
2201 * complexity is not warranted, since the intention of the YEAR_WOY field is
2202 * to support ISO 8601 notation, so it will typically be used with a
2203 * proleptic Gregorian calendar, which has no field larger than a year.
2205 void computeWeekFields(UErrorCode
&ec
);
2209 * Ensure that each field is within its valid range by calling {@link
2210 * #validateField(int, int&)} on each field that has been set. This method
2211 * should only be called if this calendar is not lenient.
2213 * @see #validateField(int, int&)
2216 void validateFields(UErrorCode
&status
);
2219 * Validate a single field of this calendar. Subclasses should
2220 * override this method to validate any calendar-specific fields.
2221 * Generic fields can be handled by
2222 * <code>Calendar::validateField()</code>.
2223 * @see #validateField(int, int, int, int&)
2226 virtual void validateField(UCalendarDateFields field
, UErrorCode
&status
);
2229 * Validate a single field of this calendar given its minimum and
2230 * maximum allowed value. If the field is out of range,
2231 * <code>U_ILLEGAL_ARGUMENT_ERROR</code> will be set. Subclasses may
2232 * use this method in their implementation of {@link
2233 * #validateField(int, int&)}.
2236 void validateField(UCalendarDateFields field
, int32_t min
, int32_t max
, UErrorCode
& status
);
2239 #ifndef U_HIDE_INTERNAL_API
2241 * Convert a quasi Julian date to the day of the week. The Julian date used here is
2242 * not a true Julian date, since it is measured from midnight, not noon. Return
2243 * value is one-based.
2245 * @param julian The given Julian date number.
2246 * @return Day number from 1..7 (SUN..SAT).
2249 static uint8_t julianDayToDayOfWeek(double julian
);
2250 #endif /* U_HIDE_INTERNAL_API */
2253 char validLocale
[ULOC_FULLNAME_CAPACITY
];
2254 char actualLocale
[ULOC_FULLNAME_CAPACITY
];
2257 #if !UCONFIG_NO_SERVICE
2259 * INTERNAL FOR 2.6 -- Registration.
2262 #ifndef U_HIDE_INTERNAL_API
2264 * Return a StringEnumeration over the locales available at the time of the call,
2265 * including registered locales.
2266 * @return a StringEnumeration over the locales available at the time of the call
2269 static StringEnumeration
* getAvailableLocales(void);
2272 * Register a new Calendar factory. The factory will be adopted.
2274 * @param toAdopt the factory instance to be adopted
2275 * @param status the in/out status code, no special meanings are assigned
2276 * @return a registry key that can be used to unregister this factory
2279 static URegistryKey
registerFactory(ICUServiceFactory
* toAdopt
, UErrorCode
& status
);
2282 * Unregister a previously-registered CalendarFactory using the key returned from the
2283 * register call. Key becomes invalid after a successful call and should not be used again.
2284 * The CalendarFactory corresponding to the key will be deleted.
2286 * @param key the registry key returned by a previous call to registerFactory
2287 * @param status the in/out status code, no special meanings are assigned
2288 * @return TRUE if the factory for the key was successfully unregistered
2291 static UBool
unregister(URegistryKey key
, UErrorCode
& status
);
2292 #endif /* U_HIDE_INTERNAL_API */
2295 * Multiple Calendar Implementation
2298 friend class CalendarFactory
;
2301 * Multiple Calendar Implementation
2304 friend class CalendarService
;
2307 * Multiple Calendar Implementation
2310 friend class DefaultCalendarFactory
;
2311 #endif /* !UCONFIG_NO_SERVICE */
2315 * @return TRUE if this calendar has a default century (i.e. 03 -> 2003)
2317 virtual UBool
haveDefaultCentury() const = 0;
2321 * @return the start of the default century, as a UDate
2323 virtual UDate
defaultCenturyStart() const = 0;
2326 * @return the beginning year of the default century, as a year
2328 virtual int32_t defaultCenturyStartYear() const = 0;
2330 /** Get the locale for this calendar object. You can choose between valid and actual locale.
2331 * @param type type of the locale we're looking for (valid or actual)
2332 * @param status error code for the operation
2333 * @return the locale
2336 Locale
getLocale(ULocDataLocaleType type
, UErrorCode
&status
) const;
2338 #ifndef U_HIDE_INTERNAL_API
2339 /** Get the locale for this calendar object. You can choose between valid and actual locale.
2340 * @param type type of the locale we're looking for (valid or actual)
2341 * @param status error code for the operation
2342 * @return the locale
2345 const char* getLocaleID(ULocDataLocaleType type
, UErrorCode
&status
) const;
2346 #endif /* U_HIDE_INTERNAL_API */
2350 * Cast TimeZone used by this object to BasicTimeZone, or NULL if the TimeZone
2351 * is not an instance of BasicTimeZone.
2353 BasicTimeZone
* getBasicTimeZone() const;
2356 // -------------------------------------
2359 Calendar::createInstance(TimeZone
* zone
, UErrorCode
& errorCode
)
2361 // since the Locale isn't specified, use the default locale
2362 return createInstance(zone
, Locale::getDefault(), errorCode
);
2365 // -------------------------------------
2368 Calendar::roll(UCalendarDateFields field
, UBool up
, UErrorCode
& status
)
2370 roll(field
, (int32_t)(up
? +1 : -1), status
);
2373 #ifndef U_HIDE_DEPRECATED_API
2375 Calendar::roll(EDateFields field
, UBool up
, UErrorCode
& status
)
2377 roll((UCalendarDateFields
) field
, up
, status
);
2382 // -------------------------------------
2385 * Fast method for subclasses. The caller must maintain fUserSetDSTOffset and
2386 * fUserSetZoneOffset, as well as the isSet[] array.
2390 Calendar::internalSet(UCalendarDateFields field
, int32_t value
)
2392 fFields
[field
] = value
;
2393 fStamp
[field
] = kInternallySet
;
2394 fIsSet
[field
] = TRUE
; // Remove later
2398 #ifndef U_HIDE_INTERNAL_API
2399 inline int32_t Calendar::weekNumber(int32_t dayOfPeriod
, int32_t dayOfWeek
)
2401 return weekNumber(dayOfPeriod
, dayOfPeriod
, dayOfWeek
);
2407 #endif /* #if !UCONFIG_NO_FORMATTING */