2 *******************************************************************************
3 * Copyright (C) 1996-2008, International Business Machines Corporation and
4 * others. All Rights Reserved.
5 *******************************************************************************
11 #include "unicode/utypes.h"
12 #include "unicode/uenum.h"
13 #include "unicode/uloc.h"
15 #if !UCONFIG_NO_FORMATTING
19 * \brief C API: Calendar
21 * <h2>Calendar C API</h2>
23 * UCalendar C API is used for converting between a <code>UDate</code> object
24 * and a set of integer fields such as <code>UCAL_YEAR</code>, <code>UCAL_MONTH</code>,
25 * <code>UCAL_DAY</code>, <code>UCAL_HOUR</code>, and so on.
26 * (A <code>UDate</code> object represents a specific instant in
27 * time with millisecond precision. See UDate
28 * for information about the <code>UDate</code> .)
31 * Types of <code>UCalendar</code> interpret a <code>UDate</code>
32 * according to the rules of a specific calendar system. The U_STABLE
33 * provides the enum UCalendarType with UCAL_TRADITIONAL and
36 * Like other locale-sensitive C API, calendar API provides a
37 * function, <code>ucal_open()</code>, which returns a pointer to
38 * <code>UCalendar</code> whose time fields have been initialized
39 * with the current date and time. We need to specify the type of
40 * calendar to be opened and the timezoneId.
41 * \htmlonly<blockquote>\endhtmlonly
47 * tzId=(UChar*)malloc(sizeof(UChar) * (strlen("PST") +1) );
48 * u_uastrcpy(tzId, "PST");
49 * caldef=ucal_open(tzID, u_strlen(tzID), NULL, UCAL_TRADITIONAL, &status);
52 * \htmlonly</blockquote>\endhtmlonly
55 * A <code>UCalendar</code> object can produce all the time field values
56 * needed to implement the date-time formatting for a particular language
57 * and calendar style (for example, Japanese-Gregorian, Japanese-Traditional).
60 * When computing a <code>UDate</code> from time fields, two special circumstances
61 * may arise: there may be insufficient information to compute the
62 * <code>UDate</code> (such as only year and month but no day in the month),
63 * or there may be inconsistent information (such as "Tuesday, July 15, 1996"
64 * -- July 15, 1996 is actually a Monday).
67 * <strong>Insufficient information.</strong> The calendar will use default
68 * information to specify the missing fields. This may vary by calendar; for
69 * the Gregorian calendar, the default for a field is the same as that of the
70 * start of the epoch: i.e., UCAL_YEAR = 1970, UCAL_MONTH = JANUARY, UCAL_DATE = 1, etc.
73 * <strong>Inconsistent information.</strong> If fields conflict, the calendar
74 * will give preference to fields set more recently. For example, when
75 * determining the day, the calendar will look for one of the following
76 * combinations of fields. The most recent combination, as determined by the
77 * most recently set single field, will be used.
79 * \htmlonly<blockquote>\endhtmlonly
82 * UCAL_MONTH + UCAL_DAY_OF_MONTH
83 * UCAL_MONTH + UCAL_WEEK_OF_MONTH + UCAL_DAY_OF_WEEK
84 * UCAL_MONTH + UCAL_DAY_OF_WEEK_IN_MONTH + UCAL_DAY_OF_WEEK
86 * UCAL_DAY_OF_WEEK + UCAL_WEEK_OF_YEAR
89 * \htmlonly</blockquote>\endhtmlonly
91 * For the time of day:
93 * \htmlonly<blockquote>\endhtmlonly
97 * UCAL_AM_PM + UCAL_HOUR
100 * \htmlonly</blockquote>\endhtmlonly
103 * <strong>Note:</strong> for some non-Gregorian calendars, different
104 * fields may be necessary for complete disambiguation. For example, a full
105 * specification of the historial Arabic astronomical calendar requires year,
106 * month, day-of-month <em>and</em> day-of-week in some cases.
109 * <strong>Note:</strong> There are certain possible ambiguities in
110 * interpretation of certain singular times, which are resolved in the
113 * <li> 24:00:00 "belongs" to the following day. That is,
114 * 23:59 on Dec 31, 1969 < 24:00 on Jan 1, 1970 < 24:01:00 on Jan 1, 1970
116 * <li> Although historically not precise, midnight also belongs to "am",
117 * and noon belongs to "pm", so on the same day,
118 * 12:00 am (midnight) < 12:01 am, and 12:00 pm (noon) < 12:01 pm
122 * The date or time format strings are not part of the definition of a
123 * calendar, as those must be modifiable or overridable by the user at
124 * runtime. Use {@link DateFormat}
128 * <code>Calendar</code> provides an API for field "rolling", where fields
129 * can be incremented or decremented, but wrap around. For example, rolling the
130 * month up in the date <code>December 12, <b>1996</b></code> results in
131 * <code>January 12, <b>1996</b></code>.
134 * <code>Calendar</code> also provides a date arithmetic function for
135 * adding the specified (signed) amount of time to a particular time field.
136 * For example, subtracting 5 days from the date <code>September 12, 1996</code>
137 * results in <code>September 7, 1996</code>.
143 * For usage in C programs.
146 typedef void* UCalendar
;
148 /** Possible types of UCalendars
153 * Despite the name, UCAL_TRADITIONAL designates the locale's default calendar,
154 * which may be the Gregorian calendar or some other calendar.
159 * Unambiguously designates the Gregorian calendar for the locale.
164 * A better name for UCAL_TRADITIONAL.
167 UCAL_DEFAULT
= UCAL_TRADITIONAL
170 /** @stable ICU 2.0 */
171 typedef enum UCalendarType UCalendarType
;
173 /** Possible fields in a UCalendar
176 enum UCalendarDateFields
{
178 * Field number indicating the era, e.g., AD or BC in the Gregorian (Julian) calendar.
179 * This is a calendar-specific value.
185 * Field number indicating the year. This is a calendar-specific value.
191 * Field number indicating the month. This is a calendar-specific value.
192 * The first month of the year is
193 * <code>JANUARY</code>; the last depends on the number of months in a year.
195 * @see #UCAL_FEBRUARY
202 * @see #UCAL_SEPTEMBER
204 * @see #UCAL_NOVEMBER
205 * @see #UCAL_DECEMBER
206 * @see #UCAL_UNDECIMBER
212 * Field number indicating the
213 * week number within the current year. The first week of the year, as
214 * defined by <code>UCAL_FIRST_DAY_OF_WEEK</code> and <code>UCAL_MINIMAL_DAYS_IN_FIRST_WEEK</code>
215 * attributes, has value 1. Subclasses define
216 * the value of <code>UCAL_WEEK_OF_YEAR</code> for days before the first week of
218 * @see ucal_getAttribute
219 * @see ucal_setAttribute
225 * Field number indicating the
226 * week number within the current month. The first week of the month, as
227 * defined by <code>UCAL_FIRST_DAY_OF_WEEK</code> and <code>UCAL_MINIMAL_DAYS_IN_FIRST_WEEK</code>
228 * attributes, has value 1. Subclasses define
229 * the value of <code>WEEK_OF_MONTH</code> for days before the first week of
231 * @see ucal_getAttribute
232 * @see ucal_setAttribute
233 * @see #UCAL_FIRST_DAY_OF_WEEK
234 * @see #UCAL_MINIMAL_DAYS_IN_FIRST_WEEK
240 * Field number indicating the
241 * day of the month. This is a synonym for <code>DAY_OF_MONTH</code>.
242 * The first day of the month has value 1.
243 * @see #UCAL_DAY_OF_MONTH
249 * Field number indicating the day
250 * number within the current year. The first day of the year has value 1.
256 * Field number indicating the day
257 * of the week. This field takes values <code>SUNDAY</code>,
258 * <code>MONDAY</code>, <code>TUESDAY</code>, <code>WEDNESDAY</code>,
259 * <code>THURSDAY</code>, <code>FRIDAY</code>, and <code>SATURDAY</code>.
263 * @see #UCAL_WEDNESDAY
264 * @see #UCAL_THURSDAY
266 * @see #UCAL_SATURDAY
272 * Field number indicating the
273 * ordinal number of the day of the week within the current month. Together
274 * with the <code>DAY_OF_WEEK</code> field, this uniquely specifies a day
275 * within a month. Unlike <code>WEEK_OF_MONTH</code> and
276 * <code>WEEK_OF_YEAR</code>, this field's value does <em>not</em> depend on
277 * <code>getFirstDayOfWeek()</code> or
278 * <code>getMinimalDaysInFirstWeek()</code>. <code>DAY_OF_MONTH 1</code>
279 * through <code>7</code> always correspond to <code>DAY_OF_WEEK_IN_MONTH
280 * 1</code>; <code>8</code> through <code>15</code> correspond to
281 * <code>DAY_OF_WEEK_IN_MONTH 2</code>, and so on.
282 * <code>DAY_OF_WEEK_IN_MONTH 0</code> indicates the week before
283 * <code>DAY_OF_WEEK_IN_MONTH 1</code>. Negative values count back from the
284 * end of the month, so the last Sunday of a month is specified as
285 * <code>DAY_OF_WEEK = SUNDAY, DAY_OF_WEEK_IN_MONTH = -1</code>. Because
286 * negative values count backward they will usually be aligned differently
287 * within the month than positive values. For example, if a month has 31
288 * days, <code>DAY_OF_WEEK_IN_MONTH -1</code> will overlap
289 * <code>DAY_OF_WEEK_IN_MONTH 5</code> and the end of <code>4</code>.
290 * @see #UCAL_DAY_OF_WEEK
291 * @see #UCAL_WEEK_OF_MONTH
294 UCAL_DAY_OF_WEEK_IN_MONTH
,
297 * Field number indicating
298 * whether the <code>HOUR</code> is before or after noon.
299 * E.g., at 10:04:15.250 PM the <code>AM_PM</code> is <code>PM</code>.
308 * Field number indicating the
309 * hour of the morning or afternoon. <code>HOUR</code> is used for the 12-hour
311 * E.g., at 10:04:15.250 PM the <code>HOUR</code> is 10.
313 * @see #UCAL_HOUR_OF_DAY
319 * Field number indicating the
320 * hour of the day. <code>HOUR_OF_DAY</code> is used for the 24-hour clock.
321 * E.g., at 10:04:15.250 PM the <code>HOUR_OF_DAY</code> is 22.
328 * Field number indicating the
329 * minute within the hour.
330 * E.g., at 10:04:15.250 PM the <code>UCAL_MINUTE</code> is 4.
336 * Field number indicating the
337 * second within the minute.
338 * E.g., at 10:04:15.250 PM the <code>UCAL_SECOND</code> is 15.
344 * Field number indicating the
345 * millisecond within the second.
346 * E.g., at 10:04:15.250 PM the <code>UCAL_MILLISECOND</code> is 250.
352 * Field number indicating the
353 * raw offset from GMT in milliseconds.
359 * Field number indicating the
360 * daylight savings offset in milliseconds.
367 * indicating the extended year corresponding to the
368 * <code>UCAL_WEEK_OF_YEAR</code> field. This may be one greater or less
369 * than the value of <code>UCAL_EXTENDED_YEAR</code>.
376 * indicating the localized day of week. This will be a value from 1
377 * to 7 inclusive, with 1 being the localized first day of the week.
383 * Year of this calendar system, encompassing all supra-year fields. For example,
384 * in Gregorian/Julian calendars, positive Extended Year values indicate years AD,
385 * 1 BC = 0 extended, 2 BC = -1 extended, and so on.
392 * indicating the modified Julian day number. This is different from
393 * the conventional Julian day number in two regards. First, it
394 * demarcates days at local zone midnight, rather than noon GMT.
395 * Second, it is a local number; that is, it depends on the local time
396 * zone. It can be thought of as a single number that encompasses all
397 * the date-related fields.
403 * Ranges from 0 to 23:59:59.999 (regardless of DST). This field behaves <em>exactly</em>
404 * like a composite of all time-related fields, not including the zone fields. As such,
405 * it also reflects discontinuities of those fields on DST transition days. On a day
406 * of DST onset, it will jump forward. On a day of DST cessation, it will jump
407 * backward. This reflects the fact that it must be combined with the DST_OFFSET field
408 * to obtain a unique local time value.
411 UCAL_MILLISECONDS_IN_DAY
,
414 * Whether or not the current month is a leap month (0 or 1). See the Chinese calendar for
415 * an example of this.
426 * Field number indicating the
427 * day of the month. This is a synonym for <code>UCAL_DATE</code>.
428 * The first day of the month has value 1.
430 * Synonym for UCAL_DATE
433 UCAL_DAY_OF_MONTH
=UCAL_DATE
436 /** @stable ICU 2.0 */
437 typedef enum UCalendarDateFields UCalendarDateFields
;
439 * Useful constant for days of week. Note: Calendar day-of-week is 1-based. Clients
440 * who create locale resources for the field of first-day-of-week should be aware of
441 * this. For instance, in US locale, first-day-of-week is set to 1, i.e., UCAL_SUNDAY.
443 /** Possible days of the week in a UCalendar
446 enum UCalendarDaysOfWeek
{
463 /** @stable ICU 2.0 */
464 typedef enum UCalendarDaysOfWeek UCalendarDaysOfWeek
;
466 /** Possible months in a UCalendar. Note: Calendar month is 0-based.
469 enum UCalendarMonths
{
494 /** Value of the <code>UCAL_MONTH</code> field indicating the
495 * thirteenth month of the year. Although the Gregorian calendar
496 * does not use this value, lunar calendars do.
501 /** @stable ICU 2.0 */
502 typedef enum UCalendarMonths UCalendarMonths
;
504 /** Possible AM/PM values in a UCalendar
507 enum UCalendarAMPMs
{
514 /** @stable ICU 2.0 */
515 typedef enum UCalendarAMPMs UCalendarAMPMs
;
518 * Create an enumeration over all time zones.
520 * @param ec input/output error code
522 * @return an enumeration object that the caller must dispose of using
523 * uenum_close(), or NULL upon failure. In case of failure *ec will
524 * indicate the error.
528 U_STABLE UEnumeration
* U_EXPORT2
529 ucal_openTimeZones(UErrorCode
* ec
);
532 * Create an enumeration over all time zones associated with the given
533 * country. Some zones are affiliated with no country (e.g., "UTC");
534 * these may also be retrieved, as a group.
536 * @param country the ISO 3166 two-letter country code, or NULL to
537 * retrieve zones not affiliated with any country
539 * @param ec input/output error code
541 * @return an enumeration object that the caller must dispose of using
542 * uenum_close(), or NULL upon failure. In case of failure *ec will
543 * indicate the error.
547 U_STABLE UEnumeration
* U_EXPORT2
548 ucal_openCountryTimeZones(const char* country
, UErrorCode
* ec
);
551 * Return the default time zone. The default is determined initially
552 * by querying the host operating system. It may be changed with
553 * ucal_setDefaultTimeZone() or with the C++ TimeZone API.
555 * @param result A buffer to receive the result, or NULL
557 * @param resultCapacity The capacity of the result buffer
559 * @param ec input/output error code
561 * @return The result string length, not including the terminating
566 U_STABLE
int32_t U_EXPORT2
567 ucal_getDefaultTimeZone(UChar
* result
, int32_t resultCapacity
, UErrorCode
* ec
);
570 * Set the default time zone.
572 * @param zoneID null-terminated time zone ID
574 * @param ec input/output error code
578 U_STABLE
void U_EXPORT2
579 ucal_setDefaultTimeZone(const UChar
* zoneID
, UErrorCode
* ec
);
582 * Return the amount of time in milliseconds that the clock is
583 * advanced during daylight savings time for the given time zone, or
584 * zero if the time zone does not observe daylight savings time.
586 * @param zoneID null-terminated time zone ID
588 * @param ec input/output error code
590 * @return the number of milliseconds the time is advanced with
591 * respect to standard time when the daylight savings rules are in
592 * effect. This is always a non-negative number, most commonly either
593 * 3,600,000 (one hour) or zero.
597 U_STABLE
int32_t U_EXPORT2
598 ucal_getDSTSavings(const UChar
* zoneID
, UErrorCode
* ec
);
601 * Get the current date and time.
602 * The value returned is represented as milliseconds from the epoch.
603 * @return The current date and time.
606 U_STABLE UDate U_EXPORT2
611 * A UCalendar may be used to convert a millisecond value to a year,
613 * @param zoneID The desired TimeZone ID. If 0, use the default time zone.
614 * @param len The length of zoneID, or -1 if null-terminated.
615 * @param locale The desired locale
616 * @param type The type of UCalendar to open. This can be UCAL_GREGORIAN to open the Gregorian
617 * calendar for the locale, or UCAL_DEFAULT to open the default calendar for the locale (the
618 * default calendar may also be Gregorian). To open a specific non-Gregorian calendar for the
619 * locale, use uloc_setKeywordValue to set the value of the calendar keyword for the locale
620 * and then pass the locale to ucal_open with UCAL_DEFAULT as the type.
621 * @param status A pointer to an UErrorCode to receive any errors
622 * @return A pointer to a UCalendar, or 0 if an error occurred.
625 U_STABLE UCalendar
* U_EXPORT2
626 ucal_open(const UChar
* zoneID
,
634 * Once closed, a UCalendar may no longer be used.
635 * @param cal The UCalendar to close.
638 U_STABLE
void U_EXPORT2
639 ucal_close(UCalendar
*cal
);
642 * Open a copy of a UCalendar.
643 * This function performs a deep copy.
644 * @param cal The calendar to copy
645 * @param status A pointer to an UErrorCode to receive any errors.
646 * @return A pointer to a UCalendar identical to cal.
649 U_DRAFT UCalendar
* U_EXPORT2
650 ucal_clone(const UCalendar
* cal
,
654 * Set the TimeZone used by a UCalendar.
655 * A UCalendar uses a timezone for converting from Greenwich time to local time.
656 * @param cal The UCalendar to set.
657 * @param zoneID The desired TimeZone ID. If 0, use the default time zone.
658 * @param len The length of zoneID, or -1 if null-terminated.
659 * @param status A pointer to an UErrorCode to receive any errors.
662 U_STABLE
void U_EXPORT2
663 ucal_setTimeZone(UCalendar
* cal
,
669 * Possible formats for a UCalendar's display name
672 enum UCalendarDisplayNameType
{
673 /** Standard display name */
675 /** Short standard display name */
677 /** Daylight savings display name */
679 /** Short daylight savings display name */
683 /** @stable ICU 2.0 */
684 typedef enum UCalendarDisplayNameType UCalendarDisplayNameType
;
687 * Get the display name for a UCalendar's TimeZone.
688 * A display name is suitable for presentation to a user.
689 * @param cal The UCalendar to query.
690 * @param type The desired display name format; one of UCAL_STANDARD, UCAL_SHORT_STANDARD,
691 * UCAL_DST, UCAL_SHORT_DST
692 * @param locale The desired locale for the display name.
693 * @param result A pointer to a buffer to receive the formatted number.
694 * @param resultLength The maximum size of result.
695 * @param status A pointer to an UErrorCode to receive any errors
696 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
699 U_STABLE
int32_t U_EXPORT2
700 ucal_getTimeZoneDisplayName(const UCalendar
* cal
,
701 UCalendarDisplayNameType type
,
704 int32_t resultLength
,
708 * Determine if a UCalendar is currently in daylight savings time.
709 * Daylight savings time is not used in all parts of the world.
710 * @param cal The UCalendar to query.
711 * @param status A pointer to an UErrorCode to receive any errors
712 * @return TRUE if cal is currently in daylight savings time, FALSE otherwise
715 U_STABLE UBool U_EXPORT2
716 ucal_inDaylightTime(const UCalendar
* cal
,
717 UErrorCode
* status
);
720 * Sets the GregorianCalendar change date. This is the point when the switch from
721 * Julian dates to Gregorian dates occurred. Default is 00:00:00 local time, October
722 * 15, 1582. Previous to this time and date will be Julian dates.
724 * This function works only for Gregorian calendars. If the UCalendar is not
725 * an instance of a Gregorian calendar, then a U_UNSUPPORTED_ERROR
728 * @param cal The calendar object.
729 * @param date The given Gregorian cutover date.
730 * @param pErrorCode Pointer to a standard ICU error code. Its input value must
731 * pass the U_SUCCESS() test, or else the function returns
732 * immediately. Check for U_FAILURE() on output or use with
733 * function chaining. (See User Guide for details.)
735 * @see GregorianCalendar::setGregorianChange
736 * @see ucal_getGregorianChange
739 U_STABLE
void U_EXPORT2
740 ucal_setGregorianChange(UCalendar
*cal
, UDate date
, UErrorCode
*pErrorCode
);
743 * Gets the Gregorian Calendar change date. This is the point when the switch from
744 * Julian dates to Gregorian dates occurred. Default is 00:00:00 local time, October
745 * 15, 1582. Previous to this time and date will be Julian dates.
747 * This function works only for Gregorian calendars. If the UCalendar is not
748 * an instance of a Gregorian calendar, then a U_UNSUPPORTED_ERROR
751 * @param cal The calendar object.
752 * @param pErrorCode Pointer to a standard ICU error code. Its input value must
753 * pass the U_SUCCESS() test, or else the function returns
754 * immediately. Check for U_FAILURE() on output or use with
755 * function chaining. (See User Guide for details.)
756 * @return The Gregorian cutover time for this calendar.
758 * @see GregorianCalendar::getGregorianChange
759 * @see ucal_setGregorianChange
762 U_STABLE UDate U_EXPORT2
763 ucal_getGregorianChange(const UCalendar
*cal
, UErrorCode
*pErrorCode
);
766 * Types of UCalendar attributes
769 enum UCalendarAttribute
{
770 /** Lenient parsing */
772 /** First day of week */
773 UCAL_FIRST_DAY_OF_WEEK
,
774 /** Minimum number of days in first week */
775 UCAL_MINIMAL_DAYS_IN_FIRST_WEEK
778 /** @stable ICU 2.0 */
779 typedef enum UCalendarAttribute UCalendarAttribute
;
782 * Get a numeric attribute associated with a UCalendar.
783 * Numeric attributes include the first day of the week, or the minimal numbers
784 * of days in the first week of the month.
785 * @param cal The UCalendar to query.
786 * @param attr The desired attribute; one of UCAL_LENIENT, UCAL_FIRST_DAY_OF_WEEK,
787 * or UCAL_MINIMAL_DAYS_IN_FIRST_WEEK
788 * @return The value of attr.
789 * @see ucal_setAttribute
792 U_STABLE
int32_t U_EXPORT2
793 ucal_getAttribute(const UCalendar
* cal
,
794 UCalendarAttribute attr
);
797 * Set a numeric attribute associated with a UCalendar.
798 * Numeric attributes include the first day of the week, or the minimal numbers
799 * of days in the first week of the month.
800 * @param cal The UCalendar to set.
801 * @param attr The desired attribute; one of UCAL_LENIENT, UCAL_FIRST_DAY_OF_WEEK,
802 * or UCAL_MINIMAL_DAYS_IN_FIRST_WEEK
803 * @param newValue The new value of attr.
804 * @see ucal_getAttribute
807 U_STABLE
void U_EXPORT2
808 ucal_setAttribute(UCalendar
* cal
,
809 UCalendarAttribute attr
,
813 * Get a locale for which calendars are available.
814 * A UCalendar in a locale returned by this function will contain the correct
815 * day and month names for the locale.
816 * @param index The index of the desired locale.
817 * @return A locale for which calendars are available, or 0 if none.
818 * @see ucal_countAvailable
821 U_STABLE
const char* U_EXPORT2
822 ucal_getAvailable(int32_t index
);
825 * Determine how many locales have calendars available.
826 * This function is most useful as determining the loop ending condition for
827 * calls to \ref ucal_getAvailable.
828 * @return The number of locales for which calendars are available.
829 * @see ucal_getAvailable
832 U_STABLE
int32_t U_EXPORT2
833 ucal_countAvailable(void);
836 * Get a UCalendar's current time in millis.
837 * The time is represented as milliseconds from the epoch.
838 * @param cal The UCalendar to query.
839 * @param status A pointer to an UErrorCode to receive any errors
840 * @return The calendar's current time in millis.
841 * @see ucal_setMillis
843 * @see ucal_setDateTime
846 U_STABLE UDate U_EXPORT2
847 ucal_getMillis(const UCalendar
* cal
,
851 * Set a UCalendar's current time in millis.
852 * The time is represented as milliseconds from the epoch.
853 * @param cal The UCalendar to set.
854 * @param dateTime The desired date and time.
855 * @param status A pointer to an UErrorCode to receive any errors
856 * @see ucal_getMillis
858 * @see ucal_setDateTime
861 U_STABLE
void U_EXPORT2
862 ucal_setMillis(UCalendar
* cal
,
864 UErrorCode
* status
);
867 * Set a UCalendar's current date.
868 * The date is represented as a series of 32-bit integers.
869 * @param cal The UCalendar to set.
870 * @param year The desired year.
871 * @param month The desired month; one of UCAL_JANUARY, UCAL_FEBRUARY, UCAL_MARCH, UCAL_APRIL, UCAL_MAY,
872 * UCAL_JUNE, UCAL_JULY, UCAL_AUGUST, UCAL_SEPTEMBER, UCAL_OCTOBER, UCAL_NOVEMBER, UCAL_DECEMBER, UCAL_UNDECIMBER
873 * @param date The desired day of the month.
874 * @param status A pointer to an UErrorCode to receive any errors
875 * @see ucal_getMillis
876 * @see ucal_setMillis
877 * @see ucal_setDateTime
880 U_STABLE
void U_EXPORT2
881 ucal_setDate(UCalendar
* cal
,
888 * Set a UCalendar's current date.
889 * The date is represented as a series of 32-bit integers.
890 * @param cal The UCalendar to set.
891 * @param year The desired year.
892 * @param month The desired month; one of UCAL_JANUARY, UCAL_FEBRUARY, UCAL_MARCH, UCAL_APRIL, UCAL_MAY,
893 * UCAL_JUNE, UCAL_JULY, UCAL_AUGUST, UCAL_SEPTEMBER, UCAL_OCTOBER, UCAL_NOVEMBER, UCAL_DECEMBER, UCAL_UNDECIMBER
894 * @param date The desired day of the month.
895 * @param hour The desired hour of day.
896 * @param minute The desired minute.
897 * @param second The desirec second.
898 * @param status A pointer to an UErrorCode to receive any errors
899 * @see ucal_getMillis
900 * @see ucal_setMillis
904 U_STABLE
void U_EXPORT2
905 ucal_setDateTime(UCalendar
* cal
,
915 * Returns TRUE if two UCalendars are equivalent. Equivalent
916 * UCalendars will behave identically, but they may be set to
918 * @param cal1 The first of the UCalendars to compare.
919 * @param cal2 The second of the UCalendars to compare.
920 * @return TRUE if cal1 and cal2 are equivalent, FALSE otherwise.
923 U_STABLE UBool U_EXPORT2
924 ucal_equivalentTo(const UCalendar
* cal1
,
925 const UCalendar
* cal2
);
928 * Add a specified signed amount to a particular field in a UCalendar.
929 * This can modify more significant fields in the calendar.
930 * @param cal The UCalendar to which to add.
931 * @param field The field to which to add the signed value; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH,
932 * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK,
933 * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND,
934 * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET.
935 * @param amount The signed amount to add to field. If the amount causes the value
936 * to exceed to maximum or minimum values for that field, other fields are modified
937 * to preserve the magnitude of the change.
938 * @param status A pointer to an UErrorCode to receive any errors
942 U_STABLE
void U_EXPORT2
943 ucal_add(UCalendar
* cal
,
944 UCalendarDateFields field
,
949 * Add a specified signed amount to a particular field in a UCalendar.
950 * This will not modify more significant fields in the calendar.
951 * @param cal The UCalendar to which to add.
952 * @param field The field to which to add the signed value; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH,
953 * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK,
954 * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND,
955 * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET.
956 * @param amount The signed amount to add to field. If the amount causes the value
957 * to exceed to maximum or minimum values for that field, the field is pinned to a permissible
959 * @param status A pointer to an UErrorCode to receive any errors
963 U_STABLE
void U_EXPORT2
964 ucal_roll(UCalendar
* cal
,
965 UCalendarDateFields field
,
970 * Get the current value of a field from a UCalendar.
971 * All fields are represented as 32-bit integers.
972 * @param cal The UCalendar to query.
973 * @param field The desired field; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH,
974 * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK,
975 * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND,
976 * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET.
977 * @param status A pointer to an UErrorCode to receive any errors
978 * @return The value of the desired field.
981 * @see ucal_clearField
985 U_STABLE
int32_t U_EXPORT2
986 ucal_get(const UCalendar
* cal
,
987 UCalendarDateFields field
,
988 UErrorCode
* status
);
991 * Set the value of a field in a UCalendar.
992 * All fields are represented as 32-bit integers.
993 * @param cal The UCalendar to set.
994 * @param field The field to set; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH,
995 * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK,
996 * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND,
997 * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET.
998 * @param value The desired value of field.
1001 * @see ucal_clearField
1005 U_STABLE
void U_EXPORT2
1006 ucal_set(UCalendar
* cal
,
1007 UCalendarDateFields field
,
1011 * Determine if a field in a UCalendar is set.
1012 * All fields are represented as 32-bit integers.
1013 * @param cal The UCalendar to query.
1014 * @param field The desired field; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH,
1015 * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK,
1016 * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND,
1017 * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET.
1018 * @return TRUE if field is set, FALSE otherwise.
1021 * @see ucal_clearField
1025 U_STABLE UBool U_EXPORT2
1026 ucal_isSet(const UCalendar
* cal
,
1027 UCalendarDateFields field
);
1030 * Clear a field in a UCalendar.
1031 * All fields are represented as 32-bit integers.
1032 * @param cal The UCalendar containing the field to clear.
1033 * @param field The field to clear; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH,
1034 * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK,
1035 * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND,
1036 * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET.
1043 U_STABLE
void U_EXPORT2
1044 ucal_clearField(UCalendar
* cal
,
1045 UCalendarDateFields field
);
1048 * Clear all fields in a UCalendar.
1049 * All fields are represented as 32-bit integers.
1050 * @param calendar The UCalendar to clear.
1054 * @see ucal_clearField
1057 U_STABLE
void U_EXPORT2
1058 ucal_clear(UCalendar
* calendar
);
1061 * Possible limit values for a UCalendar
1064 enum UCalendarLimitType
{
1065 /** Minimum value */
1067 /** Maximum value */
1069 /** Greatest minimum value */
1070 UCAL_GREATEST_MINIMUM
,
1071 /** Leaest maximum value */
1073 /** Actual minimum value */
1074 UCAL_ACTUAL_MINIMUM
,
1075 /** Actual maximum value */
1079 /** @stable ICU 2.0 */
1080 typedef enum UCalendarLimitType UCalendarLimitType
;
1083 * Determine a limit for a field in a UCalendar.
1084 * A limit is a maximum or minimum value for a field.
1085 * @param cal The UCalendar to query.
1086 * @param field The desired field; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH,
1087 * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK,
1088 * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND,
1089 * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET.
1090 * @param type The desired critical point; one of UCAL_MINIMUM, UCAL_MAXIMUM, UCAL_GREATEST_MINIMUM,
1091 * UCAL_LEAST_MAXIMUM, UCAL_ACTUAL_MINIMUM, UCAL_ACTUAL_MAXIMUM
1092 * @param status A pointer to an UErrorCode to receive any errors.
1093 * @return The requested value.
1096 U_STABLE
int32_t U_EXPORT2
1097 ucal_getLimit(const UCalendar
* cal
,
1098 UCalendarDateFields field
,
1099 UCalendarLimitType type
,
1100 UErrorCode
* status
);
1102 /** Get the locale for this calendar object. You can choose between valid and actual locale.
1103 * @param cal The calendar object
1104 * @param type type of the locale we're looking for (valid or actual)
1105 * @param status error code for the operation
1106 * @return the locale name
1109 U_STABLE
const char * U_EXPORT2
1110 ucal_getLocaleByType(const UCalendar
*cal
, ULocDataLocaleType type
, UErrorCode
* status
);
1113 * Returns the timezone data version currently used by ICU.
1114 * @param status error code for the operation
1115 * @return the version string, such as "2007f"
1118 U_DRAFT
const char * U_EXPORT2
1119 ucal_getTZDataVersion(UErrorCode
* status
);
1122 * Returns the canonical system timezone ID or the normalized
1123 * custom time zone ID for the given time zone ID.
1124 * @param id The input timezone ID to be canonicalized.
1125 * @param len The length of id, or -1 if null-terminated.
1126 * @param result The buffer receives the canonical system timezone ID
1127 * or the custom timezone ID in normalized format.
1128 * @param resultCapacity The capacity of the result buffer.
1129 * @param isSystemID Receives if the given ID is a known system
1131 * @param status Recevies the status. When the given timezone ID
1132 * is neither a known system time zone ID nor a
1133 * valid custom timezone ID, U_ILLEGAL_ARGUMENT_ERROR
1135 * @return The result string length, not including the terminating
1139 U_DRAFT
int32_t U_EXPORT2
1140 ucal_getCanonicalTimeZoneID(const UChar
* id
, int32_t len
,
1141 UChar
* result
, int32_t resultCapacity
, UBool
*isSystemID
, UErrorCode
* status
);
1143 * Get the resource keyword value string designating the calendar type for the UCalendar.
1144 * @param cal The UCalendar to query.
1145 * @param status The error code for the operation.
1146 * @return The resource keyword value string.
1149 U_DRAFT
const char * U_EXPORT2
1150 ucal_getType(const UCalendar
*cal
, UErrorCode
* status
);
1153 * The following is a temporary Apple-specific API to help InternationalPrefs
1154 * transition to the updated version of the above ICU API. It will be removed soon.
1156 U_DRAFT
const char * U_EXPORT2
1157 ucal_getTypeWithError(const UCalendar
*cal
, UErrorCode
* status
);
1159 #endif /* #if !UCONFIG_NO_FORMATTING */