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