2
********************************************************************************
3
* Copyright (C) 1997-1999, 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
********************************************************************************
26
#include "unicode/locid.h"
27
#include "unicode/timezone.h"
32
* <code>Calendar</code> is an abstract base class for converting between
33
* a <code>UDate</code> object and a set of integer fields such as
34
* <code>YEAR</code>, <code>MONTH</code>, <code>DAY</code>, <code>HOUR</code>,
35
* and so on. (A <code>UDate</code> object represents a specific instant in
36
* time with millisecond precision. See
38
* for information about the <code>UDate</code> class.)
41
* Subclasses of <code>Calendar</code> interpret a <code>UDate</code>
42
* according to the rules of a specific calendar system. The JDK
43
* provides one concrete subclass of <code>Calendar</code>:
44
* <code>GregorianCalendar</code>. Future subclasses could represent
45
* the various types of lunar calendars in use in many parts of the world.
48
* Like other locale-sensitive classes, <code>Calendar</code> provides a
49
* class method, <code>getInstance</code>, for getting a generally useful
50
* object of this type. <code>Calendar</code>'s <code>getInstance</code> method
51
* returns a <code>GregorianCalendar</code> object whose
52
* time fields have been initialized with the current date and time:
55
* Calendar rightNow = Calendar.getInstance();
60
* A <code>Calendar</code> object can produce all the time field values
61
* needed to implement the date-time formatting for a particular language
62
* and calendar style (for example, Japanese-Gregorian, Japanese-Traditional).
65
* When computing a <code>UDate</code> from time fields, two special circumstances
66
* may arise: there may be insufficient information to compute the
67
* <code>UDate</code> (such as only year and month but no day in the month),
68
* or there may be inconsistent information (such as "Tuesday, July 15, 1996"
69
* -- July 15, 1996 is actually a Monday).
72
* <strong>Insufficient information.</strong> The calendar will use default
73
* information to specify the missing fields. This may vary by calendar; for
74
* the Gregorian calendar, the default for a field is the same as that of the
75
* start of the epoch: i.e., YEAR = 1970, MONTH = JANUARY, DATE = 1, etc.
78
* <strong>Inconsistent information.</strong> If fields conflict, the calendar
79
* will give preference to fields set more recently. For example, when
80
* determining the day, the calendar will look for one of the following
81
* combinations of fields. The most recent combination, as determined by the
82
* most recently set single field, will be used.
86
* MONTH + DAY_OF_MONTH
87
* MONTH + WEEK_OF_MONTH + DAY_OF_WEEK
88
* MONTH + DAY_OF_WEEK_IN_MONTH + DAY_OF_WEEK
90
* DAY_OF_WEEK + WEEK_OF_YEAR
94
* For the time of day:
104
* <strong>Note:</strong> for some non-Gregorian calendars, different
105
* fields may be necessary for complete disambiguation. For example, a full
106
* specification of the historial Arabic astronomical calendar requires year,
107
* month, day-of-month <em>and</em> day-of-week in some cases.
110
* <strong>Note:</strong> There are certain possible ambiguities in
111
* interpretation of certain singular times, which are resolved in the
114
* <li> 24:00:00 "belongs" to the following day. That is,
115
* 23:59 on Dec 31, 1969 < 24:00 on Jan 1, 1970 < 24:01:00 on Jan 1, 1970
117
* <li> Although historically not precise, midnight also belongs to "am",
118
* and noon belongs to "pm", so on the same day,
119
* 12:00 am (midnight) < 12:01 am, and 12:00 pm (noon) < 12:01 pm
123
* The date or time format strings are not part of the definition of a
124
* calendar, as those must be modifiable or overridable by the user at
125
* runtime. Use {@link DateFormat}
129
* <code>Calendar</code> provides an API for field "rolling", where fields
130
* can be incremented or decremented, but wrap around. For example, rolling the
131
* month up in the date <code>December 12, <b>1996</b></code> results in
132
* <code>January 12, <b>1996</b></code>.
135
* <code>Calendar</code> also provides a date arithmetic function for
136
* adding the specified (signed) amount of time to a particular time field.
137
* For example, subtracting 5 days from the date <code>September 12, 1996</code>
138
* results in <code>September 7, 1996</code>.
142
class U_I18N_API Calendar {
146
* Field IDs for date and time. Used to specify date/time fields. ERA is calendar
147
* specific. Example ranges given are for illustration only; see specific Calendar
148
* subclasses for actual ranges.
152
ERA, // Example: 0..1
153
YEAR, // Example: 1..big number
154
MONTH, // Example: 0..11
155
WEEK_OF_YEAR, // Example: 1..53
156
WEEK_OF_MONTH, // Example: 1..4
157
DATE, // Example: 1..31
158
DAY_OF_YEAR, // Example: 1..365
159
DAY_OF_WEEK, // Example: 1..7
160
DAY_OF_WEEK_IN_MONTH, // Example: 1..4, may be specified as -1
161
AM_PM, // Example: 0..1
162
HOUR, // Example: 0..11
163
HOUR_OF_DAY, // Example: 0..23
164
MINUTE, // Example: 0..59
165
SECOND, // Example: 0..59
166
MILLISECOND, // Example: 0..999
167
ZONE_OFFSET, // Example: -12*U_MILLIS_PER_HOUR..12*U_MILLIS_PER_HOUR
168
DST_OFFSET, // Example: 0 or U_MILLIS_PER_HOUR
169
// here will go names for 'Y' and 'e'
170
YEAR_WOY, // 'Y' Example: 1..big number
171
DOW_LOCAL, // 'e' Example: 1..7
174
DAY_OF_MONTH = DATE // Synonyms
178
* Useful constant for days of week. Note: Calendar day-of-week is 1-based. Clients
179
* who create locale resources for the field of first-day-of-week should be aware of
180
* this. For instance, in US locale, first-day-of-week is set to 1, i.e., SUNDAY.
194
* Useful constants for month. Note: Calendar month is 0-based.
214
* Useful constants for hour in 12-hour clock. Used in GregorianCalendar.
229
* Create and return a polymorphic copy of this calendar.
232
virtual Calendar* clone(void) const = 0;
235
* Creates a Calendar using the default timezone and locale. Clients are responsible
236
* for deleting the object returned.
238
* @param success Indicates the success/failure of Calendar creation. Filled in
239
* with U_ZERO_ERROR if created successfully, set to a failure result
241
* @return A Calendar if created successfully. NULL otherwise.
244
static Calendar* createInstance(UErrorCode& success);
247
* Creates a Calendar using the given timezone and the default locale.
248
* The Calendar takes ownership of zoneToAdopt; the
249
* client must not delete it.
251
* @param zoneToAdopt The given timezone to be adopted.
252
* @param success Indicates the success/failure of Calendar creation. Filled in
253
* with U_ZERO_ERROR if created successfully, set to a failure result
255
* @return A Calendar if created successfully. NULL otherwise.
258
static Calendar* createInstance(TimeZone* zoneToAdopt, UErrorCode& success);
261
* Creates a Calendar using the given timezone and the default locale. The TimeZone
262
* is _not_ adopted; the client is still responsible for deleting it.
264
* @param zone The timezone.
265
* @param success Indicates the success/failure of Calendar creation. Filled in
266
* with U_ZERO_ERROR if created successfully, set to a failure result
268
* @return A Calendar if created successfully. NULL otherwise.
271
static Calendar* createInstance(const TimeZone& zone, UErrorCode& success);
274
* Creates a Calendar using the default timezone and the given locale.
276
* @param aLocale The given locale.
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
280
* @return A Calendar if created successfully. NULL otherwise.
283
static Calendar* createInstance(const Locale& aLocale, UErrorCode& success);
286
* Creates a Calendar using the given timezone and given locale.
287
* The Calendar takes ownership of zoneToAdopt; the
288
* client must not delete it.
290
* @param zoneToAdopt The given timezone to be adopted.
291
* @param aLocale The given locale.
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* createInstance(TimeZone* zoneToAdopt, const Locale& aLocale, UErrorCode& success);
301
* Gets a Calendar using the given timezone and given locale. The TimeZone
302
* is _not_ adopted; the client is still responsible for deleting it.
304
* @param zone The timezone.
305
* @param aLocale The given locale.
306
* @param success Indicates the success/failure of Calendar creation. Filled in
307
* with U_ZERO_ERROR if created successfully, set to a failure result
309
* @return A Calendar if created successfully. NULL otherwise.
312
static Calendar* createInstance(const TimeZone& zoneToAdopt, const Locale& aLocale, UErrorCode& success);
315
* Returns a list of the locales for which Calendars are installed.
317
* @param count Number of locales returned.
318
* @return An array of Locale objects representing the set of locales for which
319
* Calendars are installed. The system retains ownership of this list;
320
* the caller must NOT delete it.
323
static const Locale* getAvailableLocales(int32_t& count);
326
* Returns the current UTC (GMT) time measured in milliseconds since 0:00:00 on 1/1/70
327
* (derived from the system time).
329
* @return The current UTC time in milliseconds.
332
static UDate getNow(void);
335
* Gets this Calendar's time as milliseconds. May involve recalculation of time due
336
* to previous calls to set time field values. The time specified is non-local UTC
337
* (GMT) time. Although this method is const, this object may actually be changed
338
* (semantically const).
340
* @param status Output param set to success/failure code on exit. If any value
341
* previously set in the time field is invalid or restricted by
342
* leniency, this will be set to an error status.
343
* @return The current time in UTC (GMT) time, or zero if the operation
347
inline UDate getTime(UErrorCode& status) const { return getTimeInMillis(status); }
350
* Sets this Calendar's current time with the given UDate. The time specified should
351
* be in non-local UTC (GMT) time.
353
* @param date The given UDate in UTC (GMT) time.
356
inline void setTime(UDate date, UErrorCode& status) { setTimeInMillis(date, status); }
359
* Compares the equality of two Calendar objects. Objects of different subclasses
360
* are considered unequal. This comparison is very exacting; two Calendar objects
361
* must be in exactly the same state to be considered equal. To compare based on the
362
* represented time, use equals() instead.
364
* @param that The Calendar object to be compared with.
365
* @return True if the given Calendar is the same as this Calendar; false
369
virtual UBool operator==(const Calendar& that) const;
372
* Compares the inequality of two Calendar objects.
374
* @param that The Calendar object to be compared with.
375
* @return True if the given Calendar is not the same as this Calendar; false
379
UBool operator!=(const Calendar& that) const {return !operator==(that);}
382
* Compares the Calendar time, whereas Calendar::operator== compares the equality of
385
* @param when The Calendar to be compared with this Calendar. Although this is a
386
* const parameter, the object may be modified physically
387
* (semantically const).
388
* @param status Output param set to success/failure code on exit. If any value
389
* previously set in the time field is invalid or restricted by
390
* leniency, this will be set to an error status.
391
* @return True if the current time of this Calendar is equal to the time of
392
* Calendar when; false otherwise.
395
UBool equals(const Calendar& when, UErrorCode& status) const;
398
* Returns true if this Calendar's current time is before "when"'s current time.
400
* @param when The Calendar to be compared with this Calendar. Although this is a
401
* const parameter, the object may be modified physically
402
* (semantically const).
403
* @param status Output param set to success/failure code on exit. If any value
404
* previously set in the time field is invalid or restricted by
405
* leniency, this will be set to an error status.
406
* @return True if the current time of this Calendar is before the time of
407
* Calendar when; false otherwise.
410
UBool before(const Calendar& when, UErrorCode& status) const;
413
* Returns true if this Calendar's current time is after "when"'s current time.
415
* @param when The Calendar to be compared with this Calendar. Although this is a
416
* const parameter, the object may be modified physically
417
* (semantically const).
418
* @param status Output param set to success/failure code on exit. If any value
419
* previously set in the time field is invalid or restricted by
420
* leniency, this will be set to an error status.
421
* @return True if the current time of this Calendar is after the time of
422
* Calendar when; false otherwise.
425
UBool after(const Calendar& when, UErrorCode& status) const;
428
* Return true if another Calendar object is equivalent to this one. An equivalent
429
* Calendar will behave exactly as this one does, but may be set to a different time.
430
* @deprecated not in Java API!
432
virtual UBool equivalentTo(const Calendar& other) const;
435
* UDate Arithmetic function. Adds the specified (signed) amount of time to the given
436
* time field, based on the calendar's rules. For example, to subtract 5 days from
437
* the current time of the calendar, call add(Calendar::DATE, -5). When adding on
438
* the month or Calendar::MONTH field, other fields like date might conflict and
439
* need to be changed. For instance, adding 1 month on the date 01/31/96 will result
442
* @param field Specifies which date field to modify.
443
* @param amount The amount of time to be added to the field, in the natural unit
444
* for that field (e.g., days for the day fields, hours for the hour
446
* @param status Output param set to success/failure code on exit. If any value
447
* previously set in the time field is invalid or restricted by
448
* leniency, this will be set to an error status.
451
virtual void add(EDateFields field, int32_t amount, UErrorCode& status) = 0;
454
* Time Field Rolling function. Rolls (up/down) a single unit of time on the given
455
* time field. For example, to roll the current date up by one day, call
456
* roll(Calendar::DATE, true). When rolling on the year or Calendar::YEAR field, it
457
* will roll the year value in the range between getMinimum(Calendar::YEAR) and the
458
* value returned by getMaximum(Calendar::YEAR). When rolling on the month or
459
* Calendar::MONTH field, other fields like date might conflict and, need to be
460
* changed. For instance, rolling the month up on the date 01/31/96 will result in
461
* 02/29/96. Rolling up always means rolling forward in time; e.g., rolling the year
462
* up on "100 BC" will result in "99 BC", for Gregorian calendar. When rolling on the
463
* hour-in-day or Calendar::HOUR_OF_DAY field, it will roll the hour value in the range
464
* between 0 and 23, which is zero-based.
466
* NOTE: Do not use this method -- use roll(EDateFields, int, UErrorCode&) instead.
468
* @param field The time field.
469
* @param up Indicates if the value of the specified time field is to be rolled
470
* up or rolled down. Use true if rolling up, false otherwise.
471
* @param status Output param set to success/failure code on exit. If any value
472
* previously set in the time field is invalid or restricted by
473
* leniency, this will be set to an error status.
476
void roll(EDateFields field, UBool up, UErrorCode& status);
479
* Time Field Rolling function. Rolls by the given amount on the given
480
* time field. For example, to roll the current date up by one day, call
481
* roll(Calendar::DATE, +1, status). When rolling on the month or
482
* Calendar::MONTH field, other fields like date might conflict and, need to be
483
* changed. For instance, rolling the month up on the date 01/31/96 will result in
484
* 02/29/96. Rolling by a positive value always means rolling forward in time;
485
* e.g., rolling the year by +1 on "100 BC" will result in "99 BC", for Gregorian
486
* calendar. When rolling on the hour-in-day or Calendar::HOUR_OF_DAY field, it will
487
* roll the hour value in the range between 0 and 23, which is zero-based.
489
* The only difference between roll() and add() is that roll() does not change
490
* the value of more significant fields when it reaches the minimum or maximum
491
* of its range, whereas add() does.
493
* @param field The time field.
494
* @param amount Indicates amount to roll.
495
* @param status Output param set to success/failure code on exit. If any value
496
* previously set in the time field is invalid, this will be set to
500
virtual void roll(EDateFields field, int32_t amount, UErrorCode& status) = 0;
503
* Return the difference between the given time and the time this
504
* calendar object is set to. If this calendar is set
505
* <em>before</em> the given time, the returned value will be
506
* positive. If this calendar is set <em>after</em> the given
507
* time, the returned value will be negative. The
508
* <code>field</code> parameter specifies the units of the return
509
* value. For example, if <code>fieldDifference(when,
510
* Calendar.MONTH)</code> returns 3, then this calendar is set to
511
* 3 months before <code>when</code>, and possibly some addition
512
* time less than one month.
514
* <p>As a side effect of this call, this calendar is advanced
515
* toward <code>when</code> by the given amount. That is, calling
516
* this method has the side effect of calling <code>add(field,
517
* n)</code>, where <code>n</code> is the return value.
519
* <p>Usage: To use this method, call it first with the largest
520
* field of interest, then with progressively smaller fields. For
524
* int y = cal.fieldDifference(when, Calendar.YEAR);
525
* int m = cal.fieldDifference(when, Calendar.MONTH);
526
* int d = cal.fieldDifference(when, Calendar.DATE);</pre>
528
* computes the difference between <code>cal</code> and
529
* <code>when</code> in years, months, and days.
531
* <p>Note: <code>fieldDifference()</code> is
532
* <em>asymmetrical</em>. That is, in the following code:
535
* cal.setTime(date1);
536
* int m1 = cal.fieldDifference(date2, Calendar.MONTH);
537
* int d1 = cal.fieldDifference(date2, Calendar.DATE);
538
* cal.setTime(date2);
539
* int m2 = cal.fieldDifference(date1, Calendar.MONTH);
540
* int d2 = cal.fieldDifference(date1, Calendar.DATE);</pre>
542
* one might expect that <code>m1 == -m2 && d1 == -d2</code>.
543
* However, this is not generally the case, because of
544
* irregularities in the underlying calendar system (e.g., the
545
* Gregorian calendar has a varying number of days per month).
547
* @param when the date to compare this calendar's time to
548
* @param field the field in which to compute the result
549
* @return the difference, either positive or negative, between
550
* this calendar's time and <code>when</code>, in terms of
551
* <code>field</code>.
554
virtual int32_t fieldDifference(UDate when, EDateFields field, UErrorCode& status);
557
* Sets the calendar's time zone to be the one passed in. The Calendar takes ownership
558
* of the TimeZone; the caller is no longer responsible for deleting it. If the
559
* given time zone is NULL, this function has no effect.
561
* @param value The given time zone.
564
void adoptTimeZone(TimeZone* value);
567
* Sets the calendar's time zone to be the same as the one passed in. The TimeZone
568
* passed in is _not_ adopted; the client is still responsible for deleting it.
570
* @param value The given time zone.
573
void setTimeZone(const TimeZone& zone);
576
* Returns a reference to the time zone owned by this calendar. The returned reference
577
* is only valid until clients make another call to adoptTimeZone or setTimeZone,
578
* or this Calendar is destroyed.
580
* @return The time zone object associated with this calendar.
583
const TimeZone& getTimeZone(void) const;
586
* Returns the time zone owned by this calendar. The caller owns the returned object
587
* and must delete it when done. After this call, the new time zone associated
588
* with this Calendar is the default TimeZone as returned by TimeZone::createDefault().
590
* @return The time zone object which was associated with this calendar.
593
TimeZone* orphanTimeZone(void);
596
* Queries if the current date for this Calendar is in Daylight Savings Time.
598
* @param status Fill-in parameter which receives the status of this operation.
599
* @return True if the current date for this Calendar is in Daylight Savings Time,
603
virtual UBool inDaylightTime(UErrorCode& status) const = 0;
606
* Specifies whether or not date/time interpretation is to be lenient. With lenient
607
* interpretation, a date such as "February 942, 1996" will be treated as being
608
* equivalent to the 941st day after February 1, 1996. With strict interpretation,
609
* such dates will cause an error when computing time from the time field values
610
* representing the dates.
612
* @param lenient True specifies date/time interpretation to be lenient.
614
* @see DateFormat#setLenient
617
void setLenient(UBool lenient);
620
* Tells whether date/time interpretation is to be lenient.
622
* @return True tells that date/time interpretation is to be lenient.
625
UBool isLenient(void) const;
628
* Sets what the first day of the week is; e.g., Sunday in US, Monday in France.
630
* @param value The given first day of the week.
633
void setFirstDayOfWeek(EDaysOfWeek value);
636
* Gets what the first day of the week is; e.g., Sunday in US, Monday in France.
638
* @return The first day of the week.
641
EDaysOfWeek getFirstDayOfWeek(void) const;
644
* Sets what the minimal days required in the first week of the year are; For
645
* example, if the first week is defined as one that contains the first day of the
646
* first month of a year, call the method with value 1. If it must be a full week,
649
* @param value The given minimal days required in the first week of the year.
652
void setMinimalDaysInFirstWeek(uint8_t value);
655
* Gets what the minimal days required in the first week of the year are; e.g., if
656
* the first week is defined as one that contains the first day of the first month
657
* of a year, getMinimalDaysInFirstWeek returns 1. If the minimal days required must
658
* be a full week, getMinimalDaysInFirstWeek returns 7.
660
* @return The minimal days required in the first week of the year.
663
uint8_t getMinimalDaysInFirstWeek(void) const;
666
* Gets the minimum value for the given time field. e.g., for Gregorian
669
* @param field The given time field.
670
* @return The minimum value for the given time field.
673
virtual int32_t getMinimum(EDateFields field) const = 0;
676
* Gets the maximum value for the given time field. e.g. for Gregorian DAY_OF_MONTH,
679
* @param field The given time field.
680
* @return The maximum value for the given time field.
683
virtual int32_t getMaximum(EDateFields field) const = 0;
686
* Gets the highest minimum value for the given field if varies. Otherwise same as
687
* getMinimum(). For Gregorian, no difference.
689
* @param field The given time field.
690
* @return The highest minimum value for the given time field.
693
virtual int32_t getGreatestMinimum(EDateFields field) const = 0;
696
* Gets the lowest maximum value for the given field if varies. Otherwise same as
697
* getMaximum(). e.g., for Gregorian DAY_OF_MONTH, 28.
699
* @param field The given time field.
700
* @return The lowest maximum value for the given time field.
703
virtual int32_t getLeastMaximum(EDateFields field) const = 0;
706
* Return the minimum value that this field could have, given the current date.
707
* For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum().
709
* The version of this function on Calendar uses an iterative algorithm to determine the
710
* actual minimum value for the field. There is almost always a more efficient way to
711
* accomplish this (in most cases, you can simply return getMinimum()). GregorianCalendar
712
* overrides this function with a more efficient implementation.
714
* @param field the field to determine the minimum of
715
* @return the minimum of the given field for the current date of this Calendar
718
int32_t getActualMinimum(EDateFields field, UErrorCode& status) const;
721
* Return the maximum value that this field could have, given the current date.
722
* For example, with the date "Feb 3, 1997" and the DAY_OF_MONTH field, the actual
723
* maximum would be 28; for "Feb 3, 1996" it s 29. Similarly for a Hebrew calendar,
724
* for some years the actual maximum for MONTH is 12, and for others 13.
726
* The version of this function on Calendar uses an iterative algorithm to determine the
727
* actual maximum value for the field. There is almost always a more efficient way to
728
* accomplish this (in most cases, you can simply return getMaximum()). GregorianCalendar
729
* overrides this function with a more efficient implementation.
731
* @param field the field to determine the maximum of
732
* @return the maximum of the given field for the current date of this Calendar
735
int32_t getActualMaximum(EDateFields field, UErrorCode& status) const;
738
* Gets the value for a given time field. Recalculate the current time field values
739
* if the time value has been changed by a call to setTime(). Return zero for unset
740
* fields if any fields have been explicitly set by a call to set(). To force a
741
* recomputation of all fields regardless of the previous state, call complete().
742
* This method is semantically const, but may alter the object in memory.
744
* @param field The given time field.
745
* @param status Fill-in parameter which receives the status of the operation.
746
* @return The value for the given time field, or zero if the field is unset,
747
* and set() has been called for any other field.
750
int32_t get(EDateFields field, UErrorCode& status) const;
753
* Determines if the given time field has a value set. This can affect in the
754
* resolving of time in Calendar. Unset fields have a value of zero, by definition.
756
* @return True if the given time field has a value set; false otherwise.
759
UBool isSet(EDateFields field) const;
762
* Sets the given time field with the given value.
764
* @param field The given time field.
765
* @param value The value to be set for the given time field.
768
void set(EDateFields field, int32_t value);
771
* Sets the values for the fields YEAR, MONTH, and DATE. Other field values are
772
* retained; call clear() first if this is not desired.
774
* @param year The value used to set the YEAR time field.
775
* @param month The value used to set the MONTH time field. Month value is 0-based.
776
* e.g., 0 for January.
777
* @param date The value used to set the DATE time field.
780
void set(int32_t year, int32_t month, int32_t date);
783
* Sets the values for the fields YEAR, MONTH, DATE, HOUR_OF_DAY, and MINUTE. Other
784
* field values are retained; call clear() first if this is not desired.
786
* @param year The value used to set the YEAR time field.
787
* @param month The value used to set the MONTH time field. Month value is
788
* 0-based. E.g., 0 for January.
789
* @param date The value used to set the DATE time field.
790
* @param hour The value used to set the HOUR_OF_DAY time field.
791
* @param minute The value used to set the MINUTE time field.
794
void set(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute);
797
* Sets the values for the fields YEAR, MONTH, DATE, HOUR_OF_DAY, MINUTE, and SECOND.
798
* Other field values are retained; call clear() first if this is not desired.
800
* @param year The value used to set the YEAR time field.
801
* @param month The value used to set the MONTH time field. Month value is
802
* 0-based. E.g., 0 for January.
803
* @param date The value used to set the DATE time field.
804
* @param hour The value used to set the HOUR_OF_DAY time field.
805
* @param minute The value used to set the MINUTE time field.
806
* @param second The value used to set the SECOND time field.
809
void set(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, int32_t second);
812
* Clears the values of all the time fields, making them both unset and assigning
813
* them a value of zero. The field values will be determined during the next
814
* resolving of time into time fields.
820
* Clears the value in the given time field, both making it unset and assigning it a
821
* value of zero. This field value will be determined during the next resolving of
822
* time into time fields.
824
* @param field The time field to be cleared.
827
void clear(EDateFields field);
830
* Returns a unique class ID POLYMORPHICALLY. Pure virtual method. This method is to
831
* implement a simple version of RTTI, since not all C++ compilers support genuine
832
* RTTI. Polymorphic operator==() and clone() methods call this method.
834
* Concrete subclasses of Calendar must implement getDynamicClassID() and also a
835
* static method and data member:
837
* static UClassID getStaticClassID() { return (UClassID)&fgClassID; }
838
* static char fgClassID;
840
* @return The class ID for this object. All objects of a given class have the
841
* same class ID. Objects of other classes have different class IDs.
844
virtual UClassID getDynamicClassID(void) const = 0;
849
* Constructs a Calendar with the default time zone as returned by
850
* TimeZone::createInstance(), and the default locale.
852
* @param success Indicates the status of Calendar object construction. Returns
853
* U_ZERO_ERROR if constructed successfully.
856
Calendar(UErrorCode& success);
862
Calendar(const Calendar& source);
865
* Default assignment operator
868
Calendar& operator=(const Calendar& right);
871
* Constructs a Calendar with the given time zone and locale. Clients are no longer
872
* responsible for deleting the given time zone object after it's adopted.
874
* @param zoneToAdopt The given time zone.
875
* @param aLocale The given locale.
876
* @param success Indicates the status of Calendar object construction. Returns
877
* U_ZERO_ERROR if constructed successfully.
880
Calendar(TimeZone* zone, const Locale& aLocale, UErrorCode& success);
883
* Constructs a Calendar with the given time zone and locale.
885
* @param zone The given time zone.
886
* @param aLocale The given locale.
887
* @param success Indicates the status of Calendar object construction. Returns
888
* U_ZERO_ERROR if constructed successfully.
891
Calendar(const TimeZone& zone, const Locale& aLocale, UErrorCode& success);
894
* Converts Calendar's time field values to GMT as milliseconds.
896
* @param status Output param set to success/failure code on exit. If any value
897
* previously set in the time field is invalid or restricted by
898
* leniency, this will be set to an error status.
901
virtual void computeTime(UErrorCode& status) = 0;
904
* Converts GMT as milliseconds to time field values. This allows you to sync up the
905
* time field values with a new time that is set for the calendar. This method
906
* does NOT recompute the time first; to recompute the time, then the fields, use
907
* the method complete().
910
virtual void computeFields(UErrorCode& status) = 0;
913
* Gets this Calendar's current time as a long.
914
* @return the current time as UTC milliseconds from the epoch.
917
double getTimeInMillis(UErrorCode& status) const;
920
* Sets this Calendar's current time from the given long value.
921
* @param date the new time in UTC milliseconds from the epoch.
924
void setTimeInMillis( double millis, UErrorCode& status );
927
* Recomputes the current time from currently set fields, and then fills in any
928
* unset fields in the time field list.
930
* @param status Output param set to success/failure code on exit. If any value
931
* previously set in the time field is invalid or restricted by
932
* leniency, this will be set to an error status.
935
void complete(UErrorCode& status);
938
* Gets the value for a given time field. Subclasses can use this function to get
939
* field values without forcing recomputation of time.
941
* @param field The given time field.
942
* @return The value for the given time field.
945
int32_t internalGet(EDateFields field) const {return fFields[field];}
948
* Sets the value for a given time field. This is a fast internal method for
949
* subclasses. It does not affect the areFieldsInSync, isTimeSet, or areAllFieldsSet
953
void internalSet(EDateFields field, int32_t value);
957
* The flag which indicates if the current time is set in the calendar.
963
* True if the fields are in sync with the currently set time of this Calendar.
964
* If false, then the next attempt to get the value of a field will
965
* force a recomputation of all fields from the current value of the time
968
* This should really be named areFieldsInSync, but the old name is retained
969
* for backward compatibility.
975
* True if all of the fields have been set. This is initially false, and set to
976
* true by computeFields().
979
UBool fAreAllFieldsSet;
982
* Get the current time without recomputing.
985
UDate internalGetTime(void) const { return fTime; }
988
* Set the current time without affecting flags or fields.
991
void internalSetTime(UDate time) { fTime = time; }
994
* The time fields containing values into which the millis is computed.
997
int32_t fFields[FIELD_COUNT];
1000
* The flags which tell if a specified time field for the calendar is set.
1003
UBool fIsSet[FIELD_COUNT];
1005
/** Special values of stamp[]
1015
* Pseudo-time-stamps which specify when each field was set. There
1016
* are two special values, UNSET and INTERNALLY_SET. Values from
1017
* MINIMUM_USER_SET to Integer.MAX_VALUE are legal user set values.
1020
int32_t fStamp[FIELD_COUNT];
1024
// The next available value for stampp[]
1025
int32_t fNextStamp;// = MINIMUM_USER_STAMP;
1028
* The current time set for the calendar.
1038
* Time zone affects the time calculation done by Calendar. Calendar subclasses use
1039
* the time zone data to produce the local time.
1044
* Both firstDayOfWeek and minimalDaysInFirstWeek are locale-dependent. They are
1045
* used to figure out the week count for a specific date for a given locale. These
1046
* must be set when a Calendar is constructed. For example, in US locale,
1047
* firstDayOfWeek is SUNDAY; minimalDaysInFirstWeek is 1. They are used to figure
1048
* out the week count for a specific date for a given locale. These must be set when
1049
* a Calendar is constructed.
1051
EDaysOfWeek fFirstDayOfWeek;
1052
uint8_t fMinimalDaysInFirstWeek;
1055
* Sets firstDayOfWeek and minimalDaysInFirstWeek. Called at Calendar construction
1058
* @param desiredLocale The given locale.
1059
* @param success Indicates the status of setting the week count data from
1060
* the resource for the given locale. Returns U_ZERO_ERROR if
1061
* constructed successfully.
1063
void setWeekCountData(const Locale& desiredLocale, UErrorCode& success);
1066
* Recompute the time and update the status fields isTimeSet
1067
* and areFieldsSet. Callers should check isTimeSet and only
1068
* call this method if isTimeSet is false.
1070
void updateTime(UErrorCode& status);
1073
* The resource tag for the resource where the week-count data is stored.
1075
static const char kDateTimeElements[];
1078
// -------------------------------------
1081
Calendar::createInstance(TimeZone* zone, UErrorCode& errorCode)
1083
// since the Locale isn't specified, use the default locale
1084
return createInstance(zone, Locale::getDefault(), errorCode);
1087
// -------------------------------------
1090
Calendar::roll(EDateFields field, UBool up, UErrorCode& status)
1092
roll(field, (int32_t)(up ? +1 : -1), status);
1095
// -------------------------------------
1098
* Fast method for subclasses. The caller must maintain fUserSetDSTOffset and
1099
* fUserSetZoneOffset, as well as the isSet[] array.
1102
Calendar::internalSet(EDateFields field, int32_t value)
1104
fFields[field] = value;