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