ICU 78.1  78.1
calendar.h
Go to the documentation of this file.
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 
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)
55 typedef int32_t UFieldResolutionTable[12][8];
56 
57 class BasicTimeZone;
190 public:
191 #ifndef U_FORCE_HIDE_DEPRECATED_API
198  enum EDateFields {
199 #ifndef U_HIDE_DEPRECATED_API
200 /*
201  * ERA may be defined on other platforms. To avoid any potential problems undefined it here.
202  */
203 #ifdef ERA
204 #undef ERA
205 #endif
206  ERA, // Example: 0..1
207  YEAR, // Example: 1..big number
208  MONTH, // Example: 0..11
209  WEEK_OF_YEAR, // Example: 1..53
210  WEEK_OF_MONTH, // Example: 1..4
211  DATE, // Example: 1..31
212  DAY_OF_YEAR, // Example: 1..365
213  DAY_OF_WEEK, // Example: 1..7
214  DAY_OF_WEEK_IN_MONTH, // Example: 1..4, may be specified as -1
215  AM_PM, // Example: 0..1
216  HOUR, // Example: 0..11
217  HOUR_OF_DAY, // Example: 0..23
218  MINUTE, // Example: 0..59
219  SECOND, // Example: 0..59
220  MILLISECOND, // Example: 0..999
221  ZONE_OFFSET, // Example: -12*U_MILLIS_PER_HOUR..12*U_MILLIS_PER_HOUR
222  DST_OFFSET, // Example: 0 or U_MILLIS_PER_HOUR
223  YEAR_WOY, // 'Y' Example: 1..big number - Year of Week of Year
224  DOW_LOCAL, // 'e' Example: 1..7 - Day of Week / Localized
225 
226  EXTENDED_YEAR,
227  JULIAN_DAY,
228  MILLISECONDS_IN_DAY,
229  IS_LEAP_MONTH,
230 
231  FIELD_COUNT = UCAL_FIELD_COUNT // See ucal.h for other fields.
232 #endif /* U_HIDE_DEPRECATED_API */
233  };
234 #endif // U_FORCE_HIDE_DEPRECATED_API
235 
236 #ifndef U_HIDE_DEPRECATED_API
243  enum EDaysOfWeek {
244  SUNDAY = 1,
245  MONDAY,
246  TUESDAY,
247  WEDNESDAY,
248  THURSDAY,
249  FRIDAY,
250  SATURDAY
251  };
252 
257  enum EMonths {
258  JANUARY,
259  FEBRUARY,
260  MARCH,
261  APRIL,
262  MAY,
263  JUNE,
264  JULY,
265  AUGUST,
266  SEPTEMBER,
267  OCTOBER,
268  NOVEMBER,
269  DECEMBER,
270  UNDECIMBER
271  };
272 
277  enum EAmpm {
278  AM,
279  PM
280  };
281 #endif /* U_HIDE_DEPRECATED_API */
282 
288 
295  U_I18N_API virtual Calendar* clone() const = 0;
296 
308  U_I18N_API static Calendar* U_EXPORT2 createInstance(UErrorCode& success);
309 
322  U_I18N_API static Calendar* U_EXPORT2 createInstance(TimeZone* zoneToAdopt, UErrorCode& success);
323 
335  U_I18N_API static Calendar* U_EXPORT2 createInstance(const TimeZone& zone, UErrorCode& success);
336 
347  U_I18N_API static Calendar* U_EXPORT2 createInstance(const Locale& aLocale, UErrorCode& success);
348 
362  U_I18N_API static Calendar* U_EXPORT2 createInstance(TimeZone* zoneToAdopt,
363  const Locale& aLocale,
364  UErrorCode& success);
365 
378  U_I18N_API static Calendar* U_EXPORT2 createInstance(const TimeZone& zone,
379  const Locale& aLocale,
380  UErrorCode& success);
381 
391  U_I18N_API static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
392 
409  U_I18N_API static StringEnumeration* U_EXPORT2 getKeywordValuesForLocale(const char* key,
410  const Locale& locale,
411  UBool commonlyUsed,
412  UErrorCode& status);
413 
421  U_I18N_API static UDate U_EXPORT2 getNow();
422 
436  U_I18N_API inline UDate getTime(UErrorCode& status) const { return getTimeInMillis(status); }
437 
448  U_I18N_API inline void setTime(UDate date, UErrorCode& status) { setTimeInMillis(date, status); }
449 
461  U_I18N_API virtual bool operator==(const Calendar& that) const;
462 
471  U_I18N_API bool operator!=(const Calendar& that) const { return !operator==(that); }
472 
483  U_I18N_API virtual UBool isEquivalentTo(const Calendar& other) const;
484 
499  U_I18N_API UBool equals(const Calendar& when, UErrorCode& status) const;
500 
514  U_I18N_API UBool before(const Calendar& when, UErrorCode& status) const;
515 
529  U_I18N_API UBool after(const Calendar& when, UErrorCode& status) const;
530 
531 #ifndef U_FORCE_HIDE_DEPRECATED_API
552  U_I18N_API virtual void add(EDateFields field, int32_t amount, UErrorCode& status);
553 #endif // U_FORCE_HIDE_DEPRECATED_API
554 
575  U_I18N_API virtual void add(UCalendarDateFields field, int32_t amount, UErrorCode& status);
576 
577 #ifndef U_HIDE_DEPRECATED_API
610  U_I18N_API inline void roll(EDateFields field, UBool up, UErrorCode& status);
611 #endif /* U_HIDE_DEPRECATED_API */
612 
645  U_I18N_API inline void roll(UCalendarDateFields field, UBool up, UErrorCode& status);
646 
647 #ifndef U_FORCE_HIDE_DEPRECATED_API
679  U_I18N_API virtual void roll(EDateFields field, int32_t amount, UErrorCode& status);
680 #endif // U_FORCE_HIDE_DEPRECATED_API
681 
713  U_I18N_API virtual void roll(UCalendarDateFields field, int32_t amount, UErrorCode& status);
714 
715 #ifndef U_FORCE_HIDE_DEPRECATED_API
771  U_I18N_API virtual int32_t fieldDifference(UDate when, EDateFields field, UErrorCode& status);
772 #endif // U_FORCE_HIDE_DEPRECATED_API
773 
829  U_I18N_API virtual int32_t fieldDifference(UDate when,
830  UCalendarDateFields field,
831  UErrorCode& status);
832 
842 
850  U_I18N_API void setTimeZone(const TimeZone& zone);
851 
861 
871 
880  U_I18N_API virtual UBool inDaylightTime(UErrorCode& status) const;
881 
894  U_I18N_API void setLenient(UBool lenient);
895 
903 
925 
936 
959 
971 
979 
980 #ifndef U_HIDE_DEPRECATED_API
988 #endif /* U_HIDE_DEPRECATED_API */
989 
998 
1009 
1020 
1021 #ifndef U_FORCE_HIDE_DEPRECATED_API
1030  U_I18N_API virtual int32_t getMinimum(EDateFields field) const;
1031 #endif // U_FORCE_HIDE_DEPRECATED_API
1032 
1041  U_I18N_API virtual int32_t getMinimum(UCalendarDateFields field) const;
1042 
1043 #ifndef U_FORCE_HIDE_DEPRECATED_API
1052  U_I18N_API virtual int32_t getMaximum(EDateFields field) const;
1053 #endif // U_FORCE_HIDE_DEPRECATED_API
1054 
1063  U_I18N_API virtual int32_t getMaximum(UCalendarDateFields field) const;
1064 
1065 #ifndef U_FORCE_HIDE_DEPRECATED_API
1074  U_I18N_API virtual int32_t getGreatestMinimum(EDateFields field) const;
1075 #endif // U_FORCE_HIDE_DEPRECATED_API
1076 
1085  U_I18N_API virtual int32_t getGreatestMinimum(UCalendarDateFields field) const;
1086 
1087 #ifndef U_FORCE_HIDE_DEPRECATED_API
1096  U_I18N_API virtual int32_t getLeastMaximum(EDateFields field) const;
1097 #endif // U_FORCE_HIDE_DEPRECATED_API
1098 
1107  U_I18N_API virtual int32_t getLeastMaximum(UCalendarDateFields field) const;
1108 
1109 #ifndef U_HIDE_DEPRECATED_API
1124  U_I18N_API int32_t getActualMinimum(EDateFields field, UErrorCode& status) const;
1125 #endif /* U_HIDE_DEPRECATED_API */
1126 
1141  U_I18N_API virtual int32_t getActualMinimum(UCalendarDateFields field, UErrorCode& status) const;
1142 
1159  U_I18N_API virtual int32_t getActualMaximum(UCalendarDateFields field, UErrorCode& status) const;
1160 
1174  U_I18N_API int32_t get(UCalendarDateFields field, UErrorCode& status) const;
1175 
1185 
1193  U_I18N_API void set(UCalendarDateFields field, int32_t value);
1194 
1205  U_I18N_API void set(int32_t year, int32_t month, int32_t date);
1206 
1219  U_I18N_API void set(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute);
1220 
1234  U_I18N_API void set(int32_t year, int32_t month, int32_t date,
1235  int32_t hour, int32_t minute, int32_t second);
1236 
1244 
1255 
1271  U_I18N_API virtual UClassID getDynamicClassID() const override = 0;
1272 
1305  U_I18N_API virtual const char* getType() const = 0;
1306 
1324  UErrorCode& status) const;
1325 
1341  UErrorCode& status) const;
1342 
1352  U_I18N_API virtual UBool isWeekend(UDate date, UErrorCode& status) const;
1353 
1361  U_I18N_API virtual UBool isWeekend() const;
1362 
1377  U_I18N_API virtual bool inTemporalLeapYear(UErrorCode& status) const;
1378 
1397  U_I18N_API virtual const char* getTemporalMonthCode(UErrorCode& status) const;
1398 
1418  U_I18N_API virtual void setTemporalMonthCode(const char* temporalMonth, UErrorCode& status);
1419 
1420 protected:
1421 
1431 
1438  U_I18N_API Calendar(const Calendar& source);
1439 
1447 
1458  U_I18N_API Calendar(TimeZone* zone, const Locale& aLocale, UErrorCode& success);
1459 
1469  U_I18N_API Calendar(const TimeZone& zone, const Locale& aLocale, UErrorCode& success);
1470 
1479  U_I18N_API virtual void computeTime(UErrorCode& status);
1480 
1492  U_I18N_API virtual void computeFields(UErrorCode& status);
1493 
1503  U_I18N_API double getTimeInMillis(UErrorCode& status) const;
1504 
1513  U_I18N_API void setTimeInMillis(double millis, UErrorCode& status);
1514 
1525 
1526 #ifndef U_HIDE_DEPRECATED_API
1535  U_I18N_API inline int32_t internalGet(EDateFields field) const { return fFields[field]; }
1536 #endif /* U_HIDE_DEPRECATED_API */
1537 
1538 #ifndef U_HIDE_INTERNAL_API
1549  U_I18N_API inline int32_t internalGet(UCalendarDateFields field, int32_t defaultValue) const {
1550  return fStamp[field] > kUnset ? fFields[field] : defaultValue;
1551  }
1552 
1561  U_I18N_API inline int32_t internalGet(UCalendarDateFields field) const { return fFields[field]; }
1562 
1568  U_I18N_API virtual bool isEra0CountingBackward() const { return false; }
1569 
1575  U_I18N_API virtual int32_t getRelatedYearDifference() const;
1576 
1577 #endif /* U_HIDE_INTERNAL_API */
1578 
1588  U_I18N_API virtual int32_t internalGetMonth(UErrorCode& status) const;
1589 
1603  U_I18N_API virtual int32_t internalGetMonth(int32_t defaultValue, UErrorCode& status) const;
1604 
1605 #ifndef U_HIDE_DEPRECATED_API
1615  U_I18N_API void internalSet(EDateFields field, int32_t value);
1616 #endif /* U_HIDE_DEPRECATED_API */
1617 
1627  U_I18N_API inline void internalSet(UCalendarDateFields field, int32_t value);
1628 
1636  UBool isMinimum,
1637  UErrorCode& status);
1638 
1643  enum ELimitType {
1644 #ifndef U_HIDE_INTERNAL_API
1645  UCAL_LIMIT_MINIMUM = 0,
1646  UCAL_LIMIT_GREATEST_MINIMUM,
1647  UCAL_LIMIT_LEAST_MAXIMUM,
1648  UCAL_LIMIT_MAXIMUM,
1649  UCAL_LIMIT_COUNT
1650 #endif /* U_HIDE_INTERNAL_API */
1651  };
1652 
1674  U_I18N_API virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const = 0;
1675 
1683  U_I18N_API virtual int32_t getLimit(UCalendarDateFields field, ELimitType limitType) const;
1684 
1700  U_I18N_API virtual int64_t handleComputeMonthStart(int32_t eyear,
1701  int32_t month,
1702  UBool useMonth,
1703  UErrorCode& status) const = 0;
1704 
1712  U_I18N_API virtual int32_t handleGetMonthLength(int32_t extendedYear,
1713  int32_t month,
1714  UErrorCode& status) const;
1715 
1723  U_I18N_API virtual int32_t handleGetYearLength(int32_t eyear, UErrorCode& status) const;
1724 
1734  U_I18N_API virtual int32_t handleGetExtendedYear(UErrorCode& status) = 0;
1735 
1746 
1755  U_I18N_API virtual int32_t handleGetExtendedYearFromWeekFields(int32_t yearWoy,
1756  int32_t woy,
1757  UErrorCode& status);
1758 
1766 
1767 #ifndef U_HIDE_INTERNAL_API
1776 
1785 
1795  U_I18N_API int32_t computeZoneOffset(double millis, double millisInDay, UErrorCode& ec);
1796 
1806  UCalendarDateFields end,
1807  int32_t bestSoFar) const;
1808 
1815  U_I18N_API static constexpr int32_t kResolveSTOP = -1;
1816 
1826  U_I18N_API static constexpr int32_t kResolveRemap = 32;
1827 
1833  U_I18N_API static const UFieldResolutionTable kDatePrecedence[];
1834 
1840  U_I18N_API static const UFieldResolutionTable kYearPrecedence[];
1841 
1847  U_I18N_API static const UFieldResolutionTable kDOWPrecedence[];
1848 
1854  U_I18N_API static const UFieldResolutionTable kMonthPrecedence[];
1855 
1884 #endif /* U_HIDE_INTERNAL_API */
1885 
1890 
1891 #ifndef U_HIDE_INTERNAL_API
1898  UCalendarDateFields alternateField) const;
1899 #endif /* U_HIDE_INTERNAL_API */
1900 
1901 
1902 private:
1910  int32_t getActualHelper(UCalendarDateFields field, int32_t startValue, int32_t endValue, UErrorCode &status) const;
1911 
1912 protected:
1919  U_I18N_API UDate internalGetTime() const { return fTime; }
1920 
1928  U_I18N_API void internalSetTime(UDate time) { fTime = time; }
1929 
1934  int32_t fFields[UCAL_FIELD_COUNT];
1935 
1936 protected:
1940  enum {
1941  kUnset = 0,
1942  kInternallySet,
1943  kMinimumUserStamp
1944  };
1945 
1946 private:
1952  int8_t fStamp[UCAL_FIELD_COUNT];
1953 
1954 protected:
1979  U_I18N_API virtual void handleComputeFields(int32_t julianDay, UErrorCode& status);
1980 
1981 #ifndef U_HIDE_INTERNAL_API
1987  U_I18N_API int32_t getGregorianYear() const {
1988  return fGregorianYear;
1989  }
1990 
1996  U_I18N_API int32_t getGregorianMonth() const {
1997  return fGregorianMonth;
1998  }
1999 
2006  return fGregorianDayOfYear;
2007  }
2008 
2015  return fGregorianDayOfMonth;
2016  }
2017 #endif /* U_HIDE_INTERNAL_API */
2018 
2027  U_I18N_API virtual int32_t getDefaultMonthInYear(int32_t eyear, UErrorCode& status);
2028 
2038  U_I18N_API virtual int32_t getDefaultDayInMonth(int32_t eyear, int32_t month, UErrorCode& status);
2039 
2040  //-------------------------------------------------------------------------
2041  // Protected utility methods for use by subclasses. These are very handy
2042  // for implementing add, roll, and computeFields.
2043  //-------------------------------------------------------------------------
2044 
2074  U_I18N_API virtual void pinField(UCalendarDateFields field, UErrorCode& status);
2075 
2119  U_I18N_API int32_t weekNumber(int32_t desiredDay, int32_t dayOfPeriod, int32_t dayOfWeek);
2120 
2121 #ifndef U_HIDE_INTERNAL_API
2152  U_I18N_API inline int32_t weekNumber(int32_t dayOfPeriod, int32_t dayOfWeek);
2153 
2159 #endif /* U_HIDE_INTERNAL_API */
2160 
2161 private:
2162 
2166  int8_t fNextStamp = kMinimumUserStamp;
2167 
2172  void recalculateStamp();
2173 
2177  UDate fTime = 0;
2178 
2183  TimeZone* fZone = nullptr;
2184 
2188  bool fIsTimeSet:1;
2189 
2199  bool fAreFieldsSet:1;
2200 
2205  bool fAreAllFieldsSet:1;
2206 
2213  bool fAreFieldsVirtuallySet:1;
2214 
2218  bool fLenient:1;
2219 
2224  UCalendarWallTimeOption fRepeatedWallTime:3; // Somehow MSVC need 3 bits for UCalendarWallTimeOption
2225 
2230  UCalendarWallTimeOption fSkippedWallTime:3; // Somehow MSVC need 3 bits for UCalendarWallTimeOption
2231 
2240  UCalendarDaysOfWeek fFirstDayOfWeek:4; // Somehow MSVC need 4 bits for
2241  // UCalendarDaysOfWeek
2242  UCalendarDaysOfWeek fWeekendOnset:4; // Somehow MSVC need 4 bits for
2243  // UCalendarDaysOfWeek
2244  UCalendarDaysOfWeek fWeekendCease:4; // Somehow MSVC need 4 bits for
2245  // UCalendarDaysOfWeek
2246  uint8_t fMinimalDaysInFirstWeek;
2247  int32_t fWeekendOnsetMillis;
2248  int32_t fWeekendCeaseMillis;
2249 
2260  void setWeekData(const Locale& desiredLocale, const char *type, UErrorCode& success);
2261 
2271  void updateTime(UErrorCode& status);
2272 
2278  int32_t fGregorianYear;
2279 
2285  int8_t fGregorianMonth;
2286 
2292  int8_t fGregorianDayOfMonth;
2293 
2299  int16_t fGregorianDayOfYear;
2300 
2301  /* calculations */
2302 
2303 protected:
2304 
2312  U_I18N_API void computeGregorianFields(int32_t julianDay, UErrorCode& ec);
2313 
2314 private:
2315 
2336  void computeWeekFields(UErrorCode &ec);
2337 
2338 
2346  void validateFields(UErrorCode &status);
2347 
2355  void validateField(UCalendarDateFields field, int32_t min, int32_t max, UErrorCode& status);
2356 
2357  protected:
2358 #ifndef U_HIDE_INTERNAL_API
2368  U_I18N_API static uint8_t julianDayToDayOfWeek(int32_t julian);
2369 #endif /* U_HIDE_INTERNAL_API */
2370 
2371  private:
2372  Locale validLocale;
2373  Locale actualLocale;
2374 
2375  public:
2376 #if !UCONFIG_NO_SERVICE
2381 #ifndef U_HIDE_INTERNAL_API
2389 
2403  U_I18N_API static URegistryKey registerFactory(ICUServiceFactory* toAdopt, UErrorCode& status);
2404 
2421 #endif /* U_HIDE_INTERNAL_API */
2422 
2427  friend class CalendarFactory;
2428 
2433  friend class CalendarService;
2434 
2439  friend class DefaultCalendarFactory;
2440 #endif /* !UCONFIG_NO_SERVICE */
2441 
2446  U_I18N_API virtual UBool haveDefaultCentury() const = 0;
2447 
2452  U_I18N_API virtual UDate defaultCenturyStart() const = 0;
2453 
2458  U_I18N_API virtual int32_t defaultCenturyStartYear() const = 0;
2459 
2467 
2473  U_I18N_API virtual int32_t getRelatedYear(UErrorCode& status) const;
2474 
2480  U_I18N_API virtual void setRelatedYear(int32_t year);
2481 
2482 #ifndef U_HIDE_INTERNAL_API
2489  U_I18N_API const char* getLocaleID(ULocDataLocaleType type, UErrorCode& status) const;
2490 #endif /* U_HIDE_INTERNAL_API */
2491 
2492 private:
2497  BasicTimeZone* getBasicTimeZone() const;
2498 
2506  UBool getImmediatePreviousZoneTransition(UDate base, UDate *transitionTime, UErrorCode& status) const;
2507 
2508 public:
2509 #ifndef U_HIDE_INTERNAL_API
2518  U_I18N_API static Calendar* U_EXPORT2 makeInstance(const Locale& locale, UErrorCode& status);
2519 
2530  U_I18N_API static void U_EXPORT2 getCalendarTypeFromLocale(const Locale& locale,
2531  char* typeBuffer,
2532  int32_t typeBufferSize,
2533  UErrorCode& status);
2534 #endif /* U_HIDE_INTERNAL_API */
2535 };
2536 
2537 // -------------------------------------
2538 
2539 inline Calendar*
2540 Calendar::createInstance(TimeZone* zone, UErrorCode& errorCode)
2541 {
2542  // since the Locale isn't specified, use the default locale
2543  return createInstance(zone, Locale::getDefault(), errorCode);
2544 }
2545 
2546 // -------------------------------------
2547 
2548 inline void
2549 Calendar::roll(UCalendarDateFields field, UBool up, UErrorCode& status)
2550 {
2551  roll(field, static_cast<int32_t>(up ? +1 : -1), status);
2552 }
2553 
2554 #ifndef U_HIDE_DEPRECATED_API
2555 inline void
2556 Calendar::roll(EDateFields field, UBool up, UErrorCode& status)
2557 {
2558  roll(static_cast<UCalendarDateFields>(field), up, status);
2559 }
2560 #endif /* U_HIDE_DEPRECATED_API */
2561 
2562 
2563 // -------------------------------------
2564 
2570 inline void
2571 Calendar::internalSet(UCalendarDateFields field, int32_t value)
2572 {
2573  fFields[field] = value;
2574  fStamp[field] = kInternallySet;
2575 }
2576 
2583 #define DECLARE_OVERRIDE_SYSTEM_DEFAULT_CENTURY \
2584  virtual UBool haveDefaultCentury() const override; \
2585  virtual UDate defaultCenturyStart() const override; \
2586  virtual int32_t defaultCenturyStartYear() const override;
2587 
2588 #ifndef U_HIDE_INTERNAL_API
2589 inline int32_t Calendar::weekNumber(int32_t dayOfPeriod, int32_t dayOfWeek)
2590 {
2591  return weekNumber(dayOfPeriod, dayOfPeriod, dayOfWeek);
2592 }
2593 #endif /* U_HIDE_INTERNAL_API */
2594 
2595 U_NAMESPACE_END
2596 
2597 #endif /* #if !UCONFIG_NO_FORMATTING */
2598 
2599 #endif /* U_SHOW_CPLUSPLUS_API */
2600 
2601 #endif // _CALENDAR
BasicTimeZone is an abstract class extending TimeZone.
Definition: basictz.h:38
Calendar is an abstract base class for converting between a UDate object and a set of integer fields ...
Definition: calendar.h:189
U_I18N_API int32_t computeJulianDay(UErrorCode &status)
Compute the Julian day from fields.
virtual U_I18N_API UClassID getDynamicClassID() const override=0
Returns a unique class ID POLYMORPHICALLY.
U_I18N_API double computeMillisInDay()
Compute the milliseconds in the day from the fields.
U_I18N_API int32_t getGregorianYear() const
Return the extended year on the Gregorian calendar as computed by computeGregorianFields().
Definition: calendar.h:1987
static U_I18N_API void getCalendarTypeFromLocale(const Locale &locale, char *typeBuffer, int32_t typeBufferSize, UErrorCode &status)
Get the calendar type for given locale.
U_I18N_API void adoptTimeZone(TimeZone *value)
Sets the calendar's time zone to be the one passed in.
U_I18N_API Locale getLocale(ULocDataLocaleType type, UErrorCode &status) const
Get the locale for this calendar object.
static U_I18N_API URegistryKey registerFactory(ICUServiceFactory *toAdopt, UErrorCode &status)
Register a new Calendar factory.
virtual U_I18N_API int32_t getLeastMaximum(EDateFields field) const
Gets the lowest maximum value for the given field if varies.
U_I18N_API void setRepeatedWallTimeOption(UCalendarWallTimeOption option)
Sets the behavior for handling wall time repeating multiple times at negative time zone offset transi...
U_I18N_API void set(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, int32_t second)
Sets the values for the fields YEAR, MONTH, DATE, HOUR_OF_DAY, MINUTE, and SECOND.
static U_I18N_API UBool unregister(URegistryKey key, UErrorCode &status)
Unregister a previously-registered CalendarFactory using the key returned from the register call.
static U_I18N_API StringEnumeration * getAvailableLocales()
INTERNAL FOR 2.6 – Registration.
U_I18N_API UDate getTime(UErrorCode &status) const
Gets this Calendar's time as milliseconds.
Definition: calendar.h:436
virtual U_I18N_API int32_t handleComputeJulianDay(UCalendarDateFields bestField, UErrorCode &status)
Subclasses may override this.
virtual U_I18N_API bool operator==(const Calendar &that) const
Compares the equality of two Calendar objects.
U_I18N_API void setTimeInMillis(double millis, UErrorCode &status)
Sets this Calendar's current time from the given long value.
virtual U_I18N_API void computeTime(UErrorCode &status)
Converts Calendar's time field values to GMT as milliseconds.
static U_I18N_API StringEnumeration * getKeywordValuesForLocale(const char *key, const Locale &locale, UBool commonlyUsed, UErrorCode &status)
Given a key and a locale, returns an array of string values in a preferred order that would make a di...
static U_I18N_API Calendar * createInstance(const TimeZone &zone, UErrorCode &success)
Creates a Calendar using the given timezone and the default locale.
virtual U_I18N_API void roll(UCalendarDateFields field, int32_t amount, UErrorCode &status)
Time Field Rolling function.
U_I18N_API Calendar(TimeZone *zone, const Locale &aLocale, UErrorCode &success)
Constructs a Calendar with the given time zone and locale.
virtual U_I18N_API int32_t getMaximum(UCalendarDateFields field) const
Gets the maximum value for the given time field.
U_I18N_API UBool before(const Calendar &when, UErrorCode &status) const
Returns true if this Calendar's current time is before "when"'s current time.
virtual U_I18N_API const char * getType() const =0
Returns the calendar type name string for this Calendar object.
U_I18N_API UBool isLenient() const
Tells whether date/time interpretation is to be lenient.
U_I18N_API void set(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute)
Sets the values for the fields YEAR, MONTH, DATE, HOUR_OF_DAY, and MINUTE.
virtual U_I18N_API int32_t handleGetExtendedYear(UErrorCode &status)=0
Return the extended year defined by the current fields.
virtual U_I18N_API const UFieldResolutionTable * getFieldResolutionTable() const
virtual U_I18N_API void roll(EDateFields field, int32_t amount, UErrorCode &status)
Time Field Rolling function.
virtual U_I18N_API int32_t getActualMinimum(UCalendarDateFields field, UErrorCode &status) const
Return the minimum value that this field could have, given the current date.
U_I18N_API int32_t computeZoneOffset(double millis, double millisInDay, UErrorCode &ec)
This method can assume EXTENDED_YEAR has been set.
virtual U_I18N_API int32_t handleGetExtendedYearFromWeekFields(int32_t yearWoy, int32_t woy, UErrorCode &status)
Subclasses must override this to convert from week fields (YEAR_WOY and WEEK_OF_YEAR) to an extended ...
EDaysOfWeek
Useful constant for days of week.
Definition: calendar.h:243
U_I18N_API UCalendarDateFields newerField(UCalendarDateFields defaultField, UCalendarDateFields alternateField) const
Return the field that is newer, either defaultField, or alternateField.
U_I18N_API void setLenient(UBool lenient)
Specifies whether or not date/time interpretation is to be lenient.
U_I18N_API int32_t getActualMinimum(EDateFields field, UErrorCode &status) const
Return the minimum value that this field could have, given the current date.
virtual U_I18N_API int32_t internalGetMonth(int32_t defaultValue, UErrorCode &status) const
Use this function instead of internalGet(UCAL_MONTH, defaultValue).
U_I18N_API UCalendarDateFields resolveFields(const UFieldResolutionTable *precedenceTable) const
Given a precedence table, return the newest field combination in the table, or UCAL_FIELD_COUNT if no...
U_I18N_API TimeZone * orphanTimeZone()
Returns the time zone owned by this calendar.
virtual U_I18N_API const char * getTemporalMonthCode(UErrorCode &status) const
Gets The Temporal monthCode value corresponding to the month for the date.
EDateFields
Field IDs for date and time.
Definition: calendar.h:198
U_I18N_API double getTimeInMillis(UErrorCode &status) const
Gets this Calendar's current time as a long.
U_I18N_API void setFirstDayOfWeek(UCalendarDaysOfWeek value)
Sets what the first day of the week is; e.g., Sunday in US, Monday in France.
U_I18N_API void internalSetTime(UDate time)
Set the current time without affecting flags or fields.
Definition: calendar.h:1928
virtual U_I18N_API void pinField(UCalendarDateFields field, UErrorCode &status)
Adjust the specified field so that it is within the allowable range for the date to which this calend...
ELimitType
Limit enums.
Definition: calendar.h:1643
static U_I18N_API Calendar * createInstance(const TimeZone &zone, const Locale &aLocale, UErrorCode &success)
Gets a Calendar using the given timezone and given locale.
virtual U_I18N_API int32_t fieldDifference(UDate when, UCalendarDateFields field, UErrorCode &status)
Return the difference between the given time and the time this calendar object is set to.
U_I18N_API UCalendarWallTimeOption getSkippedWallTimeOption() const
Gets the behavior for handling skipped wall time at positive time zone offset transitions.
static U_I18N_API Calendar * createInstance(const Locale &aLocale, UErrorCode &success)
Creates a Calendar using the default timezone and the given locale.
U_I18N_API int32_t internalGet(UCalendarDateFields field) const
Gets the value for a given time field.
Definition: calendar.h:1561
U_I18N_API void clear()
Clears the values of all the time fields, making them both unset and assigning them a value of zero.
virtual U_I18N_API void add(UCalendarDateFields field, int32_t amount, UErrorCode &status)
UDate Arithmetic function.
virtual U_I18N_API int32_t handleGetMonthLength(int32_t extendedYear, int32_t month, UErrorCode &status) const
Return the number of days in the given month of the given extended year of this calendar system.
virtual U_I18N_API UCalendarWeekdayType getDayOfWeekType(UCalendarDaysOfWeek dayOfWeek, UErrorCode &status) const
Returns whether the given day of the week is a weekday, a weekend day, or a day that transitions from...
U_I18N_API bool operator!=(const Calendar &that) const
Compares the inequality of two Calendar objects.
Definition: calendar.h:471
virtual U_I18N_API int32_t getMinimum(UCalendarDateFields field) const
Gets the minimum value for the given time field.
static U_I18N_API uint8_t julianDayToDayOfWeek(int32_t julian)
Convert a quasi Julian date to the day of the week.
virtual U_I18N_API Calendar * clone() const =0
Create and return a polymorphic copy of this calendar.
U_I18N_API int32_t weekNumber(int32_t desiredDay, int32_t dayOfPeriod, int32_t dayOfWeek)
Return the week number of a day, within a period.
U_I18N_API void internalSet(EDateFields field, int32_t value)
Sets the value for a given time field.
virtual U_I18N_API int32_t getLeastMaximum(UCalendarDateFields field) const
Gets the lowest maximum value for the given field if varies.
U_I18N_API void set(int32_t year, int32_t month, int32_t date)
Sets the values for the fields YEAR, MONTH, and DATE.
virtual U_I18N_API bool isEra0CountingBackward() const
The year in this calendar is counting from 1 backward if the era is 0.
Definition: calendar.h:1568
virtual U_I18N_API int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const =0
Subclass API for defining limits of different types.
virtual U_I18N_API int32_t defaultCenturyStartYear() const =0
U_I18N_API UBool isSet(UCalendarDateFields field) const
Determines if the given time field has a value set.
virtual U_I18N_API void setRelatedYear(int32_t year)
virtual U_I18N_API UBool inDaylightTime(UErrorCode &status) const
Queries if the current date for this Calendar is in Daylight Savings Time.
U_I18N_API int32_t internalGet(UCalendarDateFields field, int32_t defaultValue) const
Gets the value for a given time field.
Definition: calendar.h:1549
static U_I18N_API Calendar * createInstance(TimeZone *zoneToAdopt, const Locale &aLocale, UErrorCode &success)
Creates a Calendar using the given timezone and given locale.
U_I18N_API int32_t internalGet(EDateFields field) const
Gets the value for a given time field.
Definition: calendar.h:1535
U_I18N_API UCalendarWallTimeOption getRepeatedWallTimeOption() const
Gets the behavior for handling wall time repeating multiple times at negative time zone offset transi...
virtual U_I18N_API int32_t getRelatedYear(UErrorCode &status) const
virtual U_I18N_API UBool isWeekend() const
Returns true if this Calendar's current date-time is in the weekend in this calendar system.
U_I18N_API UCalendarDaysOfWeek getFirstDayOfWeek(UErrorCode &status) const
Gets what the first day of the week is; e.g., Sunday in US, Monday in France.
virtual U_I18N_API void prepareGetActual(UCalendarDateFields field, UBool isMinimum, UErrorCode &status)
Prepare this calendar for computing the actual minimum or maximum.
virtual U_I18N_API int32_t handleGetYearLength(int32_t eyear, UErrorCode &status) const
Return the number of days in the given extended year of this calendar system.
U_I18N_API int32_t getGregorianDayOfYear() const
Return the day of year (1-based) on the Gregorian calendar as computed by computeGregorianFields().
Definition: calendar.h:2005
virtual U_I18N_API int32_t internalGetMonth(UErrorCode &status) const
Use this function instead of internalGet(UCAL_MONTH).
virtual U_I18N_API UBool isEquivalentTo(const Calendar &other) const
Returns true if the given Calendar object is equivalent to this one.
virtual U_I18N_API UBool haveDefaultCentury() const =0
virtual U_I18N_API int64_t handleComputeMonthStart(int32_t eyear, int32_t month, UBool useMonth, UErrorCode &status) const =0
Return the Julian day number of day before the first day of the given month in the given extended yea...
virtual U_I18N_API ~Calendar()
destructor
U_I18N_API int32_t getGregorianMonth() const
Return the month (0-based) on the Gregorian calendar as computed by computeGregorianFields().
Definition: calendar.h:1996
virtual U_I18N_API int32_t getMinimum(EDateFields field) const
Gets the minimum value for the given time field.
U_I18N_API Calendar & operator=(const Calendar &right)
Default assignment operator.
virtual U_I18N_API int32_t getDefaultDayInMonth(int32_t eyear, int32_t month, UErrorCode &status)
Called by computeJulianDay.
virtual U_I18N_API void computeFields(UErrorCode &status)
Converts GMT as milliseconds to time field values.
virtual U_I18N_API bool inTemporalLeapYear(UErrorCode &status) const
Returns true if the date is in a leap year.
U_I18N_API void setMinimalDaysInFirstWeek(uint8_t value)
Sets what the minimal days required in the first week of the year are; For example,...
virtual U_I18N_API void add(EDateFields field, int32_t amount, UErrorCode &status)
UDate Arithmetic function.
U_I18N_API const TimeZone & getTimeZone() const
Returns a reference to the time zone owned by this calendar.
virtual U_I18N_API UDate defaultCenturyStart() const =0
U_I18N_API void clear(UCalendarDateFields field)
Clears the value in the given time field, both making it unset and assigning it a value of zero.
virtual U_I18N_API int32_t fieldDifference(UDate when, EDateFields field, UErrorCode &status)
Return the difference between the given time and the time this calendar object is set to.
U_I18N_API uint8_t getMinimalDaysInFirstWeek() const
Gets what the minimal days required in the first week of the year are; e.g., if the first week is def...
virtual U_I18N_API int32_t getGreatestMinimum(EDateFields field) const
Gets the highest minimum value for the given field if varies.
U_I18N_API UBool equals(const Calendar &when, UErrorCode &status) const
Compares the Calendar time, whereas Calendar::operator== compares the equality of Calendar objects.
U_I18N_API void setSkippedWallTimeOption(UCalendarWallTimeOption option)
Sets the behavior for handling skipped wall time at positive time zone offset transitions.
static U_I18N_API Calendar * createInstance(UErrorCode &success)
Creates a Calendar using the default timezone and locale.
U_I18N_API Calendar(const Calendar &source)
Copy constructor.
EAmpm
Useful constants for hour in 12-hour clock.
Definition: calendar.h:277
virtual U_I18N_API int32_t getLimit(UCalendarDateFields field, ELimitType limitType) const
Return a limit for a field.
U_I18N_API void complete(UErrorCode &status)
Recomputes the current time from currently set fields, and then fills in any unset fields in the time...
U_I18N_API void set(UCalendarDateFields field, int32_t value)
Sets the given time field with the given value.
U_I18N_API void setTime(UDate date, UErrorCode &status)
Sets this Calendar's current time with the given UDate.
Definition: calendar.h:448
U_I18N_API UDate internalGetTime() const
Get the current time without recomputing.
Definition: calendar.h:1919
virtual U_I18N_API int32_t getGreatestMinimum(UCalendarDateFields field) const
Gets the highest minimum value for the given field if varies.
U_I18N_API int32_t getGregorianDayOfMonth() const
Return the day of month (1-based) on the Gregorian calendar as computed by computeGregorianFields().
Definition: calendar.h:2014
virtual U_I18N_API int32_t getActualMaximum(UCalendarDateFields field, UErrorCode &status) const
Return the maximum value that this field could have, given the current date.
U_I18N_API int32_t getLocalDOW(UErrorCode &status)
returns the local DOW, valid range 0..6
U_I18N_API UBool after(const Calendar &when, UErrorCode &status) const
Returns true if this Calendar's current time is after "when"'s current time.
U_I18N_API EDaysOfWeek getFirstDayOfWeek() const
Gets what the first day of the week is; e.g., Sunday in US, Monday in France.
U_I18N_API void setTimeZone(const TimeZone &zone)
Sets the calendar's time zone to be the same as the one passed in.
static U_I18N_API const Locale * getAvailableLocales(int32_t &count)
Returns a list of the locales for which Calendars are installed.
virtual U_I18N_API int32_t getDefaultMonthInYear(int32_t eyear, UErrorCode &status)
Called by computeJulianDay.
U_I18N_API Calendar(UErrorCode &success)
Constructs a Calendar with the default time zone as returned by TimeZone::createInstance(),...
virtual U_I18N_API void validateField(UCalendarDateFields field, UErrorCode &status)
Validate a single field of this calendar.
virtual U_I18N_API void handleComputeFields(int32_t julianDay, UErrorCode &status)
Subclasses may override this method to compute several fields specific to each calendar system.
U_I18N_API Calendar(const TimeZone &zone, const Locale &aLocale, UErrorCode &success)
Constructs a Calendar with the given time zone and locale.
EMonths
Useful constants for month.
Definition: calendar.h:257
virtual U_I18N_API int32_t getMaximum(EDateFields field) const
Gets the maximum value for the given time field.
U_I18N_API void computeGregorianFields(int32_t julianDay, UErrorCode &ec)
Compute the Gregorian calendar year, month, and day of month from the Julian day.
virtual U_I18N_API void setTemporalMonthCode(const char *temporalMonth, UErrorCode &status)
Sets The Temporal monthCode which is a string identifier that starts with the literal grapheme "M" fo...
U_I18N_API int32_t newestStamp(UCalendarDateFields start, UCalendarDateFields end, int32_t bestSoFar) const
Determine the best stamp in a range.
virtual U_I18N_API UBool isWeekend(UDate date, UErrorCode &status) const
Returns true if the given UDate is in the weekend in this calendar system.
static U_I18N_API UDate getNow()
Returns the current UTC (GMT) time measured in milliseconds since 0:00:00 on 1/1/70 (derived from the...
U_I18N_API int32_t get(UCalendarDateFields field, UErrorCode &status) const
Gets the value for a given time field.
virtual U_I18N_API int32_t getRelatedYearDifference() const
Related year difference.
U_I18N_API const char * getLocaleID(ULocDataLocaleType type, UErrorCode &status) const
Get the locale for this calendar object.
static U_I18N_API Calendar * makeInstance(const Locale &locale, UErrorCode &status)
Creates a new Calendar from a Locale for the cache.
virtual U_I18N_API int32_t getWeekendTransition(UCalendarDaysOfWeek dayOfWeek, UErrorCode &status) const
Returns the time during the day at which the weekend begins or ends in this calendar system.
A Locale object represents a specific geographical, political, or cultural region.
Definition: locid.h:198
Base class for 'pure' C++ implementations of uenum api.
Definition: strenum.h:61
TimeZone represents a time zone offset, and also figures out daylight savings.
Definition: timezone.h:133
UObject is the common ICU "boilerplate" class.
Definition: uobject.h:222
C++ API: Locale ID object.
int32_t UFieldResolutionTable[12][8]
Definition: calendar.h:48
U_COMMON_API UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
C++ API: TimeZone object.
C API: Calendar.
UCalendarDateFields
Possible fields in a UCalendar.
Definition: ucal.h:202
@ UCAL_FIELD_COUNT
One more than the highest normal UCalendarDateFields value.
Definition: ucal.h:477
UCalendarWallTimeOption
Options for handling ambiguous wall time at time zone offset transitions.
Definition: ucal.h:991
UCalendarWeekdayType
Weekday types, as returned by ucal_getDayOfWeekType().
Definition: ucal.h:1455
UCalendarDaysOfWeek
Useful constant for days of week.
Definition: ucal.h:502
ULocDataLocaleType
Constants for *_getLocale() Allow user to select whether she wants information on requested,...
Definition: uloc.h:338
int8_t UBool
The ICU boolean type, a signed-byte integer.
Definition: umachine.h:269
C API: Miscellaneous definitions.
const void * URegistryKey
Opaque type returned by registerInstance, registerFactory and unregister for service registration.
Definition: umisc.h:57
C++ API: Common ICU base class UObject.
void * UClassID
UClassID is used to identify classes without using the compiler's RTTI.
Definition: uobject.h:96
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Standard ICU4C error code type, a substitute for exceptions.
Definition: utypes.h:509
#define U_I18N_API_CLASS
Set to export library symbols from inside the i18n library, and to import them from outside,...
Definition: utypes.h:457
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition: utypes.h:316
double UDate
Date and Time data type.
Definition: utypes.h:218