ICU 77.1  77.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;
58 class CharString;
190 class U_I18N_API Calendar : public UObject {
191 public:
192 #ifndef U_FORCE_HIDE_DEPRECATED_API
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
244  enum EDaysOfWeek {
245  SUNDAY = 1,
246  MONDAY,
247  TUESDAY,
248  WEDNESDAY,
249  THURSDAY,
250  FRIDAY,
251  SATURDAY
252  };
253 
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 
278  enum EAmpm {
279  AM,
280  PM
281  };
282 #endif /* U_HIDE_DEPRECATED_API */
283 
288  virtual ~Calendar();
289 
296  virtual Calendar* clone() const = 0;
297 
309  static Calendar* U_EXPORT2 createInstance(UErrorCode& success);
310 
323  static Calendar* U_EXPORT2 createInstance(TimeZone* zoneToAdopt, UErrorCode& success);
324 
336  static Calendar* U_EXPORT2 createInstance(const TimeZone& zone, UErrorCode& success);
337 
348  static Calendar* U_EXPORT2 createInstance(const Locale& aLocale, UErrorCode& success);
349 
363  static Calendar* U_EXPORT2 createInstance(TimeZone* zoneToAdopt, const Locale& aLocale, UErrorCode& success);
364 
377  static Calendar* U_EXPORT2 createInstance(const TimeZone& zone, const Locale& aLocale, UErrorCode& success);
378 
388  static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
389 
390 
407  static StringEnumeration* U_EXPORT2 getKeywordValuesForLocale(const char* key,
408  const Locale& locale, UBool commonlyUsed, UErrorCode& status);
409 
417  static UDate U_EXPORT2 getNow();
418 
432  inline UDate getTime(UErrorCode& status) const { return getTimeInMillis(status); }
433 
444  inline void setTime(UDate date, UErrorCode& status) { setTimeInMillis(date, status); }
445 
457  virtual bool operator==(const Calendar& that) const;
458 
467  bool operator!=(const Calendar& that) const {return !operator==(that);}
468 
479  virtual UBool isEquivalentTo(const Calendar& other) const;
480 
495  UBool equals(const