]> git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/unicode/calendar.h
ICU-3.13.tar.gz
[apple/icu.git] / icuSources / i18n / unicode / calendar.h
1 /*
2 ********************************************************************************
3 * Copyright (C) 1997-2003, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 ********************************************************************************
6 *
7 * File CALENDAR.H
8 *
9 * Modification History:
10 *
11 * Date Name Description
12 * 04/22/97 aliu Expanded and corrected comments and other header
13 * contents.
14 * 05/01/97 aliu Made equals(), before(), after() arguments const.
15 * 05/20/97 aliu Replaced fAreFieldsSet with fAreFieldsInSync and
16 * fAreAllFieldsSet.
17 * 07/27/98 stephen Sync up with JDK 1.2
18 * 11/15/99 weiv added YEAR_WOY and DOW_LOCAL
19 * to EDateFields
20 * 8/19/2002 srl Removed Javaisms
21 ********************************************************************************
22 */
23
24 #ifndef CALENDAR_H
25 #define CALENDAR_H
26
27 #include "unicode/utypes.h"
28
29 #if !UCONFIG_NO_FORMATTING
30
31 #include "unicode/uobject.h"
32 #include "unicode/locid.h"
33 #include "unicode/timezone.h"
34 #include "unicode/ucal.h"
35
36 U_NAMESPACE_BEGIN
37
38 class ICUServiceFactory;
39
40 /**
41 * @internal
42 */
43 typedef const void* URegistryKey;
44
45 /**
46 * <code>Calendar</code> is an abstract base class for converting between
47 * a <code>UDate</code> object and a set of integer fields such as
48 * <code>YEAR</code>, <code>MONTH</code>, <code>DAY</code>, <code>HOUR</code>,
49 * and so on. (A <code>UDate</code> object represents a specific instant in
50 * time with millisecond precision. See UDate
51 * for information about the <code>UDate</code> class.)
52 *
53 * <p>
54 * Subclasses of <code>Calendar</code> interpret a <code>UDate</code>
55 * according to the rules of a specific calendar system.
56 * The most commonly used subclass of <code>Calendar</code> is
57 * <code>GregorianCalendar</code>. Other subclasses could represent
58 * the various types of lunar calendars in use in many parts of the world.
59 *
60 * <p>
61 * <b>NOTE</b>: (ICU 2.6) The subclass interface should be considered unstable
62 * - it WILL change.
63 *
64 * <p>
65 * Like other locale-sensitive classes, <code>Calendar</code> provides a
66 * static method, <code>createInstance</code>, for getting a generally useful
67 * object of this type. <code>Calendar</code>'s <code>createInstance</code> method
68 * returns the appropriate <code>Calendar</code> subclass whose
69 * time fields have been initialized with the current date and time:
70 * <blockquote>
71 * <pre>
72 * Calendar *rightNow = Calendar::createInstance(errCode);
73 * </pre>
74 * </blockquote>
75 *
76 * <p>
77 * A <code>Calendar</code> object can produce all the time field values
78 * needed to implement the date-time formatting for a particular language
79 * and calendar style (for example, Japanese-Gregorian, Japanese-Traditional).
80 *
81 * <p>
82 * When computing a <code>UDate</code> from time fields, two special circumstances
83 * may arise: there may be insufficient information to compute the
84 * <code>UDate</code> (such as only year and month but no day in the month),
85 * or there may be inconsistent information (such as "Tuesday, July 15, 1996"
86 * -- July 15, 1996 is actually a Monday).
87 *
88 * <p>
89 * <strong>Insufficient information.</strong> The calendar will use default
90 * information to specify the missing fields. This may vary by calendar; for
91 * the Gregorian calendar, the default for a field is the same as that of the
92 * start of the epoch: i.e., YEAR = 1970, MONTH = JANUARY, DATE = 1, etc.
93 *
94 * <p>
95 * <strong>Inconsistent information.</strong> If fields conflict, the calendar
96 * will give preference to fields set more recently. For example, when
97 * determining the day, the calendar will look for one of the following
98 * combinations of fields. The most recent combination, as determined by the
99 * most recently set single field, will be used.
100 *
101 * <blockquote>
102 * <pre>
103 * MONTH + DAY_OF_MONTH
104 * MONTH + WEEK_OF_MONTH + DAY_OF_WEEK
105 * MONTH + DAY_OF_WEEK_IN_MONTH + DAY_OF_WEEK
106 * DAY_OF_YEAR
107 * DAY_OF_WEEK + WEEK_OF_YEAR
108 * </pre>
109 * </blockquote>
110 *
111 * For the time of day:
112 *
113 * <blockquote>
114 * <pre>
115 * HOUR_OF_DAY
116 * AM_PM + HOUR
117 * </pre>
118 * </blockquote>
119 *
120 * <p>
121 * <strong>Note:</strong> for some non-Gregorian calendars, different
122 * fields may be necessary for complete disambiguation. For example, a full
123 * specification of the historial Arabic astronomical calendar requires year,
124 * month, day-of-month <em>and</em> day-of-week in some cases.
125 *
126 * <p>
127 * <strong>Note:</strong> There are certain possible ambiguities in
128 * interpretation of certain singular times, which are resolved in the
129 * following ways:
130 * <ol>
131 * <li> 24:00:00 "belongs" to the following day. That is,
132 * 23:59 on Dec 31, 1969 &lt; 24:00 on Jan 1, 1970 &lt; 24:01:00 on Jan 1, 1970
133 *
134 * <li> Although historically not precise, midnight also belongs to "am",
135 * and noon belongs to "pm", so on the same day,
136 * 12:00 am (midnight) &lt; 12:01 am, and 12:00 pm (noon) &lt; 12:01 pm
137 * </ol>
138 *
139 * <p>
140 * The date or time format strings are not part of the definition of a
141 * calendar, as those must be modifiable or overridable by the user at
142 * runtime. Use {@link DateFormat}
143 * to format dates.
144 *
145 * <p>
146 * <code>Calendar</code> provides an API for field "rolling", where fields
147 * can be incremented or decremented, but wrap around. For example, rolling the
148 * month up in the date <code>December 12, <b>1996</b></code> results in
149 * <code>January 12, <b>1996</b></code>.
150 *
151 * <p>
152 * <code>Calendar</code> also provides a date arithmetic function for
153 * adding the specified (signed) amount of time to a particular time field.
154 * For example, subtracting 5 days from the date <code>September 12, 1996</code>
155 * results in <code>September 7, 1996</code>.
156 *
157 * @stable ICU 2.0
158 */
159 class U_I18N_API Calendar : public UObject {
160 public:
161
162 /**
163 * Field IDs for date and time. Used to specify date/time fields. ERA is calendar
164 * specific. Example ranges given are for illustration only; see specific Calendar
165 * subclasses for actual ranges.
166 * @deprecated ICU 2.6. Use C enum UCalendarDateFields defined in ucal.h
167 */
168 enum EDateFields {
169 ERA, // Example: 0..1
170 YEAR, // Example: 1..big number
171 MONTH, // Example: 0..11
172 WEEK_OF_YEAR, // Example: 1..53
173 WEEK_OF_MONTH, // Example: 1..4
174 DATE, // Example: 1..31
175 DAY_OF_YEAR, // Example: 1..365
176 DAY_OF_WEEK, // Example: 1..7
177 DAY_OF_WEEK_IN_MONTH, // Example: 1..4, may be specified as -1
178 AM_PM, // Example: 0..1
179 HOUR, // Example: 0..11
180 HOUR_OF_DAY, // Example: 0..23
181 MINUTE, // Example: 0..59
182 SECOND, // Example: 0..59
183 MILLISECOND, // Example: 0..999
184 ZONE_OFFSET, // Example: -12*U_MILLIS_PER_HOUR..12*U_MILLIS_PER_HOUR
185 DST_OFFSET, // Example: 0 or U_MILLIS_PER_HOUR
186 // here will go names for 'Y' and 'e'
187 YEAR_WOY, // 'Y' Example: 1..big number
188 DOW_LOCAL, // 'e' Example: 1..7
189 FIELD_COUNT,
190
191 DAY_OF_MONTH = DATE // Synonyms
192 };
193
194 /**
195 * Useful constant for days of week. Note: Calendar day-of-week is 1-based. Clients
196 * who create locale resources for the field of first-day-of-week should be aware of
197 * this. For instance, in US locale, first-day-of-week is set to 1, i.e., SUNDAY.
198 * @deprecated ICU 2.6. Use C enum UCalendarDaysOfWeek defined in ucal.h
199 */
200 enum EDaysOfWeek {
201 SUNDAY = 1,
202 MONDAY,
203 TUESDAY,
204 WEDNESDAY,
205 THURSDAY,
206 FRIDAY,
207 SATURDAY
208 };
209
210 /**
211 * Useful constants for month. Note: Calendar month is 0-based.
212 * @deprecated ICU 2.6. Use C enum UCalendarMonths defined in ucal.h
213 */
214 enum EMonths {
215 JANUARY,
216 FEBRUARY,
217 MARCH,
218 APRIL,
219 MAY,
220 JUNE,
221 JULY,
222 AUGUST,
223 SEPTEMBER,
224 OCTOBER,
225 NOVEMBER,
226 DECEMBER,
227 UNDECIMBER
228 };
229
230 /**
231 * Useful constants for hour in 12-hour clock. Used in GregorianCalendar.
232 * @deprecated ICU 2.6. Use C enum UCalendarAMPMs defined in ucal.h
233 */
234 enum EAmpm {
235 AM,
236 PM
237 };
238
239 /**
240 * destructor
241 * @stable ICU 2.0
242 */
243 virtual ~Calendar();
244
245 /**
246 * Create and return a polymorphic copy of this calendar.
247 *
248 * @return a polymorphic copy of this calendar.
249 * @stable ICU 2.0
250 */
251 virtual Calendar* clone(void) const = 0;
252
253 /**
254 * Creates a Calendar using the default timezone and locale. Clients are responsible
255 * for deleting the object returned.
256 *
257 * @param success Indicates the success/failure of Calendar creation. Filled in
258 * with U_ZERO_ERROR if created successfully, set to a failure result
259 * otherwise. U_MISSING_RESOURCE_ERROR will be returned if the resource data
260 * requests a calendar type which has not been installed.
261 * @return A Calendar if created successfully. NULL otherwise.
262 * @stable ICU 2.0
263 */
264 static Calendar* createInstance(UErrorCode& success);
265
266 /**
267 * Creates a Calendar using the given timezone and the default locale.
268 * The Calendar takes ownership of zoneToAdopt; the
269 * client must not delete it.
270 *
271 * @param zoneToAdopt The given timezone to be adopted.
272 * @param success Indicates the success/failure of Calendar creation. Filled in
273 * with U_ZERO_ERROR if created successfully, set to a failure result
274 * otherwise.
275 * @return A Calendar if created successfully. NULL otherwise.
276 * @stable ICU 2.0
277 */
278 static Calendar* createInstance(TimeZone* zoneToAdopt, UErrorCode& success);
279
280 /**
281 * Creates a Calendar using the given timezone and the default locale. The TimeZone
282 * is _not_ adopted; the client is still responsible for deleting it.
283 *
284 * @param zone The timezone.
285 * @param success Indicates the success/failure of Calendar creation. Filled in
286 * with U_ZERO_ERROR if created successfully, set to a failure result
287 * otherwise.
288 * @return A Calendar if created successfully. NULL otherwise.
289 * @stable ICU 2.0
290 */
291 static Calendar* createInstance(const TimeZone& zone, UErrorCode& success);
292
293 /**
294 * Creates a Calendar using the default timezone and the given locale.
295 *
296 * @param aLocale The given locale.
297 * @param success Indicates the success/failure of Calendar creation. Filled in
298 * with U_ZERO_ERROR if created successfully, set to a failure result
299 * otherwise.
300 * @return A Calendar if created successfully. NULL otherwise.
301 * @stable ICU 2.0
302 */
303 static Calendar* createInstance(const Locale& aLocale, UErrorCode& success);
304
305 /**
306 * Creates a Calendar using the given timezone and given locale.
307 * The Calendar takes ownership of zoneToAdopt; the
308 * client must not delete it.
309 *
310 * @param zoneToAdopt The given timezone to be adopted.
311 * @param aLocale The given locale.
312 * @param success Indicates the success/failure of Calendar creation. Filled in
313 * with U_ZERO_ERROR if created successfully, set to a failure result
314 * otherwise.
315 * @return A Calendar if created successfully. NULL otherwise.
316 * @stable ICU 2.0
317 */
318 static Calendar* createInstance(TimeZone* zoneToAdopt, const Locale& aLocale, UErrorCode& success);
319
320 /**
321 * Gets a Calendar using the given timezone and given locale. The TimeZone
322 * is _not_ adopted; the client is still responsible for deleting it.
323 *
324 * @param zoneToAdopt The given timezone to be adopted.
325 * @param aLocale The given locale.
326 * @param success Indicates the success/failure of Calendar creation. Filled in
327 * with U_ZERO_ERROR if created successfully, set to a failure result
328 * otherwise.
329 * @return A Calendar if created successfully. NULL otherwise.
330 * @stable ICU 2.0
331 */
332 static Calendar* createInstance(const TimeZone& zoneToAdopt, const Locale& aLocale, UErrorCode& success);
333
334 /**
335 * Returns a list of the locales for which Calendars are installed.
336 *
337 * @param count Number of locales returned.
338 * @return An array of Locale objects representing the set of locales for which
339 * Calendars are installed. The system retains ownership of this list;
340 * the caller must NOT delete it. Does not include user-registered Calendars.
341 * @stable ICU 2.0
342 */
343 static const Locale* getAvailableLocales(int32_t& count);
344
345 /**
346 * Returns the current UTC (GMT) time measured in milliseconds since 0:00:00 on 1/1/70
347 * (derived from the system time).
348 *
349 * @return The current UTC time in milliseconds.
350 * @stable ICU 2.0
351 */
352 static UDate getNow(void);
353
354 /**
355 * Gets this Calendar's time as milliseconds. May involve recalculation of time due
356 * to previous calls to set time field values. The time specified is non-local UTC
357 * (GMT) time. Although this method is const, this object may actually be changed
358 * (semantically const).
359 *
360 * @param status Output param set to success/failure code on exit. If any value
361 * previously set in the time field is invalid or restricted by
362 * leniency, this will be set to an error status.
363 * @return The current time in UTC (GMT) time, or zero if the operation
364 * failed.
365 * @stable ICU 2.0
366 */
367 inline UDate getTime(UErrorCode& status) const { return getTimeInMillis(status); }
368
369 /**
370 * Sets this Calendar's current time with the given UDate. The time specified should
371 * be in non-local UTC (GMT) time.
372 *
373 * @param date The given UDate in UTC (GMT) time.
374 * @param status Output param set to success/failure code on exit. If any value
375 * set in the time field is invalid or restricted by
376 * leniency, this will be set to an error status.
377 * @stable ICU 2.0
378 */
379 inline void setTime(UDate date, UErrorCode& status) { setTimeInMillis(date, status); }
380
381 /**
382 * Compares the equality of two Calendar objects. Objects of different subclasses
383 * are considered unequal. This comparison is very exacting; two Calendar objects
384 * must be in exactly the same state to be considered equal. To compare based on the
385 * represented time, use equals() instead.
386 *
387 * @param that The Calendar object to be compared with.
388 * @return True if the given Calendar is the same as this Calendar; false
389 * otherwise.
390 * @stable ICU 2.0
391 */
392 virtual UBool operator==(const Calendar& that) const;
393
394 /**
395 * Compares the inequality of two Calendar objects.
396 *
397 * @param that The Calendar object to be compared with.
398 * @return True if the given Calendar is not the same as this Calendar; false
399 * otherwise.
400 * @stable ICU 2.0
401 */
402 UBool operator!=(const Calendar& that) const {return !operator==(that);}
403
404 /**
405 * Returns TRUE if the given Calendar object is equivalent to this
406 * one. An equivalent Calendar will behave exactly as this one
407 * does, but it may be set to a different time. By contrast, for
408 * the operator==() method to return TRUE, the other Calendar must
409 * be set to the same time.
410 *
411 * @param other the Calendar to be compared with this Calendar
412 * @draft ICU 2.4
413 */
414 virtual UBool isEquivalentTo(const Calendar& other) const;
415
416 /**
417 * Compares the Calendar time, whereas Calendar::operator== compares the equality of
418 * Calendar objects.
419 *
420 * @param when The Calendar to be compared with this Calendar. Although this is a
421 * const parameter, the object may be modified physically
422 * (semantically const).
423 * @param status Output param set to success/failure code on exit. If any value
424 * previously set in the time field is invalid or restricted by
425 * leniency, this will be set to an error status.
426 * @return True if the current time of this Calendar is equal to the time of
427 * Calendar when; false otherwise.
428 * @stable ICU 2.0
429 */
430 UBool equals(const Calendar& when, UErrorCode& status) const;
431
432 /**
433 * Returns true if this Calendar's current time is before "when"'s current time.
434 *
435 * @param when The Calendar to be compared with this Calendar. Although this is a
436 * const parameter, the object may be modified physically
437 * (semantically const).
438 * @param status Output param set to success/failure code on exit. If any value
439 * previously set in the time field is invalid or restricted by
440 * leniency, this will be set to an error status.
441 * @return True if the current time of this Calendar is before the time of
442 * Calendar when; false otherwise.
443 * @stable ICU 2.0
444 */
445 UBool before(const Calendar& when, UErrorCode& status) const;
446
447 /**
448 * Returns true if this Calendar's current time is after "when"'s current time.
449 *
450 * @param when The Calendar to be compared with this Calendar. Although this is a
451 * const parameter, the object may be modified physically
452 * (semantically const).
453 * @param status Output param set to success/failure code on exit. If any value
454 * previously set in the time field is invalid or restricted by
455 * leniency, this will be set to an error status.
456 * @return True if the current time of this Calendar is after the time of
457 * Calendar when; false otherwise.
458 * @stable ICU 2.0
459 */
460 UBool after(const Calendar& when, UErrorCode& status) const;
461
462 /**
463 * UDate Arithmetic function. Adds the specified (signed) amount of time to the given
464 * time field, based on the calendar's rules. For example, to subtract 5 days from
465 * the current time of the calendar, call add(Calendar::DATE, -5). When adding on
466 * the month or Calendar::MONTH field, other fields like date might conflict and
467 * need to be changed. For instance, adding 1 month on the date 01/31/96 will result
468 * in 02/29/96.
469 *
470 * @param field Specifies which date field to modify.
471 * @param amount The amount of time to be added to the field, in the natural unit
472 * for that field (e.g., days for the day fields, hours for the hour
473 * field.)
474 * @param status Output param set to success/failure code on exit. If any value
475 * previously set in the time field is invalid or restricted by
476 * leniency, this will be set to an error status.
477 * @deprecated ICU 2.6. use add(UCalendarDateFields field, int32_t amount, UErrorCode& status) instead.
478 */
479 virtual void add(EDateFields field, int32_t amount, UErrorCode& status) = 0;
480
481 /**
482 * UDate Arithmetic function. Adds the specified (signed) amount of time to the given
483 * time field, based on the calendar's rules. For example, to subtract 5 days from
484 * the current time of the calendar, call add(Calendar::DATE, -5). When adding on
485 * the month or Calendar::MONTH field, other fields like date might conflict and
486 * need to be changed. For instance, adding 1 month on the date 01/31/96 will result
487 * in 02/29/96.
488 *
489 * @param field Specifies which date field to modify.
490 * @param amount The amount of time to be added to the field, in the natural unit
491 * for that field (e.g., days for the day fields, hours for the hour
492 * field.)
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 * @draft ICU 2.6.
497 */
498 virtual void add(UCalendarDateFields field, int32_t amount, UErrorCode& status) = 0;
499
500 /**
501 * Time Field Rolling function. Rolls (up/down) a single unit of time on the given
502 * time field. For example, to roll the current date up by one day, call
503 * roll(Calendar::DATE, true). When rolling on the year or Calendar::YEAR field, it
504 * will roll the year value in the range between getMinimum(Calendar::YEAR) and the
505 * value returned by getMaximum(Calendar::YEAR). When rolling on the month or
506 * Calendar::MONTH field, other fields like date might conflict and, need to be
507 * changed. For instance, rolling the month up on the date 01/31/96 will result in
508 * 02/29/96. Rolling up always means rolling forward in time; e.g., rolling the year
509 * up on "100 BC" will result in "99 BC", for Gregorian calendar. When rolling on the
510 * hour-in-day or Calendar::HOUR_OF_DAY field, it will roll the hour value in the range
511 * between 0 and 23, which is zero-based.
512 * <P>
513 * NOTE: Do not use this method -- use roll(EDateFields, int, UErrorCode&) instead.
514 *
515 * @param field The time field.
516 * @param up Indicates if the value of the specified time field is to be rolled
517 * up or rolled down. Use true if rolling up, false otherwise.
518 * @param status Output param set to success/failure code on exit. If any value
519 * previously set in the time field is invalid or restricted by
520 * leniency, this will be set to an error status.
521 * @deprecated ICU 2.6. Use roll(UCalendarDateFields field, UBool up, UErrorCode& status) instead.
522 */
523 inline void roll(EDateFields field, UBool up, UErrorCode& status);
524
525 /**
526 * Time Field Rolling function. Rolls (up/down) a single unit of time on the given
527 * time field. For example, to roll the current date up by one day, call
528 * roll(Calendar::DATE, true). When rolling on the year or Calendar::YEAR field, it
529 * will roll the year value in the range between getMinimum(Calendar::YEAR) and the
530 * value returned by getMaximum(Calendar::YEAR). When rolling on the month or
531 * Calendar::MONTH field, other fields like date might conflict and, need to be
532 * changed. For instance, rolling the month up on the date 01/31/96 will result in
533 * 02/29/96. Rolling up always means rolling forward in time; e.g., rolling the year
534 * up on "100 BC" will result in "99 BC", for Gregorian calendar. When rolling on the
535 * hour-in-day or Calendar::HOUR_OF_DAY field, it will roll the hour value in the range
536 * between 0 and 23, which is zero-based.
537 * <P>
538 * NOTE: Do not use this method -- use roll(UCalendarDateFields, int, UErrorCode&) instead.
539 *
540 * @param field The time field.
541 * @param up Indicates if the value of the specified time field is to be rolled
542 * up or rolled down. Use true if rolling up, false otherwise.
543 * @param status Output param set to success/failure code on exit. If any value
544 * previously set in the time field is invalid or restricted by
545 * leniency, this will be set to an error status.
546 * @draft ICU 2.6.
547 */
548 inline void roll(UCalendarDateFields field, UBool up, UErrorCode& status);
549
550 /**
551 * Time Field Rolling function. Rolls by the given amount on the given
552 * time field. For example, to roll the current date up by one day, call
553 * roll(Calendar::DATE, +1, status). When rolling on the month or
554 * Calendar::MONTH field, other fields like date might conflict and, need to be
555 * changed. For instance, rolling the month up on the date 01/31/96 will result in
556 * 02/29/96. Rolling by a positive value always means rolling forward in time;
557 * e.g., rolling the year by +1 on "100 BC" will result in "99 BC", for Gregorian
558 * calendar. When rolling on the hour-in-day or Calendar::HOUR_OF_DAY field, it will
559 * roll the hour value in the range between 0 and 23, which is zero-based.
560 * <P>
561 * The only difference between roll() and add() is that roll() does not change
562 * the value of more significant fields when it reaches the minimum or maximum
563 * of its range, whereas add() does.
564 *
565 * @param field The time field.
566 * @param amount Indicates amount to roll.
567 * @param status Output param set to success/failure code on exit. If any value
568 * previously set in the time field is invalid, this will be set to
569 * an error status.
570 * @deprecated ICU 2.6. Use roll(UCalendarDateFields field, int32_t amount, UErrorCode& status) instead.
571 */
572 virtual void roll(EDateFields field, int32_t amount, UErrorCode& status) = 0;
573
574 /**
575 * Time Field Rolling function. Rolls by the given amount on the given
576 * time field. For example, to roll the current date up by one day, call
577 * roll(Calendar::DATE, +1, status). When rolling on the month or
578 * Calendar::MONTH field, other fields like date might conflict and, need to be
579 * changed. For instance, rolling the month up on the date 01/31/96 will result in
580 * 02/29/96. Rolling by a positive value always means rolling forward in time;
581 * e.g., rolling the year by +1 on "100 BC" will result in "99 BC", for Gregorian
582 * calendar. When rolling on the hour-in-day or Calendar::HOUR_OF_DAY field, it will
583 * roll the hour value in the range between 0 and 23, which is zero-based.
584 * <P>
585 * The only difference between roll() and add() is that roll() does not change
586 * the value of more significant fields when it reaches the minimum or maximum
587 * of its range, whereas add() does.
588 *
589 * @param field The time field.
590 * @param amount Indicates amount to roll.
591 * @param status Output param set to success/failure code on exit. If any value
592 * previously set in the time field is invalid, this will be set to
593 * an error status.
594 * @draft ICU 2.6.
595 */
596 virtual void roll(UCalendarDateFields field, int32_t amount, UErrorCode& status) = 0;
597
598 /**
599 * Return the difference between the given time and the time this
600 * calendar object is set to. If this calendar is set
601 * <em>before</em> the given time, the returned value will be
602 * positive. If this calendar is set <em>after</em> the given
603 * time, the returned value will be negative. The
604 * <code>field</code> parameter specifies the units of the return
605 * value. For example, if <code>fieldDifference(when,
606 * Calendar::MONTH)</code> returns 3, then this calendar is set to
607 * 3 months before <code>when</code>, and possibly some addition
608 * time less than one month.
609 *
610 * <p>As a side effect of this call, this calendar is advanced
611 * toward <code>when</code> by the given amount. That is, calling
612 * this method has the side effect of calling <code>add(field,
613 * n)</code>, where <code>n</code> is the return value.
614 *
615 * <p>Usage: To use this method, call it first with the largest
616 * field of interest, then with progressively smaller fields. For
617 * example:
618 *
619 * <pre>
620 * int y = cal->fieldDifference(when, Calendar::YEAR, err);
621 * int m = cal->fieldDifference(when, Calendar::MONTH, err);
622 * int d = cal->fieldDifference(when, Calendar::DATE, err);</pre>
623 *
624 * computes the difference between <code>cal</code> and
625 * <code>when</code> in years, months, and days.
626 *
627 * <p>Note: <code>fieldDifference()</code> is
628 * <em>asymmetrical</em>. That is, in the following code:
629 *
630 * <pre>
631 * cal->setTime(date1, err);
632 * int m1 = cal->fieldDifference(date2, Calendar::MONTH, err);
633 * int d1 = cal->fieldDifference(date2, Calendar::DATE, err);
634 * cal->setTime(date2, err);
635 * int m2 = cal->fieldDifference(date1, Calendar::MONTH, err);
636 * int d2 = cal->fieldDifference(date1, Calendar::DATE, err);</pre>
637 *
638 * one might expect that <code>m1 == -m2 && d1 == -d2</code>.
639 * However, this is not generally the case, because of
640 * irregularities in the underlying calendar system (e.g., the
641 * Gregorian calendar has a varying number of days per month).
642 *
643 * @param when the date to compare this calendar's time to
644 * @param field the field in which to compute the result
645 * @param status Output param set to success/failure code on exit. If any value
646 * previously set in the time field is invalid, this will be set to
647 * an error status.
648 * @return the difference, either positive or negative, between
649 * this calendar's time and <code>when</code>, in terms of
650 * <code>field</code>.
651 * @deprecated ICU 2.6. Use fieldDifference(UDate when, UCalendarDateFields field, UErrorCode& status).
652 */
653 virtual int32_t fieldDifference(UDate when, EDateFields field, UErrorCode& status);
654
655 /**
656 * Return the difference between the given time and the time this
657 * calendar object is set to. If this calendar is set
658 * <em>before</em> the given time, the returned value will be
659 * positive. If this calendar is set <em>after</em> the given
660 * time, the returned value will be negative. The
661 * <code>field</code> parameter specifies the units of the return
662 * value. For example, if <code>fieldDifference(when,
663 * Calendar::MONTH)</code> returns 3, then this calendar is set to
664 * 3 months before <code>when</code>, and possibly some addition
665 * time less than one month.
666 *
667 * <p>As a side effect of this call, this calendar is advanced
668 * toward <code>when</code> by the given amount. That is, calling
669 * this method has the side effect of calling <code>add(field,
670 * n)</code>, where <code>n</code> is the return value.
671 *
672 * <p>Usage: To use this method, call it first with the largest
673 * field of interest, then with progressively smaller fields. For
674 * example:
675 *
676 * <pre>
677 * int y = cal->fieldDifference(when, Calendar::YEAR, err);
678 * int m = cal->fieldDifference(when, Calendar::MONTH, err);
679 * int d = cal->fieldDifference(when, Calendar::DATE, err);</pre>
680 *
681 * computes the difference between <code>cal</code> and
682 * <code>when</code> in years, months, and days.
683 *
684 * <p>Note: <code>fieldDifference()</code> is
685 * <em>asymmetrical</em>. That is, in the following code:
686 *
687 * <pre>
688 * cal->setTime(date1, err);
689 * int m1 = cal->fieldDifference(date2, Calendar::MONTH, err);
690 * int d1 = cal->fieldDifference(date2, Calendar::DATE, err);
691 * cal->setTime(date2, err);
692 * int m2 = cal->fieldDifference(date1, Calendar::MONTH, err);
693 * int d2 = cal->fieldDifference(date1, Calendar::DATE, err);</pre>
694 *
695 * one might expect that <code>m1 == -m2 && d1 == -d2</code>.
696 * However, this is not generally the case, because of
697 * irregularities in the underlying calendar system (e.g., the
698 * Gregorian calendar has a varying number of days per month).
699 *
700 * @param when the date to compare this calendar's time to
701 * @param field the field in which to compute the result
702 * @param status Output param set to success/failure code on exit. If any value
703 * previously set in the time field is invalid, this will be set to
704 * an error status.
705 * @return the difference, either positive or negative, between
706 * this calendar's time and <code>when</code>, in terms of
707 * <code>field</code>.
708 * @draft ICU 2.6.
709 */
710 virtual int32_t fieldDifference(UDate when, UCalendarDateFields field, UErrorCode& status);
711
712 /**
713 * Sets the calendar's time zone to be the one passed in. The Calendar takes ownership
714 * of the TimeZone; the caller is no longer responsible for deleting it. If the
715 * given time zone is NULL, this function has no effect.
716 *
717 * @param value The given time zone.
718 * @stable ICU 2.0
719 */
720 void adoptTimeZone(TimeZone* value);
721
722 /**
723 * Sets the calendar's time zone to be the same as the one passed in. The TimeZone
724 * passed in is _not_ adopted; the client is still responsible for deleting it.
725 *
726 * @param zone The given time zone.
727 * @stable ICU 2.0
728 */
729 void setTimeZone(const TimeZone& zone);
730
731 /**
732 * Returns a reference to the time zone owned by this calendar. The returned reference
733 * is only valid until clients make another call to adoptTimeZone or setTimeZone,
734 * or this Calendar is destroyed.
735 *
736 * @return The time zone object associated with this calendar.
737 * @stable ICU 2.0
738 */
739 const TimeZone& getTimeZone(void) const;
740
741 /**
742 * Returns the time zone owned by this calendar. The caller owns the returned object
743 * and must delete it when done. After this call, the new time zone associated
744 * with this Calendar is the default TimeZone as returned by TimeZone::createDefault().
745 *
746 * @return The time zone object which was associated with this calendar.
747 * @stable ICU 2.0
748 */
749 TimeZone* orphanTimeZone(void);
750
751 /**
752 * Queries if the current date for this Calendar is in Daylight Savings Time.
753 *
754 * @param status Fill-in parameter which receives the status of this operation.
755 * @return True if the current date for this Calendar is in Daylight Savings Time,
756 * false, otherwise.
757 * @stable ICU 2.0
758 */
759 virtual UBool inDaylightTime(UErrorCode& status) const = 0;
760
761 /**
762 * Specifies whether or not date/time interpretation is to be lenient. With lenient
763 * interpretation, a date such as "February 942, 1996" will be treated as being
764 * equivalent to the 941st day after February 1, 1996. With strict interpretation,
765 * such dates will cause an error when computing time from the time field values
766 * representing the dates.
767 *
768 * @param lenient True specifies date/time interpretation to be lenient.
769 *
770 * @see DateFormat#setLenient
771 * @stable ICU 2.0
772 */
773 void setLenient(UBool lenient);
774
775 /**
776 * Tells whether date/time interpretation is to be lenient.
777 *
778 * @return True tells that date/time interpretation is to be lenient.
779 * @stable ICU 2.0
780 */
781 UBool isLenient(void) const;
782
783 /**
784 * Sets what the first day of the week is; e.g., Sunday in US, Monday in France.
785 *
786 * @param value The given first day of the week.
787 * @deprecated ICU 2.6. Use setFirstDayOfWeek(UCalendarDaysOfWeek value) instead.
788 */
789 void setFirstDayOfWeek(EDaysOfWeek value);
790
791 /**
792 * Sets what the first day of the week is; e.g., Sunday in US, Monday in France.
793 *
794 * @param value The given first day of the week.
795 * @draft ICU 2.6.
796 */
797 void setFirstDayOfWeek(UCalendarDaysOfWeek value);
798
799 /**
800 * Gets what the first day of the week is; e.g., Sunday in US, Monday in France.
801 *
802 * @return The first day of the week.
803 * @deprecated ICU 2.6 use the overload with error code
804 */
805 EDaysOfWeek getFirstDayOfWeek(void) const;
806
807 /**
808 * Gets what the first day of the week is; e.g., Sunday in US, Monday in France.
809 *
810 * @param status error code
811 * @return The first day of the week.
812 * @draft ICU 2.6
813 */
814 UCalendarDaysOfWeek getFirstDayOfWeek(UErrorCode &status) const;
815
816 /**
817 * Sets what the minimal days required in the first week of the year are; For
818 * example, if the first week is defined as one that contains the first day of the
819 * first month of a year, call the method with value 1. If it must be a full week,
820 * use value 7.
821 *
822 * @param value The given minimal days required in the first week of the year.
823 * @stable ICU 2.0
824 */
825 void setMinimalDaysInFirstWeek(uint8_t value);
826
827 /**
828 * Gets what the minimal days required in the first week of the year are; e.g., if
829 * the first week is defined as one that contains the first day of the first month
830 * of a year, getMinimalDaysInFirstWeek returns 1. If the minimal days required must
831 * be a full week, getMinimalDaysInFirstWeek returns 7.
832 *
833 * @return The minimal days required in the first week of the year.
834 * @stable ICU 2.0
835 */
836 uint8_t getMinimalDaysInFirstWeek(void) const;
837
838 /**
839 * Gets the minimum value for the given time field. e.g., for Gregorian
840 * DAY_OF_MONTH, 1.
841 *
842 * @param field The given time field.
843 * @return The minimum value for the given time field.
844 * @deprecated ICU 2.6. Use getMinimum(UCalendarDateFields field) instead.
845 */
846 virtual int32_t getMinimum(EDateFields field) const = 0;
847
848 /**
849 * Gets the minimum value for the given time field. e.g., for Gregorian
850 * DAY_OF_MONTH, 1.
851 *
852 * @param field The given time field.
853 * @return The minimum value for the given time field.
854 * @draft ICU 2.6.
855 */
856 virtual int32_t getMinimum(UCalendarDateFields field) const = 0;
857
858 /**
859 * Gets the maximum value for the given time field. e.g. for Gregorian DAY_OF_MONTH,
860 * 31.
861 *
862 * @param field The given time field.
863 * @return The maximum value for the given time field.
864 * @deprecated ICU 2.6. Use getMaximum(UCalendarDateFields field) instead.
865 */
866 virtual int32_t getMaximum(EDateFields field) const = 0;
867
868 /**
869 * Gets the maximum value for the given time field. e.g. for Gregorian DAY_OF_MONTH,
870 * 31.
871 *
872 * @param field The given time field.
873 * @return The maximum value for the given time field.
874 * @draft ICU 2.6.
875 */
876 virtual int32_t getMaximum(UCalendarDateFields field) const = 0;
877
878 /**
879 * Gets the highest minimum value for the given field if varies. Otherwise same as
880 * getMinimum(). For Gregorian, no difference.
881 *
882 * @param field The given time field.
883 * @return The highest minimum value for the given time field.
884 * @deprecated ICU 2.6. Use getGreatestMinimum(UCalendarDateFields field) instead.
885 */
886 virtual int32_t getGreatestMinimum(EDateFields field) const = 0;
887
888 /**
889 * Gets the highest minimum value for the given field if varies. Otherwise same as
890 * getMinimum(). For Gregorian, no difference.
891 *
892 * @param field The given time field.
893 * @return The highest minimum value for the given time field.
894 * @draft ICU 2.6.
895 */
896 virtual int32_t getGreatestMinimum(UCalendarDateFields field) const = 0;
897
898 /**
899 * Gets the lowest maximum value for the given field if varies. Otherwise same as
900 * getMaximum(). e.g., for Gregorian DAY_OF_MONTH, 28.
901 *
902 * @param field The given time field.
903 * @return The lowest maximum value for the given time field.
904 * @deprecated ICU 2.6. Use getLeastMaximum(UCalendarDateFields field) instead.
905 */
906 virtual int32_t getLeastMaximum(EDateFields field) const = 0;
907
908 /**
909 * Gets the lowest maximum value for the given field if varies. Otherwise same as
910 * getMaximum(). e.g., for Gregorian DAY_OF_MONTH, 28.
911 *
912 * @param field The given time field.
913 * @return The lowest maximum value for the given time field.
914 * @draft ICU 2.6.
915 */
916 virtual int32_t getLeastMaximum(UCalendarDateFields field) const = 0;
917
918 /**
919 * Return the minimum value that this field could have, given the current date.
920 * For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum().
921 *
922 * The version of this function on Calendar uses an iterative algorithm to determine the
923 * actual minimum value for the field. There is almost always a more efficient way to
924 * accomplish this (in most cases, you can simply return getMinimum()). GregorianCalendar
925 * overrides this function with a more efficient implementation.
926 *
927 * @param field the field to determine the minimum of
928 * @param status Fill-in parameter which receives the status of this operation.
929 * @return the minimum of the given field for the current date of this Calendar
930 * @deprecated ICU 2.6. Use getActualMinimum(UCalendarDateFields field, UErrorCode& status) instead.
931 */
932 int32_t getActualMinimum(EDateFields field, UErrorCode& status) const;
933
934 /**
935 * Return the minimum value that this field could have, given the current date.
936 * For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum().
937 *
938 * The version of this function on Calendar uses an iterative algorithm to determine the
939 * actual minimum value for the field. There is almost always a more efficient way to
940 * accomplish this (in most cases, you can simply return getMinimum()). GregorianCalendar
941 * overrides this function with a more efficient implementation.
942 *
943 * @param field the field to determine the minimum of
944 * @param status Fill-in parameter which receives the status of this operation.
945 * @return the minimum of the given field for the current date of this Calendar
946 * @draft ICU 2.6.
947 */
948 int32_t getActualMinimum(UCalendarDateFields field, UErrorCode& status) const;
949
950 /**
951 * Return the maximum value that this field could have, given the current date.
952 * For example, with the date "Feb 3, 1997" and the DAY_OF_MONTH field, the actual
953 * maximum would be 28; for "Feb 3, 1996" it s 29. Similarly for a Hebrew calendar,
954 * for some years the actual maximum for MONTH is 12, and for others 13.
955 *
956 * The version of this function on Calendar uses an iterative algorithm to determine the
957 * actual maximum value for the field. There is almost always a more efficient way to
958 * accomplish this (in most cases, you can simply return getMaximum()). GregorianCalendar
959 * overrides this function with a more efficient implementation.
960 *
961 * @param field the field to determine the maximum of
962 * @param status Fill-in parameter which receives the status of this operation.
963 * @return the maximum of the given field for the current date of this Calendar
964 * @deprecated ICU 2.6. Use getActualMaximum(UCalendarDateFields field, UErrorCode& status) instead.
965 */
966 int32_t getActualMaximum(EDateFields field, UErrorCode& status) const;
967
968 /**
969 * Return the maximum value that this field could have, given the current date.
970 * For example, with the date "Feb 3, 1997" and the DAY_OF_MONTH field, the actual
971 * maximum would be 28; for "Feb 3, 1996" it s 29. Similarly for a Hebrew calendar,
972 * for some years the actual maximum for MONTH is 12, and for others 13.
973 *
974 * The version of this function on Calendar uses an iterative algorithm to determine the
975 * actual maximum value for the field. There is almost always a more efficient way to
976 * accomplish this (in most cases, you can simply return getMaximum()). GregorianCalendar
977 * overrides this function with a more efficient implementation.
978 *
979 * @param field the field to determine the maximum of
980 * @param status Fill-in parameter which receives the status of this operation.
981 * @return the maximum of the given field for the current date of this Calendar
982 * @draft ICU 2.6.
983 */
984 int32_t getActualMaximum(UCalendarDateFields field, UErrorCode& status) const;
985
986 /**
987 * Gets the value for a given time field. Recalculate the current time field values
988 * if the time value has been changed by a call to setTime(). Return zero for unset
989 * fields if any fields have been explicitly set by a call to set(). To force a
990 * recomputation of all fields regardless of the previous state, call complete().
991 * This method is semantically const, but may alter the object in memory.
992 *
993 * @param field The given time field.
994 * @param status Fill-in parameter which receives the status of the operation.
995 * @return The value for the given time field, or zero if the field is unset,
996 * and set() has been called for any other field.
997 * @deprecated ICU 2.6. Use get(UCalendarDateFields field, UErrorCode& status) instead.
998 */
999 int32_t get(EDateFields field, UErrorCode& status) const;
1000
1001 /**
1002 * Gets the value for a given time field. Recalculate the current time field values
1003 * if the time value has been changed by a call to setTime(). Return zero for unset
1004 * fields if any fields have been explicitly set by a call to set(). To force a
1005 * recomputation of all fields regardless of the previous state, call complete().
1006 * This method is semantically const, but may alter the object in memory.
1007 *
1008 * @param field The given time field.
1009 * @param status Fill-in parameter which receives the status of the operation.
1010 * @return The value for the given time field, or zero if the field is unset,
1011 * and set() has been called for any other field.
1012 * @draft ICU 2.6.
1013 */
1014 int32_t get(UCalendarDateFields field, UErrorCode& status) const;
1015
1016 /**
1017 * Determines if the given time field has a value set. This can affect in the
1018 * resolving of time in Calendar. Unset fields have a value of zero, by definition.
1019 *
1020 * @param field The given time field.
1021 * @return True if the given time field has a value set; false otherwise.
1022 * @deprecated ICU 2.6. Use isSet(UCalendarDateFields field) instead.
1023 */
1024 UBool isSet(EDateFields field) const;
1025
1026 /**
1027 * Determines if the given time field has a value set. This can affect in the
1028 * resolving of time in Calendar. Unset fields have a value of zero, by definition.
1029 *
1030 * @param field The given time field.
1031 * @return True if the given time field has a value set; false otherwise.
1032 * @draft ICU 2.6.
1033 */
1034 UBool isSet(UCalendarDateFields field) const;
1035
1036 /**
1037 * Sets the given time field with the given value.
1038 *
1039 * @param field The given time field.
1040 * @param value The value to be set for the given time field.
1041 * @deprecated ICU 2.6. Use set(UCalendarDateFields field, int32_t value) instead.
1042 */
1043 void set(EDateFields field, int32_t value);
1044
1045 /**
1046 * Sets the given time field with the given value.
1047 *
1048 * @param field The given time field.
1049 * @param value The value to be set for the given time field.
1050 * @draft ICU 2.6.
1051 */
1052 void set(UCalendarDateFields field, int32_t value);
1053
1054 /**
1055 * Sets the values for the fields YEAR, MONTH, and DATE. Other field values are
1056 * retained; call clear() first if this is not desired.
1057 *
1058 * @param year The value used to set the YEAR time field.
1059 * @param month The value used to set the MONTH time field. Month value is 0-based.
1060 * e.g., 0 for January.
1061 * @param date The value used to set the DATE time field.
1062 * @stable ICU 2.0
1063 */
1064 void set(int32_t year, int32_t month, int32_t date);
1065
1066 /**
1067 * Sets the values for the fields YEAR, MONTH, DATE, HOUR_OF_DAY, and MINUTE. Other
1068 * field values are retained; call clear() first if this is not desired.
1069 *
1070 * @param year The value used to set the YEAR time field.
1071 * @param month The value used to set the MONTH time field. Month value is
1072 * 0-based. E.g., 0 for January.
1073 * @param date The value used to set the DATE time field.
1074 * @param hour The value used to set the HOUR_OF_DAY time field.
1075 * @param minute The value used to set the MINUTE time field.
1076 * @stable ICU 2.0
1077 */
1078 void set(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute);
1079
1080 /**
1081 * Sets the values for the fields YEAR, MONTH, DATE, HOUR_OF_DAY, MINUTE, and SECOND.
1082 * Other field values are retained; call clear() first if this is not desired.
1083 *
1084 * @param year The value used to set the YEAR time field.
1085 * @param month The value used to set the MONTH time field. Month value is
1086 * 0-based. E.g., 0 for January.
1087 * @param date The value used to set the DATE time field.
1088 * @param hour The value used to set the HOUR_OF_DAY time field.
1089 * @param minute The value used to set the MINUTE time field.
1090 * @param second The value used to set the SECOND time field.
1091 * @stable ICU 2.0
1092 */
1093 void set(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, int32_t second);
1094
1095 /**
1096 * Clears the values of all the time fields, making them both unset and assigning
1097 * them a value of zero. The field values will be determined during the next
1098 * resolving of time into time fields.
1099 * @stable ICU 2.0
1100 */
1101 void clear(void);
1102
1103 /**
1104 * Clears the value in the given time field, both making it unset and assigning it a
1105 * value of zero. This field value will be determined during the next resolving of
1106 * time into time fields.
1107 *
1108 * @param field The time field to be cleared.
1109 * @deprecated ICU 2.6. Use clear(UCalendarDateFields field) instead.
1110 */
1111 void clear(EDateFields field);
1112
1113 /**
1114 * Clears the value in the given time field, both making it unset and assigning it a
1115 * value of zero. This field value will be determined during the next resolving of
1116 * time into time fields.
1117 *
1118 * @param field The time field to be cleared.
1119 * @draft ICU 2.6.
1120 */
1121 void clear(UCalendarDateFields field);
1122
1123 /**
1124 * Returns a unique class ID POLYMORPHICALLY. Pure virtual method. This method is to
1125 * implement a simple version of RTTI, since not all C++ compilers support genuine
1126 * RTTI. Polymorphic operator==() and clone() methods call this method.
1127 * <P>
1128 * Concrete subclasses of Calendar must implement getDynamicClassID() and also a
1129 * static method and data member:
1130 *
1131 * static UClassID getStaticClassID() { return (UClassID)&fgClassID; }
1132 * static char fgClassID;
1133 *
1134 * @return The class ID for this object. All objects of a given class have the
1135 * same class ID. Objects of other classes have different class IDs.
1136 * @stable ICU 2.0
1137 */
1138 virtual UClassID getDynamicClassID(void) const = 0;
1139
1140 /**
1141 * Returns the resource key string used for this calendar type.
1142 * For example, prepending "Eras_" to this string could return "Eras_japanese"
1143 * or "Eras_gregorian".
1144 *
1145 * @returns static string, for example, "gregorian" or "japanese"
1146 * @internal
1147 */
1148 virtual const char * getType() const = 0;
1149
1150 protected:
1151
1152 /**
1153 * Constructs a Calendar with the default time zone as returned by
1154 * TimeZone::createInstance(), and the default locale.
1155 *
1156 * @param success Indicates the status of Calendar object construction. Returns
1157 * U_ZERO_ERROR if constructed successfully.
1158 * @stable ICU 2.0
1159 */
1160 Calendar(UErrorCode& success);
1161
1162 /**
1163 * Copy constructor
1164 *
1165 * @param source Calendar object to be copied from
1166 * @stable ICU 2.0
1167 */
1168 Calendar(const Calendar& source);
1169
1170 /**
1171 * Default assignment operator
1172 *
1173 * @param right Calendar object to be copied
1174 * @stable ICU 2.0
1175 */
1176 Calendar& operator=(const Calendar& right);
1177
1178 /**
1179 * Constructs a Calendar with the given time zone and locale. Clients are no longer
1180 * responsible for deleting the given time zone object after it's adopted.
1181 *
1182 * @param zone The given time zone.
1183 * @param aLocale The given locale.
1184 * @param success Indicates the status of Calendar object construction. Returns
1185 * U_ZERO_ERROR if constructed successfully.
1186 * @stable ICU 2.0
1187 */
1188 Calendar(TimeZone* zone, const Locale& aLocale, UErrorCode& success);
1189
1190 /**
1191 * Constructs a Calendar with the given time zone and locale.
1192 *
1193 * @param zone The given time zone.
1194 * @param aLocale The given locale.
1195 * @param success Indicates the status of Calendar object construction. Returns
1196 * U_ZERO_ERROR if constructed successfully.
1197 * @stable ICU 2.0
1198 */
1199 Calendar(const TimeZone& zone, const Locale& aLocale, UErrorCode& success);
1200
1201 /**
1202 * Converts Calendar's time field values to GMT as milliseconds.
1203 *
1204 * @param status Output param set to success/failure code on exit. If any value
1205 * previously set in the time field is invalid or restricted by
1206 * leniency, this will be set to an error status.
1207 * @stable ICU 2.0
1208 */
1209 virtual void computeTime(UErrorCode& status) = 0;
1210
1211 /**
1212 * Converts GMT as milliseconds to time field values. This allows you to sync up the
1213 * time field values with a new time that is set for the calendar. This method
1214 * does NOT recompute the time first; to recompute the time, then the fields, use
1215 * the method complete().
1216 *
1217 * @param status Output param set to success/failure code on exit. If any value
1218 * previously set in the time field is invalid or restricted by
1219 * leniency, this will be set to an error status.
1220 * @stable ICU 2.0
1221 */
1222 virtual void computeFields(UErrorCode& status) = 0;
1223
1224 /**
1225 * Gets this Calendar's current time as a long.
1226 *
1227 * @param status Output param set to success/failure code on exit. If any value
1228 * previously set in the time field is invalid or restricted by
1229 * leniency, this will be set to an error status.
1230 * @return the current time as UTC milliseconds from the epoch.
1231 * @stable ICU 2.0
1232 */
1233 double getTimeInMillis(UErrorCode& status) const;
1234
1235 /**
1236 * Sets this Calendar's current time from the given long value.
1237 * @param millis the new time in UTC milliseconds from the epoch.
1238 * @param status Output param set to success/failure code on exit. If any value
1239 * previously set in the time field is invalid or restricted by
1240 * leniency, this will be set to an error status.
1241 * @stable ICU 2.0
1242 */
1243 void setTimeInMillis( double millis, UErrorCode& status );
1244
1245 /**
1246 * Recomputes the current time from currently set fields, and then fills in any
1247 * unset fields in the time field list.
1248 *
1249 * @param status Output param set to success/failure code on exit. If any value
1250 * previously set in the time field is invalid or restricted by
1251 * leniency, this will be set to an error status.
1252 * @stable ICU 2.0
1253 */
1254 void complete(UErrorCode& status);
1255
1256 /**
1257 * Gets the value for a given time field. Subclasses can use this function to get
1258 * field values without forcing recomputation of time.
1259 *
1260 * @param field The given time field.
1261 * @return The value for the given time field.
1262 * @deprecated ICU 2.6. Use internalGet(UCalendarDateFields field) instead.
1263 */
1264 inline int32_t internalGet(EDateFields field) const {return fFields[field];}
1265
1266 /**
1267 * Gets the value for a given time field. Subclasses can use this function to get
1268 * field values without forcing recomputation of time.
1269 *
1270 * @param field The given time field.
1271 * @return The value for the given time field.
1272 * @draft ICU 2.6.
1273 */
1274 inline int32_t internalGet(UCalendarDateFields field) const {return fFields[field];}
1275
1276 /**
1277 * Sets the value for a given time field. This is a fast internal method for
1278 * subclasses. It does not affect the areFieldsInSync, isTimeSet, or areAllFieldsSet
1279 * flags.
1280 *
1281 * @param field The given time field.
1282 * @param value The value for the given time field.
1283 * @deprecated ICU 2.6. Use internalSet(UCalendarDateFields field, int32_t value) instead.
1284 */
1285 void internalSet(EDateFields field, int32_t value);
1286
1287 /**
1288 * Sets the value for a given time field. This is a fast internal method for
1289 * subclasses. It does not affect the areFieldsInSync, isTimeSet, or areAllFieldsSet
1290 * flags.
1291 *
1292 * @param field The given time field.
1293 * @param value The value for the given time field.
1294 * @draft ICU 2.6.
1295 */
1296 inline void internalSet(UCalendarDateFields field, int32_t value);
1297
1298 protected:
1299 /**
1300 * The flag which indicates if the current time is set in the calendar.
1301 * @stable ICU 2.0
1302 */
1303 UBool fIsTimeSet;
1304
1305 /**
1306 * True if the fields are in sync with the currently set time of this Calendar.
1307 * If false, then the next attempt to get the value of a field will
1308 * force a recomputation of all fields from the current value of the time
1309 * field.
1310 * <P>
1311 * This should really be named areFieldsInSync, but the old name is retained
1312 * for backward compatibility.
1313 * @stable ICU 2.0
1314 */
1315 UBool fAreFieldsSet;
1316
1317 /**
1318 * True if all of the fields have been set. This is initially false, and set to
1319 * true by computeFields().
1320 * @stable ICU 2.0
1321 */
1322 UBool fAreAllFieldsSet;
1323
1324 /**
1325 * Get the current time without recomputing.
1326 *
1327 * @return the current time without recomputing.
1328 * @stable ICU 2.0
1329 */
1330 UDate internalGetTime(void) const { return fTime; }
1331
1332 /**
1333 * Set the current time without affecting flags or fields.
1334 *
1335 * @param time The time to be set
1336 * @return the current time without recomputing.
1337 * @stable ICU 2.0
1338 */
1339 void internalSetTime(UDate time) { fTime = time; }
1340
1341 /**
1342 * The time fields containing values into which the millis is computed.
1343 * @stable ICU 2.0
1344 */
1345 int32_t fFields[UCAL_FIELD_COUNT];
1346
1347 /**
1348 * The flags which tell if a specified time field for the calendar is set.
1349 * @stable ICU 2.0
1350 */
1351 UBool fIsSet[UCAL_FIELD_COUNT];
1352
1353 /** Special values of stamp[]
1354 * @stable ICU 2.0
1355 */
1356 enum {
1357 kUnset = 0,
1358 kInternallySet,
1359 kMinimumUserStamp
1360 };
1361
1362 /**
1363 * Pseudo-time-stamps which specify when each field was set. There
1364 * are two special values, UNSET and INTERNALLY_SET. Values from
1365 * MINIMUM_USER_SET to Integer.MAX_VALUE are legal user set values.
1366 * @stable ICU 2.0
1367 */
1368 int32_t fStamp[UCAL_FIELD_COUNT];
1369
1370 private:
1371
1372 // The next available value for stampp[]
1373 int32_t fNextStamp;// = MINIMUM_USER_STAMP;
1374
1375 /**
1376 * The current time set for the calendar.
1377 */
1378 UDate fTime;
1379
1380 /**
1381 * @see #setLenient
1382 */
1383 UBool fLenient;
1384
1385 /**
1386 * Time zone affects the time calculation done by Calendar. Calendar subclasses use
1387 * the time zone data to produce the local time.
1388 */
1389 TimeZone* fZone;
1390
1391 /**
1392 * Both firstDayOfWeek and minimalDaysInFirstWeek are locale-dependent. They are
1393 * used to figure out the week count for a specific date for a given locale. These
1394 * must be set when a Calendar is constructed. For example, in US locale,
1395 * firstDayOfWeek is SUNDAY; minimalDaysInFirstWeek is 1. They are used to figure
1396 * out the week count for a specific date for a given locale. These must be set when
1397 * a Calendar is constructed.
1398 */
1399 UCalendarDaysOfWeek fFirstDayOfWeek;
1400 uint8_t fMinimalDaysInFirstWeek;
1401
1402 /**
1403 * Sets firstDayOfWeek and minimalDaysInFirstWeek. Called at Calendar construction
1404 * time.
1405 *
1406 * @param desiredLocale The given locale.
1407 * @param success Indicates the status of setting the week count data from
1408 * the resource for the given locale. Returns U_ZERO_ERROR if
1409 * constructed successfully.
1410 */
1411 void setWeekCountData(const Locale& desiredLocale, UErrorCode& success);
1412
1413 /**
1414 * Recompute the time and update the status fields isTimeSet
1415 * and areFieldsSet. Callers should check isTimeSet and only
1416 * call this method if isTimeSet is false.
1417 *
1418 * @param status Output param set to success/failure code on exit. If any value
1419 * previously set in the time field is invalid or restricted by
1420 * leniency, this will be set to an error status.
1421 */
1422 void updateTime(UErrorCode& status);
1423
1424 /**
1425 * The resource tag for the resource where the week-count data is stored.
1426 */
1427 static const char kDateTimeElements[];
1428
1429 /**
1430 * The resource tag where the default calendar is stored.
1431 */
1432 static const char kDefaultCalendar[];
1433
1434 public:
1435 /**
1436 * INTERNAL FOR 2.6 -- Registration.
1437 */
1438
1439 /**
1440 * Return a StringEnumeration over the locales available at the time of the call,
1441 * including registered locales.
1442 * @return a StringEnumeration over the locales available at the time of the call
1443 * @internal
1444 */
1445 static StringEnumeration* getAvailableLocales(void);
1446
1447 /**
1448 * Register a new Calendar factory. The factory will be adopted.
1449 * INTERNAL in 2.6
1450 * @param toAdopt the factory instance to be adopted
1451 * @param status the in/out status code, no special meanings are assigned
1452 * @return a registry key that can be used to unregister this factory
1453 * @internal
1454 */
1455 static URegistryKey registerFactory(ICUServiceFactory* toAdopt, UErrorCode& status);
1456
1457 /**
1458 * Unregister a previously-registered CalendarFactory using the key returned from the
1459 * register call. Key becomes invalid after a successful call and should not be used again.
1460 * The CalendarFactory corresponding to the key will be deleted.
1461 * INTERNAL in 2.6
1462 * @param key the registry key returned by a previous call to registerFactory
1463 * @param status the in/out status code, no special meanings are assigned
1464 * @return TRUE if the factory for the key was successfully unregistered
1465 * @internal
1466 */
1467 static UBool unregister(URegistryKey key, UErrorCode& status);
1468
1469 /**
1470 * Multiple Calendar Implementation
1471 * @internal
1472 */
1473 friend class CalendarFactory;
1474
1475 /**
1476 * Multiple Calendar Implementation
1477 * @internal
1478 */
1479 friend class CalendarService;
1480
1481 /**
1482 * Multiple Calendar Implementation
1483 * @internal
1484 */
1485 friend class DefaultCalendarFactory;
1486
1487 /**
1488 * @internal
1489 * @return TRUE if this calendar has a default century (i.e. 03 -> 2003)
1490 */
1491 virtual UBool haveDefaultCentury() const = 0;
1492
1493 /**
1494 * @internal
1495 * @return the start of the default century, as a UDate
1496 */
1497 virtual UDate defaultCenturyStart() const = 0;
1498 /**
1499 * @internal
1500 * @return the beginning year of the default century, as a year
1501 */
1502 virtual int32_t defaultCenturyStartYear() const = 0;
1503
1504 };
1505
1506 // -------------------------------------
1507
1508 inline Calendar*
1509 Calendar::createInstance(TimeZone* zone, UErrorCode& errorCode)
1510 {
1511 // since the Locale isn't specified, use the default locale
1512 return createInstance(zone, Locale::getDefault(), errorCode);
1513 }
1514
1515 // -------------------------------------
1516
1517 inline void
1518 Calendar::roll(UCalendarDateFields field, UBool up, UErrorCode& status)
1519 {
1520 roll(field, (int32_t)(up ? +1 : -1), status);
1521 }
1522
1523 inline void
1524 Calendar::roll(EDateFields field, UBool up, UErrorCode& status)
1525 {
1526 roll((UCalendarDateFields) field, up, status);
1527 }
1528
1529 // -------------------------------------
1530
1531 /**
1532 * Fast method for subclasses. The caller must maintain fUserSetDSTOffset and
1533 * fUserSetZoneOffset, as well as the isSet[] array.
1534 */
1535
1536 inline void
1537 Calendar::internalSet(UCalendarDateFields field, int32_t value)
1538 {
1539 fFields[field] = value;
1540 }
1541
1542 inline void
1543 Calendar::internalSet(EDateFields field, int32_t value)
1544 {
1545 internalSet((UCalendarDateFields) field, value);
1546 }
1547
1548 U_NAMESPACE_END
1549
1550 #endif /* #if !UCONFIG_NO_FORMATTING */
1551
1552 #endif // _CALENDAR