1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4  *******************************************************************************
5  * Copyright (C) 1996-2015, International Business Machines Corporation and
6  * others. All Rights Reserved.
7  *******************************************************************************
8  */
9 
10 #ifndef UCAL_H
11 #define UCAL_H
12 
13 #include "unicode/utypes.h"
14 #include "unicode/uenum.h"
15 #include "unicode/uloc.h"
16 
17 
18 #if !UCONFIG_NO_FORMATTING
19 
20 /**
21  * \file
22  * \brief C API: Calendar
23  *
24  * <h2>Calendar C API</h2>
25  *
26  * UCalendar C API is used  for converting between a <code>UDate</code> object
27  * and a set of integer fields such as <code>UCAL_YEAR</code>, <code>UCAL_MONTH</code>,
28  * <code>UCAL_DAY</code>, <code>UCAL_HOUR</code>, and so on.
29  * (A <code>UDate</code> object represents a specific instant in
30  * time with millisecond precision. See UDate
31  * for information about the <code>UDate</code> .)
32  *
33  * <p>
34  * Types of <code>UCalendar</code> interpret a <code>UDate</code>
35  * according to the rules of a specific calendar system. The C API
36  * provides the enum UCalendarType with UCAL_TRADITIONAL and
37  * UCAL_GREGORIAN.
38  * <p>
39  * Like other locale-sensitive C API, calendar API  provides a
40  * function, <code>ucal_open()</code>, which returns a pointer to
41  * <code>UCalendar</code> whose time fields have been initialized
42  * with the current date and time. We need to specify the type of
43  * calendar to be opened and the  timezoneId.
44  * \htmlonly<blockquote>\endhtmlonly
45  * <pre>
46  * \code
47  * UCalendar *caldef;
48  * UChar *tzId;
49  * UErrorCode status;
50  * tzId=(UChar*)malloc(sizeof(UChar) * (strlen("PST") +1) );
51  * u_uastrcpy(tzId, "PST");
52  * caldef=ucal_open(tzID, u_strlen(tzID), NULL, UCAL_TRADITIONAL, &status);
53  * \endcode
54  * </pre>
55  * \htmlonly</blockquote>\endhtmlonly
56  *
57  * <p>
58  * A <code>UCalendar</code> object can produce all the time field values
59  * needed to implement the date-time formatting for a particular language
60  * and calendar style (for example, Japanese-Gregorian, Japanese-Traditional).
61  *
62  * <p>
63  * When computing a <code>UDate</code> from time fields, two special circumstances
64  * may arise: there may be insufficient information to compute the
65  * <code>UDate</code> (such as only year and month but no day in the month),
66  * or there may be inconsistent information (such as "Tuesday, July 15, 1996"
67  * -- July 15, 1996 is actually a Monday).
68  *
69  * <p>
70  * <strong>Insufficient information.</strong> The calendar will use default
71  * information to specify the missing fields. This may vary by calendar; for
72  * the Gregorian calendar, the default for a field is the same as that of the
73  * start of the epoch: i.e., UCAL_YEAR = 1970, UCAL_MONTH = JANUARY, UCAL_DATE = 1, etc.
74  *
75  * <p>
76  * <strong>Inconsistent information.</strong> If fields conflict, the calendar
77  * will give preference to fields set more recently. For example, when
78  * determining the day, the calendar will look for one of the following
79  * combinations of fields.  The most recent combination, as determined by the
80  * most recently set single field, will be used.
81  *
82  * \htmlonly<blockquote>\endhtmlonly
83  * <pre>
84  * \code
85  * UCAL_MONTH + UCAL_DAY_OF_MONTH
86  * UCAL_MONTH + UCAL_WEEK_OF_MONTH + UCAL_DAY_OF_WEEK
87  * UCAL_MONTH + UCAL_DAY_OF_WEEK_IN_MONTH + UCAL_DAY_OF_WEEK
88  * UCAL_DAY_OF_YEAR
89  * UCAL_DAY_OF_WEEK + UCAL_WEEK_OF_YEAR
90  * \endcode
91  * </pre>
92  * \htmlonly</blockquote>\endhtmlonly
93  *
94  * For the time of day:
95  *
96  * \htmlonly<blockquote>\endhtmlonly
97  * <pre>
98  * \code
99  * UCAL_HOUR_OF_DAY
100  * UCAL_AM_PM + UCAL_HOUR
101  * \endcode
102  * </pre>
103  * \htmlonly</blockquote>\endhtmlonly
104  *
105  * <p>
106  * <strong>Note:</strong> for some non-Gregorian calendars, different
107  * fields may be necessary for complete disambiguation. For example, a full
108  * specification of the historical Arabic astronomical calendar requires year,
109  * month, day-of-month <em>and</em> day-of-week in some cases.
110  *
111  * <p>
112  * <strong>Note:</strong> There are certain possible ambiguities in
113  * interpretation of certain singular times, which are resolved in the
114  * following ways:
115  * <ol>
116  *     <li> 24:00:00 "belongs" to the following day. That is,
117  *          23:59 on Dec 31, 1969 &lt; 24:00 on Jan 1, 1970 &lt; 24:01:00 on Jan 1, 1970
118  *
119  *     <li> Although historically not precise, midnight also belongs to "am",
120  *          and noon belongs to "pm", so on the same day,
121  *          12:00 am (midnight) &lt; 12:01 am, and 12:00 pm (noon) &lt; 12:01 pm
122  * </ol>
123  *
124  * <p>
125  * The date or time format strings are not part of the definition of a
126  * calendar, as those must be modifiable or overridable by the user at
127  * runtime. Use {@link icu::DateFormat}
128  * to format dates.
129  *
130  * <p>
131  * <code>Calendar</code> provides an API for field "rolling", where fields
132  * can be incremented or decremented, but wrap around. For example, rolling the
133  * month up in the date <code>December 12, <b>1996</b></code> results in
134  * <code>January 12, <b>1996</b></code>.
135  *
136  * <p>
137  * <code>Calendar</code> also provides a date arithmetic function for
138  * adding the specified (signed) amount of time to a particular time field.
139  * For example, subtracting 5 days from the date <code>September 12, 1996</code>
140  * results in <code>September 7, 1996</code>.
141  *
142  * <p>
143  * The Japanese calendar uses a combination of era name and year number.
144  * When an emperor of Japan abdicates and a new emperor ascends the throne,
145  * a new era is declared and year number is reset to 1. Even if the date of
146  * abdication is scheduled ahead of time, the new era name might not be
147  * announced until just before the date. In such case, ICU4C may include
148  * a start date of future era without actual era name, but not enabled
149  * by default. ICU4C users who want to test the behavior of the future era
150  * can enable the tentative era by:
151  * <ul>
152  * <li>Environment variable <code>ICU_ENABLE_TENTATIVE_ERA=true</code>.</li>
153  * </ul>
154  *
155  * @stable ICU 2.0
156  */
157 
158 /**
159  * The time zone ID reserved for unknown time zone.
160  * It behaves like the GMT/UTC time zone but has the special ID "Etc/Unknown".
161  * @stable ICU 4.8
162  */
163 #define UCAL_UNKNOWN_ZONE_ID "Etc/Unknown"
164 
165 /** A calendar.
166  *  For usage in C programs.
167  * @stable ICU 2.0
168  */
169 typedef void* UCalendar;
170 
171 /** Possible types of UCalendars
172  * @stable ICU 2.0
173  */
174 enum UCalendarType {
175   /**
176    * Despite the name, UCAL_TRADITIONAL designates the locale's default calendar,
177    * which may be the Gregorian calendar or some other calendar.
178    * @stable ICU 2.0
179    */
180   UCAL_TRADITIONAL,
181   /**
182    * A better name for UCAL_TRADITIONAL.
183    * @stable ICU 4.2
184    */
185   UCAL_DEFAULT = UCAL_TRADITIONAL,
186   /**
187    * Unambiguously designates the Gregorian calendar for the locale.
188    * @stable ICU 2.0
189    */
190   UCAL_GREGORIAN
191 };
192 
193 /** @stable ICU 2.0 */
194 typedef enum UCalendarType UCalendarType;
195 
196 /** Possible fields in a UCalendar
197  * @stable ICU 2.0
198  */
199 enum UCalendarDateFields {
200   /**
201    * Field number indicating the era, e.g., AD or BC in the Gregorian (Julian) calendar.
202    * This is a calendar-specific value.
203    * @stable ICU 2.6
204    */
205   UCAL_ERA,
206 
207   /**
208    * Field number indicating the year. This is a calendar-specific value.
209    * @stable ICU 2.6
210    */
211   UCAL_YEAR,
212 
213   /**
214    * Field number indicating the month. This is a calendar-specific value.
215    * The first month of the year is
216    * <code>JANUARY</code>; the last depends on the number of months in a year.
217    * @see #UCAL_JANUARY
218    * @see #UCAL_FEBRUARY
219    * @see #UCAL_MARCH
220    * @see #UCAL_APRIL
221    * @see #UCAL_MAY
222    * @see #UCAL_JUNE
223    * @see #UCAL_JULY
224    * @see #UCAL_AUGUST
225    * @see #UCAL_SEPTEMBER
226    * @see #UCAL_OCTOBER
227    * @see #UCAL_NOVEMBER
228    * @see #UCAL_DECEMBER
229    * @see #UCAL_UNDECIMBER
230    * @stable ICU 2.6
231    */
232   UCAL_MONTH,
233 
234   /**
235    * Field number indicating the
236    * week number within the current year.  The first week of the year, as
237    * defined by <code>UCAL_FIRST_DAY_OF_WEEK</code> and <code>UCAL_MINIMAL_DAYS_IN_FIRST_WEEK</code>
238    * attributes, has value 1.  Subclasses define
239    * the value of <code>UCAL_WEEK_OF_YEAR</code> for days before the first week of
240    * the year.
241    * @see ucal_getAttribute
242    * @see ucal_setAttribute
243    * @stable ICU 2.6
244    */
245   UCAL_WEEK_OF_YEAR,
246 
247  /**
248    * Field number indicating the
249    * week number within the current month.  The first week of the month, as
250    * defined by <code>UCAL_FIRST_DAY_OF_WEEK</code> and <code>UCAL_MINIMAL_DAYS_IN_FIRST_WEEK</code>
251    * attributes, has value 1.  Subclasses define
252    * the value of <code>WEEK_OF_MONTH</code> for days before the first week of
253    * the month.
254    * @see ucal_getAttribute
255    * @see ucal_setAttribute
256    * @see #UCAL_FIRST_DAY_OF_WEEK
257    * @see #UCAL_MINIMAL_DAYS_IN_FIRST_WEEK
258    * @stable ICU 2.6
259    */
260   UCAL_WEEK_OF_MONTH,
261 
262  /**
263    * Field number indicating the
264    * day of the month. This is a synonym for <code>DAY_OF_MONTH</code>.
265    * The first day of the month has value 1.
266    * @see #UCAL_DAY_OF_MONTH
267    * @stable ICU 2.6
268    */
269   UCAL_DATE,
270 
271  /**
272    * Field number indicating the day
273    * number within the current year.  The first day of the year has value 1.
274    * @stable ICU 2.6
275    */
276   UCAL_DAY_OF_YEAR,
277 
278  /**
279    * Field number indicating the day
280    * of the week.  This field takes values <code>SUNDAY</code>,
281    * <code>MONDAY</code>, <code>TUESDAY</code>, <code>WEDNESDAY</code>,
282    * <code>THURSDAY</code>, <code>FRIDAY</code>, and <code>SATURDAY</code>.
283    * @see #UCAL_SUNDAY
284    * @see #UCAL_MONDAY
285    * @see #UCAL_TUESDAY
286    * @see #UCAL_WEDNESDAY
287    * @see #UCAL_THURSDAY
288    * @see #UCAL_FRIDAY
289    * @see #UCAL_SATURDAY
290    * @stable ICU 2.6
291    */
292   UCAL_DAY_OF_WEEK,
293 
294  /**
295    * Field number indicating the
296    * ordinal number of the day of the week within the current month. Together
297    * with the <code>DAY_OF_WEEK</code> field, this uniquely specifies a day
298    * within a month.  Unlike <code>WEEK_OF_MONTH</code> and
299    * <code>WEEK_OF_YEAR</code>, this field's value does <em>not</em> depend on
300    * <code>getFirstDayOfWeek()</code> or
301    * <code>getMinimalDaysInFirstWeek()</code>.  <code>DAY_OF_MONTH 1</code>
302    * through <code>7</code> always correspond to <code>DAY_OF_WEEK_IN_MONTH
303    * 1</code>; <code>8</code> through <code>15</code> correspond to
304    * <code>DAY_OF_WEEK_IN_MONTH 2</code>, and so on.
305    * <code>DAY_OF_WEEK_IN_MONTH 0</code> indicates the week before
306    * <code>DAY_OF_WEEK_IN_MONTH 1</code>.  Negative values count back from the
307    * end of the month, so the last Sunday of a month is specified as
308    * <code>DAY_OF_WEEK = SUNDAY, DAY_OF_WEEK_IN_MONTH = -1</code>.  Because
309    * negative values count backward they will usually be aligned differently
310    * within the month than positive values.  For example, if a month has 31
311    * days, <code>DAY_OF_WEEK_IN_MONTH -1</code> will overlap
312    * <code>DAY_OF_WEEK_IN_MONTH 5</code> and the end of <code>4</code>.
313    * @see #UCAL_DAY_OF_WEEK
314    * @see #UCAL_WEEK_OF_MONTH
315    * @stable ICU 2.6
316    */
317   UCAL_DAY_OF_WEEK_IN_MONTH,
318 
319  /**
320    * Field number indicating
321    * whether the <code>HOUR</code> is before or after noon.
322    * E.g., at 10:04:15.250 PM the <code>AM_PM</code> is <code>PM</code>.
323    * @see #UCAL_AM
324    * @see #UCAL_PM
325    * @see #UCAL_HOUR
326    * @stable ICU 2.6
327    */
328   UCAL_AM_PM,
329 
330  /**
331    * Field number indicating the
332    * hour of the morning or afternoon. <code>HOUR</code> is used for the 12-hour
333    * clock.
334    * E.g., at 10:04:15.250 PM the <code>HOUR</code> is 10.
335    * @see #UCAL_AM_PM
336    * @see #UCAL_HOUR_OF_DAY
337    * @stable ICU 2.6
338    */
339   UCAL_HOUR,
340 
341  /**
342    * Field number indicating the
343    * hour of the day. <code>HOUR_OF_DAY</code> is used for the 24-hour clock.
344    * E.g., at 10:04:15.250 PM the <code>HOUR_OF_DAY</code> is 22.
345    * @see #UCAL_HOUR
346    * @stable ICU 2.6
347    */
348   UCAL_HOUR_OF_DAY,
349 
350  /**
351    * Field number indicating the
352    * minute within the hour.
353    * E.g., at 10:04:15.250 PM the <code>UCAL_MINUTE</code> is 4.
354    * @stable ICU 2.6
355    */
356   UCAL_MINUTE,
357 
358  /**
359    * Field number indicating the
360    * second within the minute.
361    * E.g., at 10:04:15.250 PM the <code>UCAL_SECOND</code> is 15.
362    * @stable ICU 2.6
363    */
364   UCAL_SECOND,
365 
366  /**
367    * Field number indicating the
368    * millisecond within the second.
369    * E.g., at 10:04:15.250 PM the <code>UCAL_MILLISECOND</code> is 250.
370    * @stable ICU 2.6
371    */
372   UCAL_MILLISECOND,
373 
374  /**
375    * Field number indicating the
376    * raw offset from GMT in milliseconds.
377    * @stable ICU 2.6
378    */
379   UCAL_ZONE_OFFSET,
380 
381  /**
382    * Field number indicating the
383    * daylight savings offset in milliseconds.
384    * @stable ICU 2.6
385    */
386   UCAL_DST_OFFSET,
387 
388  /**
389    * Field number
390    * indicating the extended year corresponding to the
391    * <code>UCAL_WEEK_OF_YEAR</code> field.  This may be one greater or less
392    * than the value of <code>UCAL_EXTENDED_YEAR</code>.
393    * @stable ICU 2.6
394    */
395   UCAL_YEAR_WOY,
396 
397  /**
398    * Field number
399    * indicating the localized day of week.  This will be a value from 1
400    * to 7 inclusive, with 1 being the localized first day of the week.
401    * @stable ICU 2.6
402    */
403   UCAL_DOW_LOCAL,
404 
405   /**
406    * Year of this calendar system, encompassing all supra-year fields. For example,
407    * in Gregorian/Julian calendars, positive Extended Year values indicate years AD,
408    *  1 BC = 0 extended, 2 BC = -1 extended, and so on.
409    * @stable ICU 2.8
410    */
411   UCAL_EXTENDED_YEAR,
412 
413  /**
414    * Field number
415    * indicating the modified Julian day number.  This is different from
416    * the conventional Julian day number in two regards.  First, it
417    * demarcates days at local zone midnight, rather than noon GMT.
418    * Second, it is a local number; that is, it depends on the local time
419    * zone.  It can be thought of as a single number that encompasses all
420    * the date-related fields.
421    * @stable ICU 2.8
422    */
423   UCAL_JULIAN_DAY,
424 
425   /**
426    * Ranges from 0 to 23:59:59.999 (regardless of DST).  This field behaves <em>exactly</em>
427    * like a composite of all time-related fields, not including the zone fields.  As such,
428    * it also reflects discontinuities of those fields on DST transition days.  On a day
429    * of DST onset, it will jump forward.  On a day of DST cessation, it will jump
430    * backward.  This reflects the fact that it must be combined with the DST_OFFSET field
431    * to obtain a unique local time value.
432    * @stable ICU 2.8
433    */
434   UCAL_MILLISECONDS_IN_DAY,
435 
436   /**
437    * Whether or not the current month is a leap month (0 or 1). See the Chinese calendar for
438    * an example of this.
439    */
440   UCAL_IS_LEAP_MONTH,
441 
442  /**
443    * Field number indicating the
444    * day of the month. This is a synonym for <code>UCAL_DATE</code>.
445    * The first day of the month has value 1.
446    * @see #UCAL_DATE
447    * Synonym for UCAL_DATE
448    * @stable ICU 2.8
449    **/
450   UCAL_DAY_OF_MONTH=UCAL_DATE
451 };
452 
453 /** @stable ICU 2.0 */
454 typedef enum UCalendarDateFields UCalendarDateFields;
455     /**
456      * Useful constant for days of week. Note: Calendar day-of-week is 1-based. Clients
457      * who create locale resources for the field of first-day-of-week should be aware of
458      * this. For instance, in US locale, first-day-of-week is set to 1, i.e., UCAL_SUNDAY.
459      */
460 /** Possible days of the week in a UCalendar
461  * @stable ICU 2.0
462  */
463 enum UCalendarDaysOfWeek {
464   /** Sunday */
465   UCAL_SUNDAY = 1,
466   /** Monday */
467   UCAL_MONDAY,
468   /** Tuesday */
469   UCAL_TUESDAY,
470   /** Wednesday */
471   UCAL_WEDNESDAY,
472   /** Thursday */
473   UCAL_THURSDAY,
474   /** Friday */
475   UCAL_FRIDAY,
476   /** Saturday */
477   UCAL_SATURDAY
478 };
479 
480 /** @stable ICU 2.0 */
481 typedef enum UCalendarDaysOfWeek UCalendarDaysOfWeek;
482 
483 /** Possible months in a UCalendar. Note: Calendar month is 0-based.
484  * @stable ICU 2.0
485  */
486 enum UCalendarMonths {
487   /** January */
488   UCAL_JANUARY,
489   /** February */
490   UCAL_FEBRUARY,
491   /** March */
492   UCAL_MARCH,
493   /** April */
494   UCAL_APRIL,
495   /** May */
496   UCAL_MAY,
497   /** June */
498   UCAL_JUNE,
499   /** July */
500   UCAL_JULY,
501   /** August */
502   UCAL_AUGUST,
503   /** September */
504   UCAL_SEPTEMBER,
505   /** October */
506   UCAL_OCTOBER,
507   /** November */
508   UCAL_NOVEMBER,
509   /** December */
510   UCAL_DECEMBER,
511   /** Value of the <code>UCAL_MONTH</code> field indicating the
512     * thirteenth month of the year. Although the Gregorian calendar
513     * does not use this value, lunar calendars do.
514     */
515   UCAL_UNDECIMBER
516 };
517 
518 /** @stable ICU 2.0 */
519 typedef enum UCalendarMonths UCalendarMonths;
520 
521 /** Possible AM/PM values in a UCalendar
522  * @stable ICU 2.0
523  */
524 enum UCalendarAMPMs {
525     /** AM */
526   UCAL_AM,
527   /** PM */
528   UCAL_PM
529 };
530 
531 /** @stable ICU 2.0 */
532 typedef enum UCalendarAMPMs UCalendarAMPMs;
533 
534 /**
535  * System time zone type constants used by filtering zones
536  * in ucal_openTimeZoneIDEnumeration.
537  * @see ucal_openTimeZoneIDEnumeration
538  * @stable ICU 4.8
539  */
540 enum USystemTimeZoneType {
541     /**
542      * Any system zones.
543      * @stable ICU 4.8
544      */
545     UCAL_ZONE_TYPE_ANY,
546     /**
547      * Canonical system zones.
548      * @stable ICU 4.8
549      */
550     UCAL_ZONE_TYPE_CANONICAL,
551     /**
552      * Canonical system zones associated with actual locations.
553      * @stable ICU 4.8
554      */
555     UCAL_ZONE_TYPE_CANONICAL_LOCATION
556 };
557 
558 /** @stable ICU 4.8 */
559 typedef enum USystemTimeZoneType USystemTimeZoneType;
560 
561 /**
562  * Create an enumeration over system time zone IDs with the given
563  * filter conditions.
564  * @param zoneType  The system time zone type.
565  * @param region    The ISO 3166 two-letter country code or UN M.49
566  *                  three-digit area code.  When NULL, no filtering
567  *                  done by region.
568  * @param rawOffset An offset from GMT in milliseconds, ignoring the
569  *                  effect of daylight savings time, if any. When NULL,
570  *                  no filtering done by zone offset.
571  * @param ec        A pointer to an UErrorCode to receive any errors
572  * @return  an enumeration object that the caller must dispose of
573  *          using enum_close(), or NULL upon failure. In case of failure,
574  *          *ec will indicate the error.
575  * @stable ICU 4.8
576  */
577 U_CAPI UEnumeration* U_EXPORT2
578 ucal_openTimeZoneIDEnumeration(USystemTimeZoneType zoneType, const char* region,
579                                 const int32_t* rawOffset, UErrorCode* ec);
580 
581 /**
582  * Create an enumeration over all time zones.
583  *
584  * @param ec input/output error code
585  *
586  * @return an enumeration object that the caller must dispose of using
587  * uenum_close(), or NULL upon failure. In case of failure *ec will
588  * indicate the error.
589  *
590  * @stable ICU 2.6
591  */
592 U_CAPI UEnumeration* U_EXPORT2
593 ucal_openTimeZones(UErrorCode* ec);
594 
595 /**
596  * Create an enumeration over all time zones associated with the given
597  * country. Some zones are affiliated with no country (e.g., "UTC");
598  * these may also be retrieved, as a group.
599  *
600  * @param country the ISO 3166 two-letter country code, or NULL to
601  * retrieve zones not affiliated with any country
602  *
603  * @param ec input/output error code
604  *
605  * @return an enumeration object that the caller must dispose of using
606  * uenum_close(), or NULL upon failure. In case of failure *ec will
607  * indicate the error.
608  *
609  * @stable ICU 2.6
610  */
611 U_CAPI UEnumeration* U_EXPORT2
612 ucal_openCountryTimeZones(const char* country, UErrorCode* ec);
613 
614 /**
615  * Return the default time zone. The default is determined initially
616  * by querying the host operating system. If the host system detection
617  * routines fail, or if they specify a TimeZone or TimeZone offset
618  * which is not recognized, then the special TimeZone "Etc/Unknown"
619  * is returned.
620  *
621  * The default may be changed with `ucal_setDefaultTimeZone()` or with
622  * the C++ TimeZone API, `TimeZone::adoptDefault(TimeZone*)`.
623  *
624  * @param result A buffer to receive the result, or NULL
625  *
626  * @param resultCapacity The capacity of the result buffer
627  *
628  * @param ec input/output error code
629  *
630  * @return The result string length, not including the terminating
631  * null
632  *
633  * @see #UCAL_UNKNOWN_ZONE_ID
634  *
635  * @stable ICU 2.6
636  */
637 U_CAPI int32_t U_EXPORT2
638 ucal_getDefaultTimeZone(UChar* result, int32_t resultCapacity, UErrorCode* ec);
639 
640 /**
641  * Set the default time zone.
642  *
643  * @param zoneID null-terminated time zone ID
644  *
645  * @param ec input/output error code
646  *
647  * @stable ICU 2.6
648  */
649 U_CAPI void U_EXPORT2
650 ucal_setDefaultTimeZone(const UChar* zoneID, UErrorCode* ec);
651 
652 /**
653  * Return the current host time zone. The host time zone is detected from
654  * the current host system configuration by querying the host operating
655  * system. If the host system detection routines fail, or if they specify
656  * a TimeZone or TimeZone offset which is not recognized, then the special
657  * TimeZone "Etc/Unknown" is returned.
658  *
659  * Note that host time zone and the ICU default time zone can be different.
660  *
661  * The ICU default time zone does not change once initialized unless modified
662  * by calling `ucal_setDefaultTimeZone()` or with the C++ TimeZone API,
663  * `TimeZone::adoptDefault(TimeZone*)`.
664  *
665  * If the host operating system configuration has changed since ICU has
666  * initialized then the returned value can be different than the ICU default
667  * time zone, even if the default has not changed.
668  *
669  * <p>This function is not thread safe.</p>
670  *
671  * @param result A buffer to receive the result, or NULL
672  * @param resultCapacity The capacity of the result buffer
673  * @param ec input/output error code
674  * @return The result string length, not including the terminating
675  * null
676  *
677  * @see #UCAL_UNKNOWN_ZONE_ID
678  *
679  * @stable ICU 65
680  */
681 U_CAPI int32_t U_EXPORT2
682 ucal_getHostTimeZone(UChar *result, int32_t resultCapacity, UErrorCode *ec);
683 
684 /**
685  * Return the amount of time in milliseconds that the clock is
686  * advanced during daylight savings time for the given time zone, or
687  * zero if the time zone does not observe daylight savings time.
688  *
689  * @param zoneID null-terminated time zone ID
690  *
691  * @param ec input/output error code
692  *
693  * @return the number of milliseconds the time is advanced with
694  * respect to standard time when the daylight savings rules are in
695  * effect. This is always a non-negative number, most commonly either
696  * 3,600,000 (one hour) or zero.
697  *
698  * @stable ICU 2.6
699  */
700 U_CAPI int32_t U_EXPORT2
701 ucal_getDSTSavings(const UChar* zoneID, UErrorCode* ec);
702 
703 /**
704  * Get the current date and time.
705  * The value returned is represented as milliseconds from the epoch.
706  * @return The current date and time.
707  * @stable ICU 2.0
708  */
709 U_CAPI UDate U_EXPORT2
710 ucal_getNow(void);
711 
712 /**
713  * Open a UCalendar.
714  * A UCalendar may be used to convert a millisecond value to a year,
715  * month, and day.
716  * <p>
717  * Note: When unknown TimeZone ID is specified or if the TimeZone ID specified is "Etc/Unknown",
718  * the UCalendar returned by the function is initialized with GMT zone with TimeZone ID
719  * <code>UCAL_UNKNOWN_ZONE_ID</code> ("Etc/Unknown") without any errors/warnings.  If you want
720  * to check if a TimeZone ID is valid prior to this function, use <code>ucal_getCanonicalTimeZoneID</code>.
721  *
722  * @param zoneID The desired TimeZone ID.  If 0, use the default time zone.
723  * @param len The length of zoneID, or -1 if null-terminated.
724  * @param locale The desired locale
725  * @param type The type of UCalendar to open. This can be UCAL_GREGORIAN to open the Gregorian
726  * calendar for the locale, or UCAL_DEFAULT to open the default calendar for the locale (the
727  * default calendar may also be Gregorian). To open a specific non-Gregorian calendar for the
728  * locale, use uloc_setKeywordValue to set the value of the calendar keyword for the locale
729  * and then pass the locale to ucal_open with UCAL_DEFAULT as the type.
730  * @param status A pointer to an UErrorCode to receive any errors
731  * @return A pointer to a UCalendar, or 0 if an error occurred.
732  * @see #UCAL_UNKNOWN_ZONE_ID
733  * @stable ICU 2.0
734  */
735 U_CAPI UCalendar* U_EXPORT2
736 ucal_open(const UChar*   zoneID,
737           int32_t        len,
738           const char*    locale,
739           UCalendarType  type,
740           UErrorCode*    status);
741 
742 /**
743  * Close a UCalendar.
744  * Once closed, a UCalendar may no longer be used.
745  * @param cal The UCalendar to close.
746  * @stable ICU 2.0
747  */
748 U_CAPI void U_EXPORT2
749 ucal_close(UCalendar *cal);
750 
751 /**
752  * Open a copy of a UCalendar.
753  * This function performs a deep copy.
754  * @param cal The calendar to copy
755  * @param status A pointer to an UErrorCode to receive any errors.
756  * @return A pointer to a UCalendar identical to cal.
757  * @stable ICU 4.0
758  */
759 U_CAPI UCalendar* U_EXPORT2
760 ucal_clone(const UCalendar* cal,
761            UErrorCode*      status);
762 
763 /**
764  * Set the TimeZone used by a UCalendar.
765  * A UCalendar uses a timezone for converting from Greenwich time to local time.
766  * @param cal The UCalendar to set.
767  * @param zoneID The desired TimeZone ID.  If 0, use the default time zone.
768  * @param len The length of zoneID, or -1 if null-terminated.
769  * @param status A pointer to an UErrorCode to receive any errors.
770  * @stable ICU 2.0
771  */
772 U_CAPI void U_EXPORT2
773 ucal_setTimeZone(UCalendar*    cal,
774                  const UChar*  zoneID,
775                  int32_t       len,
776                  UErrorCode*   status);
777 
778 /**
779  * Get the ID of the UCalendar's time zone.
780  *
781  * @param cal           The UCalendar to query.
782  * @param result        Receives the UCalendar's time zone ID.
783  * @param resultLength  The maximum size of result.
784  * @param status        Receives the status.
785  * @return              The total buffer size needed; if greater than resultLength, the output was truncated.
786  * @stable ICU 51
787  */
788 U_CAPI int32_t U_EXPORT2
789 ucal_getTimeZoneID(const UCalendar *cal,
790                    UChar *result,
791                    int32_t resultLength,
792                    UErrorCode *status);
793 
794 /**
795  * Possible formats for a UCalendar's display name
796  * @stable ICU 2.0
797  */
798 enum UCalendarDisplayNameType {
799   /** Standard display name */
800   UCAL_STANDARD,
801   /** Short standard display name */
802   UCAL_SHORT_STANDARD,
803   /** Daylight savings display name */
804   UCAL_DST,
805   /** Short daylight savings display name */
806   UCAL_SHORT_DST
807 };
808 
809 /** @stable ICU 2.0 */
810 typedef enum UCalendarDisplayNameType UCalendarDisplayNameType;
811 
812 /**
813  * Get the display name for a UCalendar's TimeZone.
814  * A display name is suitable for presentation to a user.
815  * @param cal          The UCalendar to query.
816  * @param type         The desired display name format; one of UCAL_STANDARD, UCAL_SHORT_STANDARD,
817  *                     UCAL_DST, UCAL_SHORT_DST
818  * @param locale       The desired locale for the display name.
819  * @param result       A pointer to a buffer to receive the formatted number.
820  * @param resultLength The maximum size of result.
821  * @param status       A pointer to an UErrorCode to receive any errors
822  * @return             The total buffer size needed; if greater than resultLength, the output was truncated.
823  * @stable ICU 2.0
824  */
825 U_CAPI int32_t U_EXPORT2
826 ucal_getTimeZoneDisplayName(const UCalendar*          cal,
827                             UCalendarDisplayNameType  type,
828                             const char*               locale,
829                             UChar*                    result,
830                             int32_t                   resultLength,
831                             UErrorCode*               status);
832 
833 /**
834  * Determine if a UCalendar is currently in daylight savings time.
835  * Daylight savings time is not used in all parts of the world.
836  * @param cal The UCalendar to query.
837  * @param status A pointer to an UErrorCode to receive any errors
838  * @return true if cal is currently in daylight savings time, false otherwise
839  * @stable ICU 2.0
840  */
841 U_CAPI UBool U_EXPORT2
842 ucal_inDaylightTime(const UCalendar*  cal,
843                     UErrorCode*       status );
844 
845 /**
846  * Sets the GregorianCalendar change date. This is the point when the switch from
847  * Julian dates to Gregorian dates occurred. Default is 00:00:00 local time, October
848  * 15, 1582. Previous to this time and date will be Julian dates.
849  *
850  * This function works only for Gregorian calendars. If the UCalendar is not
851  * an instance of a Gregorian calendar, then a U_UNSUPPORTED_ERROR
852  * error code is set.
853  *
854  * @param cal        The calendar object.
855  * @param date       The given Gregorian cutover date.
856  * @param pErrorCode Pointer to a standard ICU error code. Its input value must
857  *                   pass the U_SUCCESS() test, or else the function returns
858  *                   immediately. Check for U_FAILURE() on output or use with
859  *                   function chaining. (See User Guide for details.)
860  *
861  * @see GregorianCalendar::setGregorianChange
862  * @see ucal_getGregorianChange
863  * @stable ICU 3.6
864  */
865 U_CAPI void U_EXPORT2
866 ucal_setGregorianChange(UCalendar *cal, UDate date, UErrorCode *pErrorCode);
867 
868 /**
869  * Gets the Gregorian Calendar change date. This is the point when the switch from
870  * Julian dates to Gregorian dates occurred. Default is 00:00:00 local time, October
871  * 15, 1582. Previous to this time and date will be Julian dates.
872  *
873  * This function works only for Gregorian calendars. If the UCalendar is not
874  * an instance of a Gregorian calendar, then a U_UNSUPPORTED_ERROR
875  * error code is set.
876  *
877  * @param cal        The calendar object.
878  * @param pErrorCode Pointer to a standard ICU error code. Its input value must
879  *                   pass the U_SUCCESS() test, or else the function returns
880  *                   immediately. Check for U_FAILURE() on output or use with
881  *                   function chaining. (See User Guide for details.)
882  * @return   The Gregorian cutover time for this calendar.
883  *
884  * @see GregorianCalendar::getGregorianChange
885  * @see ucal_setGregorianChange
886  * @stable ICU 3.6
887  */
888 U_CAPI UDate U_EXPORT2
889 ucal_getGregorianChange(const UCalendar *cal, UErrorCode *pErrorCode);
890 
891 /**
892  * Types of UCalendar attributes
893  * @stable ICU 2.0
894  */
895 enum UCalendarAttribute {
896   /**
897    * Lenient parsing
898    * @stable ICU 2.0
899    */
900   UCAL_LENIENT,
901   /**
902    * First day of week
903    * @stable ICU 2.0
904    */
905   UCAL_FIRST_DAY_OF_WEEK,
906   /**
907    * Minimum number of days in first week
908    * @stable ICU 2.0
909    */
910   UCAL_MINIMAL_DAYS_IN_FIRST_WEEK,
911   /**
912    * The behavior for handling wall time repeating multiple times
913    * at negative time zone offset transitions
914    * @stable ICU 49
915    */
916   UCAL_REPEATED_WALL_TIME,
917   /**
918    * The behavior for handling skipped wall time at positive time
919    * zone offset transitions.
920    * @stable ICU 49
921    */
922   UCAL_SKIPPED_WALL_TIME
923 };
924 
925 /** @stable ICU 2.0 */
926 typedef enum UCalendarAttribute UCalendarAttribute;
927 
928 /**
929  * Options for handling ambiguous wall time at time zone
930  * offset transitions.
931  * @stable ICU 49
932  */
933 enum UCalendarWallTimeOption {
934     /**
935      * An ambiguous wall time to be interpreted as the latest.
936      * This option is valid for UCAL_REPEATED_WALL_TIME and
937      * UCAL_SKIPPED_WALL_TIME.
938      * @stable ICU 49
939      */
940     UCAL_WALLTIME_LAST,
941     /**
942      * An ambiguous wall time to be interpreted as the earliest.
943      * This option is valid for UCAL_REPEATED_WALL_TIME and
944      * UCAL_SKIPPED_WALL_TIME.
945      * @stable ICU 49
946      */
947     UCAL_WALLTIME_FIRST,
948     /**
949      * An ambiguous wall time to be interpreted as the next valid
950      * wall time. This option is valid for UCAL_SKIPPED_WALL_TIME.
951      * @stable ICU 49
952      */
953     UCAL_WALLTIME_NEXT_VALID
954 };
955 /** @stable ICU 49 */
956 typedef enum UCalendarWallTimeOption UCalendarWallTimeOption;
957 
958 /**
959  * Get a numeric attribute associated with a UCalendar.
960  * Numeric attributes include the first day of the week, or the minimal numbers
961  * of days in the first week of the month.
962  * @param cal The UCalendar to query.
963  * @param attr The desired attribute; one of UCAL_LENIENT, UCAL_FIRST_DAY_OF_WEEK,
964  * UCAL_MINIMAL_DAYS_IN_FIRST_WEEK, UCAL_REPEATED_WALL_TIME or UCAL_SKIPPED_WALL_TIME
965  * @return The value of attr.
966  * @see ucal_setAttribute
967  * @stable ICU 2.0
968  */
969 U_CAPI int32_t U_EXPORT2
970 ucal_getAttribute(const UCalendar*    cal,
971                   UCalendarAttribute  attr);
972 
973 /**
974  * Set a numeric attribute associated with a UCalendar.
975  * Numeric attributes include the first day of the week, or the minimal numbers
976  * of days in the first week of the month.
977  * @param cal The UCalendar to set.
978  * @param attr The desired attribute; one of UCAL_LENIENT, UCAL_FIRST_DAY_OF_WEEK,
979  * UCAL_MINIMAL_DAYS_IN_FIRST_WEEK, UCAL_REPEATED_WALL_TIME or UCAL_SKIPPED_WALL_TIME
980  * @param newValue The new value of attr.
981  * @see ucal_getAttribute
982  * @stable ICU 2.0
983  */
984 U_CAPI void U_EXPORT2
985 ucal_setAttribute(UCalendar*          cal,
986                   UCalendarAttribute  attr,
987                   int32_t             newValue);
988 
989 /**
990  * Get a locale for which calendars are available.
991  * A UCalendar in a locale returned by this function will contain the correct
992  * day and month names for the locale.
993  * @param localeIndex The index of the desired locale.
994  * @return A locale for which calendars are available, or 0 if none.
995  * @see ucal_countAvailable
996  * @stable ICU 2.0
997  */
998 U_CAPI const char* U_EXPORT2
999 ucal_getAvailable(int32_t localeIndex);
1000 
1001 /**
1002  * Determine how many locales have calendars available.
1003  * This function is most useful as determining the loop ending condition for
1004  * calls to \ref ucal_getAvailable.
1005  * @return The number of locales for which calendars are available.
1006  * @see ucal_getAvailable
1007  * @stable ICU 2.0
1008  */
1009 U_CAPI int32_t U_EXPORT2
1010 ucal_countAvailable(void);
1011 
1012 /**
1013  * Get a UCalendar's current time in millis.
1014  * The time is represented as milliseconds from the epoch.
1015  * @param cal The UCalendar to query.
1016  * @param status A pointer to an UErrorCode to receive any errors
1017  * @return The calendar's current time in millis.
1018  * @see ucal_setMillis
1019  * @see ucal_setDate
1020  * @see ucal_setDateTime
1021  * @stable ICU 2.0
1022  */
1023 U_CAPI UDate U_EXPORT2
1024 ucal_getMillis(const UCalendar*  cal,
1025                UErrorCode*       status);
1026 
1027 /**
1028  * Set a UCalendar's current time in millis.
1029  * The time is represented as milliseconds from the epoch.
1030  * @param cal The UCalendar to set.
1031  * @param dateTime The desired date and time.
1032  * @param status A pointer to an UErrorCode to receive any errors
1033  * @see ucal_getMillis
1034  * @see ucal_setDate
1035  * @see ucal_setDateTime
1036  * @stable ICU 2.0
1037  */
1038 U_CAPI void U_EXPORT2
1039 ucal_setMillis(UCalendar*   cal,
1040                UDate        dateTime,
1041                UErrorCode*  status );
1042 
1043 /**
1044  * Set a UCalendar's current date.
1045  * The date is represented as a series of 32-bit integers.
1046  * @param cal The UCalendar to set.
1047  * @param year The desired year.
1048  * @param month The desired month; one of UCAL_JANUARY, UCAL_FEBRUARY, UCAL_MARCH, UCAL_APRIL, UCAL_MAY,
1049  * UCAL_JUNE, UCAL_JULY, UCAL_AUGUST, UCAL_SEPTEMBER, UCAL_OCTOBER, UCAL_NOVEMBER, UCAL_DECEMBER, UCAL_UNDECIMBER
1050  * @param date The desired day of the month.
1051  * @param status A pointer to an UErrorCode to receive any errors
1052  * @see ucal_getMillis
1053  * @see ucal_setMillis
1054  * @see ucal_setDateTime
1055  * @stable ICU 2.0
1056  */
1057 U_CAPI void U_EXPORT2
1058 ucal_setDate(UCalendar*   cal,
1059              int32_t      year,
1060              int32_t      month,
1061              int32_t      date,
1062              UErrorCode*  status);
1063 
1064 /**
1065  * Set a UCalendar's current date.
1066  * The date is represented as a series of 32-bit integers.
1067  * @param cal The UCalendar to set.
1068  * @param year The desired year.
1069  * @param month The desired month; one of UCAL_JANUARY, UCAL_FEBRUARY, UCAL_MARCH, UCAL_APRIL, UCAL_MAY,
1070  * UCAL_JUNE, UCAL_JULY, UCAL_AUGUST, UCAL_SEPTEMBER, UCAL_OCTOBER, UCAL_NOVEMBER, UCAL_DECEMBER, UCAL_UNDECIMBER
1071  * @param date The desired day of the month.
1072  * @param hour The desired hour of day.
1073  * @param minute The desired minute.
1074  * @param second The desirec second.
1075  * @param status A pointer to an UErrorCode to receive any errors
1076  * @see ucal_getMillis
1077  * @see ucal_setMillis
1078  * @see ucal_setDate
1079  * @stable ICU 2.0
1080  */
1081 U_CAPI void U_EXPORT2
1082 ucal_setDateTime(UCalendar*   cal,
1083                  int32_t      year,
1084                  int32_t      month,
1085                  int32_t      date,
1086                  int32_t      hour,
1087                  int32_t      minute,
1088                  int32_t      second,
1089                  UErrorCode*  status);
1090 
1091 /**
1092  * Returns true if two UCalendars are equivalent.  Equivalent
1093  * UCalendars will behave identically, but they may be set to
1094  * different times.
1095  * @param cal1 The first of the UCalendars to compare.
1096  * @param cal2 The second of the UCalendars to compare.
1097  * @return true if cal1 and cal2 are equivalent, false otherwise.
1098  * @stable ICU 2.0
1099  */
1100 U_CAPI UBool U_EXPORT2
1101 ucal_equivalentTo(const UCalendar*  cal1,
1102                   const UCalendar*  cal2);
1103 
1104 /**
1105  * Add a specified signed amount to a particular field in a UCalendar.
1106  * This can modify more significant fields in the calendar.
1107  * Adding a positive value always means moving forward in time, so for the Gregorian calendar,
1108  * starting with 100 BC and adding +1 to year results in 99 BC (even though this actually reduces
1109  * the numeric value of the field itself).
1110  * @param cal The UCalendar to which to add.
1111  * @param field The field to which to add the signed value; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH,
1112  * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK,
1113  * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND,
1114  * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET.
1115  * @param amount The signed amount to add to field. If the amount causes the value
1116  * to exceed to maximum or minimum values for that field, other fields are modified
1117  * to preserve the magnitude of the change.
1118  * @param status A pointer to an UErrorCode to receive any errors
1119  * @see ucal_roll
1120  * @stable ICU 2.0
1121  */
1122 U_CAPI void U_EXPORT2
1123 ucal_add(UCalendar*           cal,
1124          UCalendarDateFields  field,
1125          int32_t              amount,
1126          UErrorCode*          status);
1127 
1128 /**
1129  * Add a specified signed amount to a particular field in a UCalendar.
1130  * This will not modify more significant fields in the calendar.
1131  * Rolling by a positive value always means moving forward in time (unless the limit of the
1132  * field is reached, in which case it may pin or wrap), so for Gregorian calendar,
1133  * starting with 100 BC and rolling the year by +1 results in 99 BC.
1134  * When eras have a definite beginning and end (as in the Chinese calendar, or as in most eras in the
1135  * Japanese calendar) then rolling the year past either limit of the era will cause the year to wrap around.
1136  * When eras only have a limit at one end, then attempting to roll the year past that limit will result in
1137  * pinning the year at that limit. Note that for most calendars in which era 0 years move forward in time
1138  * (such as Buddhist, Hebrew, or Islamic), it is possible for add or roll to result in negative years for
1139  * era 0 (that is the only way to represent years before the calendar epoch).
1140  * @param cal The UCalendar to which to add.
1141  * @param field The field to which to add the signed value; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH,
1142  * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK,
1143  * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND,
1144  * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET.
1145  * @param amount The signed amount to add to field. If the amount causes the value
1146  * to exceed to maximum or minimum values for that field, the field is pinned to a permissible
1147  * value.
1148  * @param status A pointer to an UErrorCode to receive any errors
1149  * @see ucal_add
1150  * @stable ICU 2.0
1151  */
1152 U_CAPI void U_EXPORT2
1153 ucal_roll(UCalendar*           cal,
1154           UCalendarDateFields  field,
1155           int32_t              amount,
1156           UErrorCode*          status);
1157 
1158 /**
1159  * Get the current value of a field from a UCalendar.
1160  * All fields are represented as 32-bit integers.
1161  * @param cal The UCalendar to query.
1162  * @param field The desired field; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH,
1163  * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK,
1164  * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND,
1165  * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET.
1166  * @param status A pointer to an UErrorCode to receive any errors
1167  * @return The value of the desired field.
1168  * @see ucal_set
1169  * @see ucal_isSet
1170  * @see ucal_clearField
1171  * @see ucal_clear
1172  * @stable ICU 2.0
1173  */
1174 U_CAPI int32_t U_EXPORT2
1175 ucal_get(const UCalendar*     cal,
1176          UCalendarDateFields  field,
1177          UErrorCode*          status );
1178 
1179 /**
1180  * Set the value of a field in a UCalendar.
1181  * All fields are represented as 32-bit integers.
1182  * @param cal The UCalendar to set.
1183  * @param field The field to set; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH,
1184  * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK,
1185  * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND,
1186  * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET.
1187  * @param value The desired value of field.
1188  * @see ucal_get
1189  * @see ucal_isSet
1190  * @see ucal_clearField
1191  * @see ucal_clear
1192  * @stable ICU 2.0
1193  */
1194 U_CAPI void U_EXPORT2
1195 ucal_set(UCalendar*           cal,
1196          UCalendarDateFields  field,
1197          int32_t              value);
1198 
1199 /**
1200  * Determine if a field in a UCalendar is set.
1201  * All fields are represented as 32-bit integers.
1202  * @param cal The UCalendar to query.
1203  * @param field The desired field; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH,
1204  * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK,
1205  * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND,
1206  * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET.
1207  * @return true if field is set, false otherwise.
1208  * @see ucal_get
1209  * @see ucal_set
1210  * @see ucal_clearField
1211  * @see ucal_clear
1212  * @stable ICU 2.0
1213  */
1214 U_CAPI UBool U_EXPORT2
1215 ucal_isSet(const UCalendar*     cal,
1216            UCalendarDateFields  field);
1217 
1218 /**
1219  * Clear a field in a UCalendar.
1220  * All fields are represented as 32-bit integers.
1221  * @param cal The UCalendar containing the field to clear.
1222  * @param field The field to clear; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH,
1223  * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK,
1224  * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND,
1225  * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET.
1226  * @see ucal_get
1227  * @see ucal_set
1228  * @see ucal_isSet
1229  * @see ucal_clear
1230  * @stable ICU 2.0
1231  */
1232 U_CAPI void U_EXPORT2
1233 ucal_clearField(UCalendar*           cal,
1234                 UCalendarDateFields  field);
1235 
1236 /**
1237  * Clear all fields in a UCalendar.
1238  * All fields are represented as 32-bit integers.
1239  * @param calendar The UCalendar to clear.
1240  * @see ucal_get
1241  * @see ucal_set
1242  * @see ucal_isSet
1243  * @see ucal_clearField
1244  * @stable ICU 2.0
1245  */
1246 U_CAPI void U_EXPORT2
1247 ucal_clear(UCalendar* calendar);
1248 
1249 /**
1250  * Possible limit values for a UCalendar
1251  * @stable ICU 2.0
1252  */
1253 enum UCalendarLimitType {
1254   /** Minimum value */
1255   UCAL_MINIMUM,
1256   /** Maximum value */
1257   UCAL_MAXIMUM,
1258   /** Greatest minimum value */
1259   UCAL_GREATEST_MINIMUM,
1260   /** Least maximum value */
1261   UCAL_LEAST_MAXIMUM,
1262   /** Actual minimum value */
1263   UCAL_ACTUAL_MINIMUM,
1264   /** Actual maximum value */
1265   UCAL_ACTUAL_MAXIMUM
1266 };
1267 
1268 /** @stable ICU 2.0 */
1269 typedef enum UCalendarLimitType UCalendarLimitType;
1270 
1271 /**
1272  * Determine a limit for a field in a UCalendar.
1273  * A limit is a maximum or minimum value for a field.
1274  * @param cal The UCalendar to query.
1275  * @param field The desired field; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH,
1276  * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK,
1277  * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND,
1278  * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET.
1279  * @param type The desired critical point; one of UCAL_MINIMUM, UCAL_MAXIMUM, UCAL_GREATEST_MINIMUM,
1280  * UCAL_LEAST_MAXIMUM, UCAL_ACTUAL_MINIMUM, UCAL_ACTUAL_MAXIMUM
1281  * @param status A pointer to an UErrorCode to receive any errors.
1282  * @return The requested value.
1283  * @stable ICU 2.0
1284  */
1285 U_CAPI int32_t U_EXPORT2
1286 ucal_getLimit(const UCalendar*     cal,
1287               UCalendarDateFields  field,
1288               UCalendarLimitType   type,
1289               UErrorCode*          status);
1290 
1291 /** Get the locale for this calendar object. You can choose between valid and actual locale.
1292  *  @param cal The calendar object
1293  *  @param type type of the locale we're looking for (valid or actual)
1294  *  @param status error code for the operation
1295  *  @return the locale name
1296  *  @stable ICU 2.8
1297  */
1298 U_CAPI const char * U_EXPORT2
1299 ucal_getLocaleByType(const UCalendar *cal, ULocDataLocaleType type, UErrorCode* status);
1300 
1301 /**
1302  * Returns the timezone data version currently used by ICU.
1303  * @param status error code for the operation
1304  * @return the version string, such as "2007f"
1305  * @stable ICU 3.8
1306  */
1307 U_CAPI const char * U_EXPORT2
1308 ucal_getTZDataVersion(UErrorCode* status);
1309 
1310 /**
1311  * Returns the canonical system timezone ID or the normalized
1312  * custom time zone ID for the given time zone ID.
1313  * @param id        The input timezone ID to be canonicalized.
1314  * @param len       The length of id, or -1 if null-terminated.
1315  * @param result    The buffer receives the canonical system timezone ID
1316  *                  or the custom timezone ID in normalized format.
1317  * @param resultCapacity    The capacity of the result buffer.
1318  * @param isSystemID        Receives if the given ID is a known system
1319      *                      timezone ID.
1320  * @param status    Receives the status.  When the given timezone ID
1321  *                  is neither a known system time zone ID nor a
1322  *                  valid custom timezone ID, U_ILLEGAL_ARGUMENT_ERROR
1323  *                  is set.
1324  * @return          The result string length, not including the terminating
1325  *                  null.
1326  * @stable ICU 4.0
1327  */
1328 U_CAPI int32_t U_EXPORT2
1329 ucal_getCanonicalTimeZoneID(const UChar* id, int32_t len,
1330                             UChar* result, int32_t resultCapacity, UBool *isSystemID, UErrorCode* status);
1331 /**
1332  * Get the resource keyword value string designating the calendar type for the UCalendar.
1333  * @param cal The UCalendar to query.
1334  * @param status The error code for the operation.
1335  * @return The resource keyword value string.
1336  * @stable ICU 4.2
1337  */
1338 U_CAPI const char * U_EXPORT2
1339 ucal_getType(const UCalendar *cal, UErrorCode* status);
1340 
1341 /**
1342  * Given a key and a locale, returns an array of string values in a preferred
1343  * order that would make a difference. These are all and only those values where
1344  * the open (creation) of the service with the locale formed from the input locale
1345  * plus input keyword and that value has different behavior than creation with the
1346  * input locale alone.
1347  * @param key           one of the keys supported by this service.  For now, only
1348  *                      "calendar" is supported.
1349  * @param locale        the locale
1350  * @param commonlyUsed  if set to true it will return only commonly used values
1351  *                      with the given locale in preferred order.  Otherwise,
1352  *                      it will return all the available values for the locale.
1353  * @param status error status
1354  * @return a string enumeration over keyword values for the given key and the locale.
1355  * @stable ICU 4.2
1356  */
1357 U_CAPI UEnumeration* U_EXPORT2
1358 ucal_getKeywordValuesForLocale(const char* key,
1359                                const char* locale,
1360                                UBool commonlyUsed,
1361                                UErrorCode* status);
1362 
1363 
1364 /** Weekday types, as returned by ucal_getDayOfWeekType().
1365  * @stable ICU 4.4
1366  */
1367 enum UCalendarWeekdayType {
1368   /**
1369    * Designates a full weekday (no part of the day is included in the weekend).
1370    * @stable ICU 4.4
1371    */
1372   UCAL_WEEKDAY,
1373   /**
1374    * Designates a full weekend day (the entire day is included in the weekend).
1375    * @stable ICU 4.4
1376    */
1377   UCAL_WEEKEND,
1378   /**
1379    * Designates a day that starts as a weekday and transitions to the weekend.
1380    * Call ucal_getWeekendTransition() to get the time of transition.
1381    * @stable ICU 4.4
1382    */
1383   UCAL_WEEKEND_ONSET,
1384   /**
1385    * Designates a day that starts as the weekend and transitions to a weekday.
1386    * Call ucal_getWeekendTransition() to get the time of transition.
1387    * @stable ICU 4.4
1388    */
1389   UCAL_WEEKEND_CEASE
1390 };
1391 
1392 /** @stable ICU 4.4 */
1393 typedef enum UCalendarWeekdayType UCalendarWeekdayType;
1394 
1395 /**
1396  * Returns whether the given day of the week is a weekday, a weekend day,
1397  * or a day that transitions from one to the other, for the locale and
1398  * calendar system associated with this UCalendar (the locale's region is
1399  * often the most determinant factor). If a transition occurs at midnight,
1400  * then the days before and after the transition will have the
1401  * type UCAL_WEEKDAY or UCAL_WEEKEND. If a transition occurs at a time
1402  * other than midnight, then the day of the transition will have
1403  * the type UCAL_WEEKEND_ONSET or UCAL_WEEKEND_CEASE. In this case, the
1404  * function ucal_getWeekendTransition() will return the point of
1405  * transition.
1406  * @param cal The UCalendar to query.
1407  * @param dayOfWeek The day of the week whose type is desired (UCAL_SUNDAY..UCAL_SATURDAY).
1408  * @param status The error code for the operation.
1409  * @return The UCalendarWeekdayType for the day of the week.
1410  * @stable ICU 4.4
1411  */
1412 U_CAPI UCalendarWeekdayType U_EXPORT2
1413 ucal_getDayOfWeekType(const UCalendar *cal, UCalendarDaysOfWeek dayOfWeek, UErrorCode* status);
1414 
1415 /**
1416  * Returns the time during the day at which the weekend begins or ends in
1417  * this calendar system.  If ucal_getDayOfWeekType() returns UCAL_WEEKEND_ONSET
1418  * for the specified dayOfWeek, return the time at which the weekend begins.
1419  * If ucal_getDayOfWeekType() returns UCAL_WEEKEND_CEASE for the specified dayOfWeek,
1420  * return the time at which the weekend ends. If ucal_getDayOfWeekType() returns
1421  * some other UCalendarWeekdayType for the specified dayOfWeek, is it an error condition
1422  * (U_ILLEGAL_ARGUMENT_ERROR).
1423  * @param cal The UCalendar to query.
1424  * @param dayOfWeek The day of the week for which the weekend transition time is
1425  * desired (UCAL_SUNDAY..UCAL_SATURDAY).
1426  * @param status The error code for the operation.
1427  * @return The milliseconds after midnight at which the weekend begins or ends.
1428  * @stable ICU 4.4
1429  */
1430 U_CAPI int32_t U_EXPORT2
1431 ucal_getWeekendTransition(const UCalendar *cal, UCalendarDaysOfWeek dayOfWeek, UErrorCode *status);
1432 
1433 /**
1434  * Returns true if the given UDate is in the weekend in
1435  * this calendar system.
1436  * @param cal The UCalendar to query.
1437  * @param date The UDate in question.
1438  * @param status The error code for the operation.
1439  * @return true if the given UDate is in the weekend in
1440  * this calendar system, false otherwise.
1441  * @stable ICU 4.4
1442  */
1443 U_CAPI UBool U_EXPORT2
1444 ucal_isWeekend(const UCalendar *cal, UDate date, UErrorCode *status);
1445 
1446 /**
1447  * Return the difference between the target time and the time this calendar object is currently set to.
1448  * If the target time is after the current calendar setting, the the returned value will be positive.
1449  * The field parameter specifies the units of the return value. For example, if field is UCAL_MONTH
1450  * and ucal_getFieldDifference returns 3, then the target time is 3 to less than 4 months after the
1451  * current calendar setting.
1452  *
1453  * As a side effect of this call, this calendar is advanced toward target by the given amount. That is,
1454  * calling this function has the side effect of calling ucal_add on this calendar with the specified
1455  * field and an amount equal to the return value from this function.
1456  *
1457  * A typical way of using this function is to call it first with the largest field of interest, then
1458  * with progressively smaller fields.
1459  *
1460  * @param cal The UCalendar to compare and update.
1461  * @param target The target date to compare to the current calendar setting.
1462  * @param field The field to compare; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH,
1463  * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK,
1464  * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND,
1465  * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET.
1466  * @param status A pointer to an UErrorCode to receive any errors
1467  * @return The date difference for the specified field.
1468  * @stable ICU 4.8
1469  */
1470 U_CAPI int32_t U_EXPORT2
1471 ucal_getFieldDifference(UCalendar* cal,
1472                         UDate target,
1473                         UCalendarDateFields field,
1474                         UErrorCode* status);
1475 
1476 /**
1477  * Time zone transition types for ucal_getTimeZoneTransitionDate
1478  * @stable ICU 50
1479  */
1480 enum UTimeZoneTransitionType {
1481     /**
1482      * Get the next transition after the current date,
1483      * i.e. excludes the current date
1484      * @stable ICU 50
1485      */
1486     UCAL_TZ_TRANSITION_NEXT,
1487     /**
1488      * Get the next transition on or after the current date,
1489      * i.e. may include the current date
1490      * @stable ICU 50
1491      */
1492     UCAL_TZ_TRANSITION_NEXT_INCLUSIVE,
1493     /**
1494      * Get the previous transition before the current date,
1495      * i.e. excludes the current date
1496      * @stable ICU 50
1497      */
1498     UCAL_TZ_TRANSITION_PREVIOUS,
1499     /**
1500      * Get the previous transition on or before the current date,
1501      * i.e. may include the current date
1502      * @stable ICU 50
1503      */
1504     UCAL_TZ_TRANSITION_PREVIOUS_INCLUSIVE
1505 };
1506 
1507 typedef enum UTimeZoneTransitionType UTimeZoneTransitionType; /**< @stable ICU 50 */
1508 
1509 /**
1510 * Get the UDate for the next/previous time zone transition relative to
1511 * the calendar's current date, in the time zone to which the calendar
1512 * is currently set. If there is no known time zone transition of the
1513 * requested type relative to the calendar's date, the function returns
1514 * false.
1515 * @param cal The UCalendar to query.
1516 * @param type The type of transition desired.
1517 * @param transition A pointer to a UDate to be set to the transition time.
1518 *         If the function returns false, the value set is unspecified.
1519 * @param status A pointer to a UErrorCode to receive any errors.
1520 * @return true if a valid transition time is set in *transition, false
1521 *         otherwise.
1522 * @stable ICU 50
1523 */
1524 U_CAPI UBool U_EXPORT2
1525 ucal_getTimeZoneTransitionDate(const UCalendar* cal, UTimeZoneTransitionType type,
1526                                UDate* transition, UErrorCode* status);
1527 
1528 /**
1529 * Converts a system time zone ID to an equivalent Windows time zone ID. For example,
1530 * Windows time zone ID "Pacific Standard Time" is returned for input "America/Los_Angeles".
1531 *
1532 * <p>There are system time zones that cannot be mapped to Windows zones. When the input
1533 * system time zone ID is unknown or unmappable to a Windows time zone, then this
1534 * function returns 0 as the result length, but the operation itself remains successful
1535 * (no error status set on return).
1536 *
1537 * <p>This implementation utilizes <a href="http://unicode.org/cldr/charts/supplemental/zone_tzid.html">
1538 * Zone-Tzid mapping data</a>. The mapping data is updated time to time. To get the latest changes,
1539 * please read the ICU user guide section <a href="https://unicode-org.github.io/icu/userguide/datetime/timezone#updating-the-time-zone-data">
1540 * Updating the Time Zone Data</a>.
1541 *
1542 * @param id            A system time zone ID.
1543 * @param len           The length of <code>id</code>, or -1 if null-terminated.
1544 * @param winid         A buffer to receive a Windows time zone ID.
1545 * @param winidCapacity The capacity of the result buffer <code>winid</code>.
1546 * @param status        Receives the status.
1547 * @return              The result string length, not including the terminating null.
1548 * @see ucal_getTimeZoneIDForWindowsID
1549 *
1550 * @stable ICU 52
1551 */
1552 U_CAPI int32_t U_EXPORT2
1553 ucal_getWindowsTimeZoneID(const UChar* id, int32_t len,
1554                             UChar* winid, int32_t winidCapacity, UErrorCode* status);
1555 
1556 /**
1557 * Converts a Windows time zone ID to an equivalent system time zone ID
1558 * for a region. For example, system time zone ID "America/Los_Angeles" is returned
1559 * for input Windows ID "Pacific Standard Time" and region "US" (or <code>null</code>),
1560 * "America/Vancouver" is returned for the same Windows ID "Pacific Standard Time" and
1561 * region "CA".
1562 *
1563 * <p>Not all Windows time zones can be mapped to system time zones. When the input
1564 * Windows time zone ID is unknown or unmappable to a system time zone, then this
1565 * function returns 0 as the result length, but the operation itself remains successful
1566 * (no error status set on return).
1567 *
1568 * <p>This implementation utilizes <a href="http://unicode.org/cldr/charts/supplemental/zone_tzid.html">
1569 * Zone-Tzid mapping data</a>. The mapping data is updated time to time. To get the latest changes,
1570 * please read the ICU user guide section <a href="https://unicode-org.github.io/icu/userguide/datetime/timezone#updating-the-time-zone-data">
1571 * Updating the Time Zone Data</a>.
1572 *
1573 * @param winid         A Windows time zone ID.
1574 * @param len           The length of <code>winid</code>, or -1 if null-terminated.
1575 * @param region        A null-terminated region code, or <code>NULL</code> if no regional preference.
1576 * @param id            A buffer to receive a system time zone ID.
1577 * @param idCapacity    The capacity of the result buffer <code>id</code>.
1578 * @param status        Receives the status.
1579 * @return              The result string length, not including the terminating null.
1580 * @see ucal_getWindowsTimeZoneID
1581 *
1582 * @stable ICU 52
1583 */
1584 U_CAPI int32_t U_EXPORT2
1585 ucal_getTimeZoneIDForWindowsID(const UChar* winid, int32_t len, const char* region,
1586                                 UChar* id, int32_t idCapacity, UErrorCode* status);
1587 
1588 /**
1589  * Options used by ucal_getTimeZoneOffsetFromLocal and BasicTimeZone::getOffsetFromLocal()
1590  * to specify how to interpret an input time when it does not exist, or when it is ambiguous,
1591  * around a time zone transition.
1592  * @stable ICU 69
1593  */
1594 enum UTimeZoneLocalOption {
1595     /**
1596      * An input time is always interpreted as local time before
1597      * a time zone transition.
1598      * @stable ICU 69
1599      */
1600     UCAL_TZ_LOCAL_FORMER = 0x04,
1601     /**
1602      * An input time is always interpreted as local time after
1603      * a time zone transition.
1604      * @stable ICU 69
1605      */
1606     UCAL_TZ_LOCAL_LATTER = 0x0C,
1607     /**
1608      * An input time is interpreted as standard time when local
1609      * time is switched to/from daylight saving time. When both
1610      * sides of a time zone transition are standard time,
1611      * or daylight saving time, the local time before the
1612      * transition is used.
1613      * @stable ICU 69
1614      */
1615     UCAL_TZ_LOCAL_STANDARD_FORMER = UCAL_TZ_LOCAL_FORMER | 0x01,
1616     /**
1617      * An input time is interpreted as standard time when local
1618      * time is switched to/from daylight saving time. When both
1619      * sides of a time zone transition are standard time,
1620      * or daylight saving time, the local time after the
1621      * transition is used.
1622      * @stable ICU 69
1623      */
1624     UCAL_TZ_LOCAL_STANDARD_LATTER = UCAL_TZ_LOCAL_LATTER | 0x01,
1625     /**
1626      * An input time is interpreted as daylight saving time when
1627      * local time is switched to/from standard time. When both
1628      * sides of a time zone transition are standard time,
1629      * or daylight saving time, the local time before the
1630      * transition is used.
1631      * @stable ICU 69
1632      */
1633     UCAL_TZ_LOCAL_DAYLIGHT_FORMER = UCAL_TZ_LOCAL_FORMER | 0x03,
1634     /**
1635      * An input time is interpreted as daylight saving time when
1636      * local time is switched to/from standard time. When both
1637      * sides of a time zone transition are standard time,
1638      * or daylight saving time, the local time after the
1639      * transition is used.
1640      * @stable ICU 69
1641      */
1642     UCAL_TZ_LOCAL_DAYLIGHT_LATTER = UCAL_TZ_LOCAL_LATTER | 0x03,
1643 };
1644 typedef enum UTimeZoneLocalOption UTimeZoneLocalOption; /**< @stable ICU 69 */
1645 
1646 /**
1647 * Returns the time zone raw and GMT offset for the given moment
1648 * in time.  Upon return, local-millis = GMT-millis + rawOffset +
1649 * dstOffset.  All computations are performed in the proleptic
1650 * Gregorian calendar.
1651 *
1652 * @param cal The UCalendar which specify the local date and time value to query.
1653 * @param nonExistingTimeOpt The option to indicate how to interpret the date and
1654 * time in the calendar represent a local time that skipped at a positive time
1655 * zone transitions (e.g. when the daylight saving time starts or the time zone
1656 * offset is increased due to a time zone rule change).
1657 * @param duplicatedTimeOpt The option to indicate how to interpret the date and
1658 * time in the calendar represent a local time that repeating multiple times at a
1659 * negative time zone transition (e.g. when the daylight saving time ends or the
1660 * time zone offset is decreased due to a time zone rule change)
1661 * @param rawOffset output parameter to receive the raw offset, that
1662 * is, the offset not including DST adjustments.
1663 * If the status is set to one of the error code, the value set is unspecified.
1664 * @param dstOffset output parameter to receive the DST offset,
1665 * that is, the offset to be added to `rawOffset' to obtain the
1666 * total offset between local and GMT time. If DST is not in
1667 * effect, this value is zero; otherwise it is a positive value,
1668 * typically one hour.
1669 * If the status is set to one of the error code, the value set is unspecified.
1670 * @param status A pointer to a UErrorCode to receive any errors.
1671 * @stable ICU 69
1672 */
1673 U_CAPI void U_EXPORT2
1674 ucal_getTimeZoneOffsetFromLocal(
1675     const UCalendar* cal,
1676     UTimeZoneLocalOption nonExistingTimeOpt,
1677     UTimeZoneLocalOption duplicatedTimeOpt,
1678     int32_t* rawOffset, int32_t* dstOffset, UErrorCode* status);
1679 
1680 #endif /* #if !UCONFIG_NO_FORMATTING */
1681 
1682 #endif
1683