ICU 74.2 74.2
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
46U_NAMESPACE_BEGIN
47
48class 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)
55typedef int32_t UFieldResolutionTable[12][8];
56
57class BasicTimeZone;
190public:
191#ifndef U_FORCE_HIDE_DEPRECATED_API
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
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
287 virtual ~Calendar();
288
295 virtual Calendar* clone() const = 0;
296
308 static Calendar* U_EXPORT2 createInstance(UErrorCode& success);
309
322 static Calendar* U_EXPORT2 createInstance(TimeZone* zoneToAdopt, UErrorCode& success);
323
335 static Calendar* U_EXPORT2 createInstance(const TimeZone& zone, UErrorCode& success);
336
347 static Calendar* U_EXPORT2 createInstance(const Locale& aLocale, UErrorCode& success);
348
362 static Calendar* U_EXPORT2 createInstance(TimeZone* zoneToAdopt, const Locale& aLocale, UErrorCode& success);
363
376 static Calendar* U_EXPORT2 createInstance(const TimeZone& zone, const Locale& aLocale, UErrorCode& success);
377
387 static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
388
389
406 static StringEnumeration* U_EXPORT2 getKeywordValuesForLocale(const char* key,
407 const Locale& locale, UBool commonlyUsed, UErrorCode& status);
408
416 static UDate U_EXPORT2 getNow(void);
417
431 inline UDate getTime(UErrorCode& status) const { return getTimeInMillis(status); }
432
443 inline void setTime(UDate date, UErrorCode& status) { setTimeInMillis(date, status); }
444
456 virtual bool operator==(const Calendar& that) const;
457
466 bool operator!=(const Calendar& that) const {return !operator==(that);}
467
478 virtual UBool isEquivalentTo(const Calendar& other) const;
479
494 UBool equals(const Calendar& when, UErrorCode& status) const;
495
509 UBool before(const Calendar& when, UErrorCode& status) const;
510
524 UBool after(const Calendar& when, UErrorCode& status) const;
525
526#ifndef U_FORCE_HIDE_DEPRECATED_API
547 virtual void add(EDateFields field, int32_t amount, UErrorCode& status);
548#endif // U_FORCE_HIDE_DEPRECATED_API
549
570 virtual void add(UCalendarDateFields field, int32_t amount, UErrorCode& status);
571
572#ifndef U_HIDE_DEPRECATED_API
605 inline void roll(EDateFields field, UBool up, UErrorCode& status);
606#endif /* U_HIDE_DEPRECATED_API */
607
640 inline void roll(UCalendarDateFields field, UBool up, UErrorCode& status);
641
642#ifndef U_FORCE_HIDE_DEPRECATED_API
674 virtual void roll(EDateFields field, int32_t amount, UErrorCode& status);
675#endif // U_FORCE_HIDE_DEPRECATED_API
676
708 virtual void roll(UCalendarDateFields field, int32_t amount, UErrorCode& status);
709
710#ifndef U_FORCE_HIDE_DEPRECATED_API
766 virtual int32_t fieldDifference(UDate when, EDateFields field, UErrorCode& status);
767#endif // U_FORCE_HIDE_DEPRECATED_API
768
824 virtual int32_t fieldDifference(UDate when, UCalendarDateFields field, UErrorCode& status);
825
835
843 void setTimeZone(const TimeZone& zone);
844
853 const TimeZone& getTimeZone(void) const;
854
864
873 virtual UBool inDaylightTime(UErrorCode& status) const;
874
887 void setLenient(UBool lenient);
888
895 UBool isLenient(void) const;
896
918
929
952
964
972
973#ifndef U_HIDE_DEPRECATED_API
981#endif /* U_HIDE_DEPRECATED_API */
982
991
1001 void setMinimalDaysInFirstWeek(uint8_t value);
1002
1012 uint8_t getMinimalDaysInFirstWeek(void) const;
1013
1014#ifndef U_FORCE_HIDE_DEPRECATED_API
1023 virtual int32_t getMinimum(EDateFields field) const;
1024#endif // U_FORCE_HIDE_DEPRECATED_API
1025
1034 virtual int32_t getMinimum(UCalendarDateFields field) const;
1035
1036#ifndef U_FORCE_HIDE_DEPRECATED_API
1045 virtual int32_t getMaximum(EDateFields field) const;
1046#endif // U_FORCE_HIDE_DEPRECATED_API
1047
1056 virtual int32_t getMaximum(UCalendarDateFields field) const;
1057
1058#ifndef U_FORCE_HIDE_DEPRECATED_API
1067 virtual int32_t getGreatestMinimum(EDateFields field) const;
1068#endif // U_FORCE_HIDE_DEPRECATED_API
1069
1078 virtual int32_t getGreatestMinimum(UCalendarDateFields field) const;
1079
1080#ifndef U_FORCE_HIDE_DEPRECATED_API
1089 virtual int32_t getLeastMaximum(EDateFields field) const;
1090#endif // U_FORCE_HIDE_DEPRECATED_API
1091
1100 virtual int32_t getLeastMaximum(UCalendarDateFields field) const;
1101
1102#ifndef U_HIDE_DEPRECATED_API
1117 int32_t getActualMinimum(EDateFields field, UErrorCode& status) const;
1118#endif /* U_HIDE_DEPRECATED_API */
1119
1134 virtual int32_t getActualMinimum(UCalendarDateFields field, UErrorCode& status) const;
1135
1152 virtual int32_t getActualMaximum(UCalendarDateFields field, UErrorCode& status) const;
1153
1167 int32_t get(UCalendarDateFields field, UErrorCode& status) const;
1168
1178
1186 void set(UCalendarDateFields field, int32_t value);
1187
1198 void set(int32_t year, int32_t month, int32_t date);
1199
1212 void set(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute);
1213
1227 void set(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, int32_t second);
1228
1235 void clear(void);
1236
1247
1263 virtual UClassID getDynamicClassID(void) const override = 0;
1264
1297 virtual const char * getType() const = 0;
1298
1316
1331 virtual int32_t getWeekendTransition(UCalendarDaysOfWeek dayOfWeek, UErrorCode &status) const;
1332
1342 virtual UBool isWeekend(UDate date, UErrorCode &status) const;
1343
1351 virtual UBool isWeekend(void) const;
1352
1353#ifndef U_FORCE_HIDE_DRAFT_API
1368 virtual bool inTemporalLeapYear(UErrorCode& status) const;
1369
1388 virtual const char* getTemporalMonthCode(UErrorCode& status) const;
1389
1409 virtual void setTemporalMonthCode(const char* temporalMonth, UErrorCode& status);
1410
1411#endif // U_FORCE_HIDE_DRAFT_API
1412
1413protected:
1414
1424
1431 Calendar(const Calendar& source);
1432
1440
1451 Calendar(TimeZone* zone, const Locale& aLocale, UErrorCode& success);
1452
1462 Calendar(const TimeZone& zone, const Locale& aLocale, UErrorCode& success);
1463
1472 virtual void computeTime(UErrorCode& status);
1473
1485 virtual void computeFields(UErrorCode& status);
1486
1496 double getTimeInMillis(UErrorCode& status) const;
1497
1506 void setTimeInMillis( double millis, UErrorCode& status );
1507
1517 void complete(UErrorCode& status);
1518
1519#ifndef U_HIDE_DEPRECATED_API
1528 inline int32_t internalGet(EDateFields field) const {return fFields[field];}
1529#endif /* U_HIDE_DEPRECATED_API */
1530
1531#ifndef U_HIDE_INTERNAL_API
1542 inline int32_t internalGet(UCalendarDateFields field, int32_t defaultValue) const {return fStamp[field]>kUnset ? fFields[field] : defaultValue;}
1543
1552 inline int32_t internalGet(UCalendarDateFields field) const {return fFields[field];}
1553#endif /* U_HIDE_INTERNAL_API */
1554
1564 virtual int32_t internalGetMonth() const;
1565
1577 virtual int32_t internalGetMonth(int32_t defaultValue) const;
1578
1579#ifndef U_HIDE_DEPRECATED_API
1589 void internalSet(EDateFields field, int32_t value);
1590#endif /* U_HIDE_DEPRECATED_API */
1591
1601 inline void internalSet(UCalendarDateFields field, int32_t value);
1602
1609 virtual void prepareGetActual(UCalendarDateFields field, UBool isMinimum, UErrorCode &status);
1610
1616#ifndef U_HIDE_INTERNAL_API
1617 UCAL_LIMIT_MINIMUM = 0,
1618 UCAL_LIMIT_GREATEST_MINIMUM,
1619 UCAL_LIMIT_LEAST_MAXIMUM,
1620 UCAL_LIMIT_MAXIMUM,
1621 UCAL_LIMIT_COUNT
1622#endif /* U_HIDE_INTERNAL_API */
1623 };
1624
1646 virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const = 0;
1647
1655 virtual int32_t getLimit(UCalendarDateFields field, ELimitType limitType) const;
1656
1670 virtual int32_t handleComputeMonthStart(int32_t eyear, int32_t month,
1671 UBool useMonth) const = 0;
1672
1680 virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month) const ;
1681
1689 virtual int32_t handleGetYearLength(int32_t eyear) const;
1690
1691
1700 virtual int32_t handleGetExtendedYear() = 0;
1701
1711
1720 virtual int32_t handleGetExtendedYearFromWeekFields(int32_t yearWoy, int32_t woy);
1721
1728 virtual void validateField(UCalendarDateFields field, UErrorCode &status);
1729
1730#ifndef U_HIDE_INTERNAL_API
1738
1747
1757 int32_t computeZoneOffset(double millis, double millisInDay, UErrorCode &ec);
1758
1759
1768 int32_t newestStamp(UCalendarDateFields start, UCalendarDateFields end, int32_t bestSoFar) const;
1769
1776 static constexpr int32_t kResolveSTOP = -1;
1786 static constexpr int32_t kResolveRemap = 32;
1787
1793 static const UFieldResolutionTable kDatePrecedence[];
1794
1800 static const UFieldResolutionTable kYearPrecedence[];
1801
1807 static const UFieldResolutionTable kDOWPrecedence[];
1808
1814 static const UFieldResolutionTable kMonthPrecedence[];
1815
1843 UCalendarDateFields resolveFields(const UFieldResolutionTable *precedenceTable) const;
1844#endif /* U_HIDE_INTERNAL_API */
1845
1846
1851
1852#ifndef U_HIDE_INTERNAL_API
1859#endif /* U_HIDE_INTERNAL_API */
1860
1861
1862private:
1871 int32_t getActualHelper(UCalendarDateFields field, int32_t startValue, int32_t endValue, UErrorCode &status) const;
1872
1873
1874protected:
1880
1892
1899
1908
1915 UDate internalGetTime(void) const { return fTime; }
1916
1924 void internalSetTime(UDate time) { fTime = time; }
1925
1930 int32_t fFields[UCAL_FIELD_COUNT];
1931
1932#ifndef U_FORCE_HIDE_DEPRECATED_API
1938#endif // U_FORCE_HIDE_DEPRECATED_API
1939
1943 enum {
1944 kUnset = 0,
1945 kInternallySet,
1946 kMinimumUserStamp
1947 };
1948
1955 int32_t fStamp[UCAL_FIELD_COUNT];
1956
1981 virtual void handleComputeFields(int32_t julianDay, UErrorCode &status);
1982
1983#ifndef U_HIDE_INTERNAL_API
1989 int32_t getGregorianYear() const {
1990 return fGregorianYear;
1991 }
1992
1998 int32_t getGregorianMonth() const {
1999 return fGregorianMonth;
2000 }
2001
2007 int32_t getGregorianDayOfYear() const {
2008 return fGregorianDayOfYear;
2009 }
2010
2016 int32_t getGregorianDayOfMonth() const {
2017 return fGregorianDayOfMonth;
2018 }
2019#endif /* U_HIDE_INTERNAL_API */
2020
2027 virtual int32_t getDefaultMonthInYear(int32_t eyear) ;
2028
2029
2037 virtual int32_t getDefaultDayInMonth(int32_t eyear, int32_t month);
2038
2039 //-------------------------------------------------------------------------
2040 // Protected utility methods for use by subclasses. These are very handy
2041 // for implementing add, roll, and computeFields.
2042 //-------------------------------------------------------------------------
2043
2073 virtual void pinField(UCalendarDateFields field, UErrorCode& status);
2074
2118 int32_t weekNumber(int32_t desiredDay, int32_t dayOfPeriod, int32_t dayOfWeek);
2119
2120
2121#ifndef U_HIDE_INTERNAL_API
2152 inline int32_t weekNumber(int32_t dayOfPeriod, int32_t dayOfWeek);
2153
2158 int32_t getLocalDOW();
2159#endif /* U_HIDE_INTERNAL_API */
2160
2161private:
2162
2166 int32_t fNextStamp;// = MINIMUM_USER_STAMP;
2167
2172 void recalculateStamp();
2173
2177 UDate fTime;
2178
2182 UBool fLenient;
2183
2188 TimeZone* fZone;
2189
2194 UCalendarWallTimeOption fRepeatedWallTime;
2195
2200 UCalendarWallTimeOption fSkippedWallTime;
2201
2210 UCalendarDaysOfWeek fFirstDayOfWeek;
2211 uint8_t fMinimalDaysInFirstWeek;
2212 UCalendarDaysOfWeek fWeekendOnset;
2213 int32_t fWeekendOnsetMillis;
2214 UCalendarDaysOfWeek fWeekendCease;
2215 int32_t fWeekendCeaseMillis;
2216
2227 void setWeekData(const Locale& desiredLocale, const char *type, UErrorCode& success);
2228
2238 void updateTime(UErrorCode& status);
2239
2245 int32_t fGregorianYear;
2246
2252 int32_t fGregorianMonth;
2253
2259 int32_t fGregorianDayOfYear;
2260
2266 int32_t fGregorianDayOfMonth;
2267
2268 /* calculations */
2269
2276 void computeGregorianAndDOWFields(int32_t julianDay, UErrorCode &ec);
2277
2278protected:
2279
2287 void computeGregorianFields(int32_t julianDay, UErrorCode &ec);
2288
2289private:
2290
2311 void computeWeekFields(UErrorCode &ec);
2312
2313
2321 void validateFields(UErrorCode &status);
2322
2330 void validateField(UCalendarDateFields field, int32_t min, int32_t max, UErrorCode& status);
2331
2332 protected:
2333#ifndef U_HIDE_INTERNAL_API
2343 static uint8_t julianDayToDayOfWeek(double julian);
2344#endif /* U_HIDE_INTERNAL_API */
2345
2346 private:
2347 char validLocale[ULOC_FULLNAME_CAPACITY];
2348 char actualLocale[ULOC_FULLNAME_CAPACITY];
2349
2350 public:
2351#if !UCONFIG_NO_SERVICE
2356#ifndef U_HIDE_INTERNAL_API
2364
2378 static URegistryKey registerFactory(ICUServiceFactory* toAdopt, UErrorCode& status);
2379
2396#endif /* U_HIDE_INTERNAL_API */
2397
2402 friend class CalendarFactory;
2403
2408 friend class CalendarService;
2409
2414 friend class DefaultCalendarFactory;
2415#endif /* !UCONFIG_NO_SERVICE */
2416
2421 virtual UBool haveDefaultCentury() const = 0;
2422
2427 virtual UDate defaultCenturyStart() const = 0;
2432 virtual int32_t defaultCenturyStartYear() const = 0;
2433
2441
2447 virtual int32_t getRelatedYear(UErrorCode &status) const;
2448
2454 virtual void setRelatedYear(int32_t year);
2455
2456#ifndef U_HIDE_INTERNAL_API
2463 const char* getLocaleID(ULocDataLocaleType type, UErrorCode &status) const;
2464#endif /* U_HIDE_INTERNAL_API */
2465
2466private:
2471 BasicTimeZone* getBasicTimeZone() const;
2472
2480 UBool getImmediatePreviousZoneTransition(UDate base, UDate *transitionTime, UErrorCode& status) const;
2481
2482public:
2483#ifndef U_HIDE_INTERNAL_API
2492 static Calendar * U_EXPORT2 makeInstance(
2493 const Locale &locale, UErrorCode &status);
2494
2505 static void U_EXPORT2 getCalendarTypeFromLocale(
2506 const Locale &locale,
2507 char *typeBuffer,
2508 int32_t typeBufferSize,
2509 UErrorCode &status);
2510#endif /* U_HIDE_INTERNAL_API */
2511};
2512
2513// -------------------------------------
2514
2515inline Calendar*
2516Calendar::createInstance(TimeZone* zone, UErrorCode& errorCode)
2517{
2518 // since the Locale isn't specified, use the default locale
2519 return createInstance(zone, Locale::getDefault(), errorCode);
2520}
2521
2522// -------------------------------------
2523
2524inline void
2525Calendar::roll(UCalendarDateFields field, UBool up, UErrorCode& status)
2526{
2527 roll(field, (int32_t)(up ? +1 : -1), status);
2528}
2529
2530#ifndef U_HIDE_DEPRECATED_API
2531inline void
2532Calendar::roll(EDateFields field, UBool up, UErrorCode& status)
2533{
2534 roll((UCalendarDateFields) field, up, status);
2535}
2536#endif /* U_HIDE_DEPRECATED_API */
2537
2538
2539// -------------------------------------
2540
2546inline void
2547Calendar::internalSet(UCalendarDateFields field, int32_t value)
2548{
2549 fFields[field] = value;
2550 fStamp[field] = kInternallySet;
2551 fIsSet[field] = true; // Remove later
2552}
2553
2554
2555#ifndef U_HIDE_INTERNAL_API
2556inline int32_t Calendar::weekNumber(int32_t dayOfPeriod, int32_t dayOfWeek)
2557{
2558 return weekNumber(dayOfPeriod, dayOfPeriod, dayOfWeek);
2559}
2560#endif /* U_HIDE_INTERNAL_API */
2561
2562U_NAMESPACE_END
2563
2564#endif /* #if !UCONFIG_NO_FORMATTING */
2565
2566#endif /* U_SHOW_CPLUSPLUS_API */
2567
2568#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
UBool after(const Calendar &when, UErrorCode &status) const
Returns true if this Calendar's current time is after "when"'s current time.
virtual int32_t getGreatestMinimum(EDateFields field) const
Gets the highest minimum value for the given field if varies.
UBool fIsTimeSet
The flag which indicates if the current time is set in the calendar.
Definition calendar.h:1879
void setTime(UDate date, UErrorCode &status)
Sets this Calendar's current time with the given UDate.
Definition calendar.h:443
void setSkippedWallTimeOption(UCalendarWallTimeOption option)
Sets the behavior for handling skipped wall time at positive time zone offset transitions.
int32_t internalGet(UCalendarDateFields field) const
Gets the value for a given time field.
Definition calendar.h:1552
int32_t newestStamp(UCalendarDateFields start, UCalendarDateFields end, int32_t bestSoFar) const
Determine the best stamp in a range.
void set(UCalendarDateFields field, int32_t value)
Sets the given time field with the given value.
UCalendarWallTimeOption getRepeatedWallTimeOption(void) const
Gets the behavior for handling wall time repeating multiple times at negative time zone offset transi...
Locale getLocale(ULocDataLocaleType type, UErrorCode &status) const
Get the locale for this calendar object.
virtual const char * getTemporalMonthCode(UErrorCode &status) const
Gets The Temporal monthCode value corresponding to the month for the date.
int32_t get(UCalendarDateFields field, UErrorCode &status) const
Gets the value for a given time field.
virtual int32_t getMinimum(EDateFields field) const
Gets the minimum value for the given time field.
int32_t getLocalDOW()
returns the local DOW, valid range 0..6
virtual void roll(UCalendarDateFields field, int32_t amount, UErrorCode &status)
Time Field Rolling function.
virtual UClassID getDynamicClassID(void) const override=0
Returns a unique class ID POLYMORPHICALLY.
virtual 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.
int32_t weekNumber(int32_t desiredDay, int32_t dayOfPeriod, int32_t dayOfWeek)
Return the week number of a day, within a period.
virtual int32_t getLeastMaximum(UCalendarDateFields field) const
Gets the lowest maximum value for the given field if varies.
static Calendar * createInstance(UErrorCode &success)
Creates a Calendar using the default timezone and locale.
virtual int32_t handleComputeJulianDay(UCalendarDateFields bestField)
Subclasses may override this.
void setTimeInMillis(double millis, UErrorCode &status)
Sets this Calendar's current time from the given long value.
static Calendar * createInstance(const TimeZone &zone, const Locale &aLocale, UErrorCode &success)
Gets a Calendar using the given timezone and given locale.
void complete(UErrorCode &status)
Recomputes the current time from currently set fields, and then fills in any unset fields in the time...
static void getCalendarTypeFromLocale(const Locale &locale, char *typeBuffer, int32_t typeBufferSize, UErrorCode &status)
Get the calendar type for given locale.
UBool isSet(UCalendarDateFields field) const
Determines if the given time field has a value set.
void setLenient(UBool lenient)
Specifies whether or not date/time interpretation is to be lenient.
int32_t getGregorianMonth() const
Return the month (0-based) on the Gregorian calendar as computed by computeGregorianFields().
Definition calendar.h:1998
void computeGregorianFields(int32_t julianDay, UErrorCode &ec)
Compute the Gregorian calendar year, month, and day of month from the Julian day.
int32_t getGregorianDayOfYear() const
Return the day of year (1-based) on the Gregorian calendar as computed by computeGregorianFields().
Definition calendar.h:2007
virtual UBool haveDefaultCentury() const =0
EDaysOfWeek
Useful constant for days of week.
Definition calendar.h:243
static StringEnumeration * getAvailableLocales(void)
INTERNAL FOR 2.6 – Registration.
virtual int32_t internalGetMonth(int32_t defaultValue) const
Use this function instead of internalGet(UCAL_MONTH, defaultValue).
virtual int32_t getLeastMaximum(EDateFields field) const
Gets the lowest maximum value for the given field if varies.
virtual ~Calendar()
destructor
EDateFields
Field IDs for date and time.
Definition calendar.h:198
virtual bool operator==(const Calendar &that) const
Compares the equality of two Calendar objects.
virtual void roll(EDateFields field, int32_t amount, UErrorCode &status)
Time Field Rolling function.
static Calendar * createInstance(const Locale &aLocale, UErrorCode &success)
Creates a Calendar using the default timezone and the given locale.
static Calendar * makeInstance(const Locale &locale, UErrorCode &status)
Creates a new Calendar from a Locale for the cache.
ELimitType
Limit enums.
Definition calendar.h:1615
Calendar(UErrorCode &success)
Constructs a Calendar with the default time zone as returned by TimeZone::createInstance(),...
UBool equals(const Calendar &when, UErrorCode &status) const
Compares the Calendar time, whereas Calendar::operator== compares the equality of Calendar objects.
bool operator!=(const Calendar &that) const
Compares the inequality of two Calendar objects.
Definition calendar.h:466
virtual int32_t getRelatedYear(UErrorCode &status) const
virtual Calendar * clone() const =0
Create and return a polymorphic copy of this calendar.
void clear(UCalendarDateFields field)
Clears the value in the given time field, both making it unset and assigning it a value of zero.
virtual void handleComputeFields(int32_t julianDay, UErrorCode &status)
Subclasses may override this method to compute several fields specific to each calendar system.
virtual void setTemporalMonthCode(const char *temporalMonth, UErrorCode &status)
Sets The Temporal monthCode which is a string identifier that starts with the literal grapheme "M" fo...
const TimeZone & getTimeZone(void) const
Returns a reference to the time zone owned by this calendar.
static 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...
UBool fAreFieldsVirtuallySet
True if all fields have been virtually set, but have not yet been computed.
Definition calendar.h:1907
double getTimeInMillis(UErrorCode &status) const
Gets this Calendar's current time as a long.
UCalendarDaysOfWeek getFirstDayOfWeek(UErrorCode &status) const
Gets what the first day of the week is; e.g., Sunday in US, Monday in France.
Calendar & operator=(const Calendar &right)
Default assignment operator.
static Calendar * createInstance(TimeZone *zoneToAdopt, const Locale &aLocale, UErrorCode &success)
Creates a Calendar using the given timezone and given locale.
UCalendarWallTimeOption getSkippedWallTimeOption(void) const
Gets the behavior for handling skipped wall time at positive time zone offset transitions.
int32_t internalGet(EDateFields field) const
Gets the value for a given time field.
Definition calendar.h:1528
static URegistryKey registerFactory(ICUServiceFactory *toAdopt, UErrorCode &status)
Register a new Calendar factory.
virtual int32_t getDefaultDayInMonth(int32_t eyear, int32_t month)
Called by computeJulianDay.
TimeZone * orphanTimeZone(void)
Returns the time zone owned by this calendar.
virtual const char * getType() const =0
Returns the calendar type name string for this Calendar object.
UBool fAreFieldsSet
True if the fields are in sync with the currently set time of this Calendar.
Definition calendar.h:1891
Calendar(const Calendar &source)
Copy constructor.
virtual void computeFields(UErrorCode &status)
Converts GMT as milliseconds to time field values.
virtual int32_t getActualMaximum(UCalendarDateFields field, UErrorCode &status) const
Return the maximum value that this field could have, given the current date.
static const Locale * getAvailableLocales(int32_t &count)
Returns a list of the locales for which Calendars are installed.
virtual void prepareGetActual(UCalendarDateFields field, UBool isMinimum, UErrorCode &status)
Prepare this calendar for computing the actual minimum or maximum.
virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month) const
Return the number of days in the given month of the given extended year of this calendar system.
void adoptTimeZone(TimeZone *value)
Sets the calendar's time zone to be the one passed in.
UBool before(const Calendar &when, UErrorCode &status) const
Returns true if this Calendar's current time is before "when"'s current time.
virtual int32_t defaultCenturyStartYear() const =0
void setMinimalDaysInFirstWeek(uint8_t value)
Sets what the minimal days required in the first week of the year are; For example,...
virtual UBool inDaylightTime(UErrorCode &status) const
Queries if the current date for this Calendar is in Daylight Savings Time.
virtual int32_t internalGetMonth() const
Use this function instead of internalGet(UCAL_MONTH).
const char * getLocaleID(ULocDataLocaleType type, UErrorCode &status) const
Get the locale for this calendar object.
virtual UDate defaultCenturyStart() const =0
virtual int32_t getMaximum(UCalendarDateFields field) const
Gets the maximum value for the given time field.
virtual 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...
int32_t getGregorianYear() const
Return the extended year on the Gregorian calendar as computed by computeGregorianFields().
Definition calendar.h:1989
int32_t internalGet(UCalendarDateFields field, int32_t defaultValue) const
Gets the value for a given time field.
Definition calendar.h:1542
void internalSetTime(UDate time)
Set the current time without affecting flags or fields.
Definition calendar.h:1924
static uint8_t julianDayToDayOfWeek(double julian)
Convert a quasi Julian date to the day of the week.
virtual int32_t getActualMinimum(UCalendarDateFields field, UErrorCode &status) const
Return the minimum value that this field could have, given the current date.
UDate getTime(UErrorCode &status) const
Gets this Calendar's time as milliseconds.
Definition calendar.h:431
UBool fAreAllFieldsSet
True if all of the fields have been set.
Definition calendar.h:1898
int32_t computeJulianDay()
Compute the Julian day from fields.
virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const =0
Subclass API for defining limits of different types.
virtual 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.
virtual int32_t handleGetExtendedYear()=0
Return the extended year defined by the current fields.
int32_t getActualMinimum(EDateFields field, UErrorCode &status) const
Return the minimum value that this field could have, given the current date.
UCalendarDateFields newerField(UCalendarDateFields defaultField, UCalendarDateFields alternateField) const
Return the field that is newer, either defaultField, or alternateField.
virtual UBool isEquivalentTo(const Calendar &other) const
Returns true if the given Calendar object is equivalent to this one.
double computeMillisInDay()
Compute the milliseconds in the day from the fields.
EDaysOfWeek getFirstDayOfWeek(void) const
Gets what the first day of the week is; e.g., Sunday in US, Monday in France.
virtual int32_t getGreatestMinimum(UCalendarDateFields field) const
Gets the highest minimum value for the given field if varies.
Calendar(const TimeZone &zone, const Locale &aLocale, UErrorCode &success)
Constructs a Calendar with the given time zone and locale.
static Calendar * createInstance(const TimeZone &zone, UErrorCode &success)
Creates a Calendar using the given timezone and the default locale.
void setTimeZone(const TimeZone &zone)
Sets the calendar's time zone to be the same as the one passed in.
virtual int32_t getDefaultMonthInYear(int32_t eyear)
Called by computeJulianDay.
EAmpm
Useful constants for hour in 12-hour clock.
Definition calendar.h:277
UDate internalGetTime(void) const
Get the current time without recomputing.
Definition calendar.h:1915
void internalSet(EDateFields field, int32_t value)
Sets the value for a given time field.
virtual void setRelatedYear(int32_t year)
static UDate getNow(void)
Returns the current UTC (GMT) time measured in milliseconds since 0:00:00 on 1/1/70 (derived from the...
virtual int32_t getMinimum(UCalendarDateFields field) const
Gets the minimum value for the given time field.
virtual int32_t handleGetExtendedYearFromWeekFields(int32_t yearWoy, int32_t woy)
Subclasses must override this to convert from week fields (YEAR_WOY and WEEK_OF_YEAR) to an extended ...
UCalendarDateFields resolveFields(const UFieldResolutionTable *precedenceTable) const
Given a precedence table, return the newest field combination in the table, or UCAL_FIELD_COUNT if no...
void setRepeatedWallTimeOption(UCalendarWallTimeOption option)
Sets the behavior for handling wall time repeating multiple times at negative time zone offset transi...
void setFirstDayOfWeek(UCalendarDaysOfWeek value)
Sets what the first day of the week is; e.g., Sunday in US, Monday in France.
virtual bool inTemporalLeapYear(UErrorCode &status) const
Returns true if the date is in a leap year.
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.
virtual int32_t handleComputeMonthStart(int32_t eyear, int32_t month, UBool useMonth) const =0
Return the Julian day number of day before the first day of the given month in the given extended yea...
virtual 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...
void clear(void)
Clears the values of all the time fields, making them both unset and assigning them a value of zero.
virtual int32_t handleGetYearLength(int32_t eyear) const
Return the number of days in the given extended year of this calendar system.
EMonths
Useful constants for month.
Definition calendar.h:257
virtual void computeTime(UErrorCode &status)
Converts Calendar's time field values to GMT as milliseconds.
virtual UBool isWeekend(void) const
Returns true if this Calendar's current date-time is in the weekend in this calendar system.
UBool isLenient(void) const
Tells whether date/time interpretation is to be lenient.
virtual int32_t getLimit(UCalendarDateFields field, ELimitType limitType) const
Return a limit for a field.
virtual UBool isWeekend(UDate date, UErrorCode &status) const
Returns true if the given UDate is in the weekend in this calendar system.
virtual int32_t getMaximum(EDateFields field) const
Gets the maximum value for the given time field.
virtual void add(UCalendarDateFields field, int32_t amount, UErrorCode &status)
UDate Arithmetic function.
static UBool unregister(URegistryKey key, UErrorCode &status)
Unregister a previously-registered CalendarFactory using the key returned from the register call.
virtual void validateField(UCalendarDateFields field, UErrorCode &status)
Validate a single field of this calendar.
virtual const UFieldResolutionTable * getFieldResolutionTable() const
uint8_t getMinimalDaysInFirstWeek(void) const
Gets what the minimal days required in the first week of the year are; e.g., if the first week is def...
virtual void add(EDateFields field, int32_t amount, UErrorCode &status)
UDate Arithmetic function.
int32_t getGregorianDayOfMonth() const
Return the day of month (1-based) on the Gregorian calendar as computed by computeGregorianFields().
Definition calendar.h:2016
Calendar(TimeZone *zone, const Locale &aLocale, UErrorCode &success)
Constructs a Calendar with the given time zone and locale.
int32_t computeZoneOffset(double millis, double millisInDay, UErrorCode &ec)
This method can assume EXTENDED_YEAR has been set.
void set(int32_t year, int32_t month, int32_t date)
Sets the values for the fields YEAR, MONTH, and DATE.
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 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.
A Locale object represents a specific geographical, political, or cultural region.
Definition locid.h:195
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:223
C++ API: Locale ID object.
U_EXPORT UBool operator==(const StringPiece &x, const StringPiece &y)
Global operator == for StringPiece.
int32_t UFieldResolutionTable[12][8]
Definition calendar.h:55
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:483
UCalendarWallTimeOption
Options for handling ambiguous wall time at time zone offset transitions.
Definition ucal.h:998
UCalendarWeekdayType
Weekday types, as returned by ucal_getDayOfWeekType().
Definition ucal.h:1464
UCalendarDaysOfWeek
Useful constant for days of week.
Definition ucal.h:509
#define ULOC_FULLNAME_CAPACITY
Useful constant for the maximum size of the whole locale ID (including the terminating NULL and all k...
Definition uloc.h:264
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:247
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:415
#define U_I18N_API
Set to export library symbols from inside the i18n library, and to import them from outside.
Definition utypes.h:301
double UDate
Date and Time data type.
Definition utypes.h:203