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