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