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