2 *******************************************************************************
3 * Copyright (C) 1996-2006, 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
152 /** A traditional calendar for the locale */
154 /** The Gregorian calendar */
158 /** @stable ICU 2.0 */
159 typedef enum UCalendarType UCalendarType
;
161 /** Possible fields in a UCalendar
164 enum UCalendarDateFields
{
166 * Field number indicating the era, e.g., AD or BC in the Gregorian (Julian) calendar.
167 * This is a calendar-specific value.
173 * Field number indicating the year. This is a calendar-specific value.
179 * Field number indicating the month. This is a calendar-specific value.
180 * The first month of the year is
181 * <code>JANUARY</code>; the last depends on the number of months in a year.
183 * @see #UCAL_FEBRUARY
190 * @see #UCAL_SEPTEMBER
192 * @see #UCAL_NOVEMBER
193 * @see #UCAL_DECEMBER
194 * @see #UCAL_UNDECIMBER
200 * Field number indicating the
201 * week number within the current year. The first week of the year, as
202 * defined by <code>UCAL_FIRST_DAY_OF_WEEK</code> and <code>UCAL_MINIMAL_DAYS_IN_FIRST_WEEK</code>
203 * attributes, has value 1. Subclasses define
204 * the value of <code>UCAL_WEEK_OF_YEAR</code> for days before the first week of
206 * @see ucal_setAttribute
212 * Field number indicating the
213 * week number within the current month. The first week of the month, 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>WEEK_OF_MONTH</code> for days before the first week of
218 * @see #getFirstDayOfWeek
219 * @see #getMinimalDaysInFirstWeek
225 * Field number indicating the
226 * day of the month. This is a synonym for <code>DAY_OF_MONTH</code>.
227 * The first day of the month has value 1.
234 * Field number indicating the day
235 * number within the current year. The first day of the year has value 1.
241 * Field number indicating the day
242 * of the week. This field takes values <code>SUNDAY</code>,
243 * <code>MONDAY</code>, <code>TUESDAY</code>, <code>WEDNESDAY</code>,
244 * <code>THURSDAY</code>, <code>FRIDAY</code>, and <code>SATURDAY</code>.
258 * Field number indicating the
259 * ordinal number of the day of the week within the current month. Together
260 * with the <code>DAY_OF_WEEK</code> field, this uniquely specifies a day
261 * within a month. Unlike <code>WEEK_OF_MONTH</code> and
262 * <code>WEEK_OF_YEAR</code>, this field's value does <em>not</em> depend on
263 * <code>getFirstDayOfWeek()</code> or
264 * <code>getMinimalDaysInFirstWeek()</code>. <code>DAY_OF_MONTH 1</code>
265 * through <code>7</code> always correspond to <code>DAY_OF_WEEK_IN_MONTH
266 * 1</code>; <code>8</code> through <code>15</code> correspond to
267 * <code>DAY_OF_WEEK_IN_MONTH 2</code>, and so on.
268 * <code>DAY_OF_WEEK_IN_MONTH 0</code> indicates the week before
269 * <code>DAY_OF_WEEK_IN_MONTH 1</code>. Negative values count back from the
270 * end of the month, so the last Sunday of a month is specified as
271 * <code>DAY_OF_WEEK = SUNDAY, DAY_OF_WEEK_IN_MONTH = -1</code>. Because
272 * negative values count backward they will usually be aligned differently
273 * within the month than positive values. For example, if a month has 31
274 * days, <code>DAY_OF_WEEK_IN_MONTH -1</code> will overlap
275 * <code>DAY_OF_WEEK_IN_MONTH 5</code> and the end of <code>4</code>.
277 * @see #WEEK_OF_MONTH
280 UCAL_DAY_OF_WEEK_IN_MONTH
,
283 * Field number indicating
284 * whether the <code>HOUR</code> is before or after noon.
285 * E.g., at 10:04:15.250 PM the <code>AM_PM</code> is <code>PM</code>.
294 * Field number indicating the
295 * hour of the morning or afternoon. <code>HOUR</code> is used for the 12-hour
297 * E.g., at 10:04:15.250 PM the <code>HOUR</code> is 10.
299 * @see #UCAL_HOUR_OF_DAY
305 * Field number indicating the
306 * hour of the day. <code>HOUR_OF_DAY</code> is used for the 24-hour clock.
307 * E.g., at 10:04:15.250 PM the <code>HOUR_OF_DAY</code> is 22.
314 * Field number indicating the
315 * minute within the hour.
316 * E.g., at 10:04:15.250 PM the <code>UCAL_MINUTE</code> is 4.
322 * Field number indicating the
323 * second within the minute.
324 * E.g., at 10:04:15.250 PM the <code>UCAL_SECOND</code> is 15.
330 * Field number indicating the
331 * millisecond within the second.
332 * E.g., at 10:04:15.250 PM the <code>UCAL_MILLISECOND</code> is 250.
338 * Field number indicating the
339 * raw offset from GMT in milliseconds.
345 * Field number indicating the
346 * daylight savings offset in milliseconds.
353 * indicating the extended year corresponding to the
354 * <code>UCAL_WEEK_OF_YEAR</code> field. This may be one greater or less
355 * than the value of <code>UCAL_EXTENDED_YEAR</code>.
362 * indicating the localized day of week. This will be a value from 1
363 * to 7 inclusive, with 1 being the localized first day of the week.
369 * Year of this calendar system, encompassing all supra-year fields. For example,
370 * in Gregorian/Julian calendars, positive Extended Year values indicate years AD,
371 * 1 BC = 0 extended, 2 BC = -1 extended, and so on.
378 * indicating the modified Julian day number. This is different from
379 * the conventional Julian day number in two regards. First, it
380 * demarcates days at local zone midnight, rather than noon GMT.
381 * Second, it is a local number; that is, it depends on the local time
382 * zone. It can be thought of as a single number that encompasses all
383 * the date-related fields.
389 * Ranges from 0 to 23:59:59.999 (regardless of DST). This field behaves <em>exactly</em>
390 * like a composite of all time-related fields, not including the zone fields. As such,
391 * it also reflects discontinuities of those fields on DST transition days. On a day
392 * of DST onset, it will jump forward. On a day of DST cessation, it will jump
393 * backward. This reflects the fact that it must be combined with the DST_OFFSET field
394 * to obtain a unique local time value.
397 UCAL_MILLISECONDS_IN_DAY
,
406 * Field number indicating the
407 * day of the month. This is a synonym for <code>UCAL_DATE</code>.
408 * The first day of the month has value 1.
410 * Synonym for UCAL_DATE
413 UCAL_DAY_OF_MONTH
=UCAL_DATE
416 /** @stable ICU 2.0 */
417 typedef enum UCalendarDateFields UCalendarDateFields
;
419 * Useful constant for days of week. Note: Calendar day-of-week is 1-based. Clients
420 * who create locale resources for the field of first-day-of-week should be aware of
421 * this. For instance, in US locale, first-day-of-week is set to 1, i.e., UCAL_SUNDAY.
423 /** Possible days of the week in a UCalendar
426 enum UCalendarDaysOfWeek
{
443 /** @stable ICU 2.0 */
444 typedef enum UCalendarDaysOfWeek UCalendarDaysOfWeek
;
446 /** Possible months in a UCalendar. Note: Calendar month is 0-based.
449 enum UCalendarMonths
{
474 /** Value of the <code>UCAL_MONTH</code> field indicating the
475 * thirteenth month of the year. Although the Gregorian calendar
476 * does not use this value, lunar calendars do.
481 /** @stable ICU 2.0 */
482 typedef enum UCalendarMonths UCalendarMonths
;
484 /** Possible AM/PM values in a UCalendar
487 enum UCalendarAMPMs
{
494 /** @stable ICU 2.0 */
495 typedef enum UCalendarAMPMs UCalendarAMPMs
;
498 * Create an enumeration over all time zones.
500 * @param ec input/output error code
502 * @return an enumeration object that the caller must dispose of using
503 * uenum_close(), or NULL upon failure. In case of failure *ec will
504 * indicate the error.
508 U_STABLE UEnumeration
* U_EXPORT2
509 ucal_openTimeZones(UErrorCode
* ec
);
512 * Create an enumeration over all time zones associated with the given
513 * country. Some zones are affiliated with no country (e.g., "UTC");
514 * these may also be retrieved, as a group.
516 * @param country the ISO 3166 two-letter country code, or NULL to
517 * retrieve zones not affiliated with any country
519 * @param ec input/output error code
521 * @return an enumeration object that the caller must dispose of using
522 * uenum_close(), or NULL upon failure. In case of failure *ec will
523 * indicate the error.
527 U_STABLE UEnumeration
* U_EXPORT2
528 ucal_openCountryTimeZones(const char* country
, UErrorCode
* ec
);
531 * Return the default time zone. The default is determined initially
532 * by querying the host operating system. It may be changed with
533 * ucal_setDefaultTimeZone() or with the C++ TimeZone API.
535 * @param result A buffer to receive the result, or NULL
537 * @param resultCapacity The capacity of the result buffer
539 * @param ec input/output error code
541 * @return The result string length, not including the terminating
546 U_STABLE
int32_t U_EXPORT2
547 ucal_getDefaultTimeZone(UChar
* result
, int32_t resultCapacity
, UErrorCode
* ec
);
550 * Set the default time zone.
552 * @param zoneID null-terminated time zone ID
554 * @param ec input/output error code
558 U_STABLE
void U_EXPORT2
559 ucal_setDefaultTimeZone(const UChar
* zoneID
, UErrorCode
* ec
);
562 * Return the amount of time in milliseconds that the clock is
563 * advanced during daylight savings time for the given time zone, or
564 * zero if the time zone does not observe daylight savings time.
566 * @param zoneID null-terminated time zone ID
568 * @param ec input/output error code
570 * @return the number of milliseconds the time is advanced with
571 * respect to standard time when the daylight savings rules are in
572 * effect. This is always a non-negative number, most commonly either
573 * 3,600,000 (one hour) or zero.
577 U_STABLE
int32_t U_EXPORT2
578 ucal_getDSTSavings(const UChar
* zoneID
, UErrorCode
* ec
);
581 * Get the current date and time.
582 * The value returned is represented as milliseconds from the epoch.
583 * @return The current date and time.
586 U_STABLE UDate U_EXPORT2
591 * A UCalendar may be used to convert a millisecond value to a year,
593 * @param zoneID The desired TimeZone ID. If 0, use the default time zone.
594 * @param len The length of zoneID, or -1 if null-terminated.
595 * @param locale The desired locale
596 * @param type The type of UCalendar to open.
597 * @param status A pointer to an UErrorCode to receive any errors
598 * @return A pointer to a UCalendar, or 0 if an error occurred.
601 U_STABLE UCalendar
* U_EXPORT2
602 ucal_open(const UChar
* zoneID
,
610 * Once closed, a UCalendar may no longer be used.
611 * @param cal The UCalendar to close.
614 U_STABLE
void U_EXPORT2
615 ucal_close(UCalendar
*cal
);
618 * Set the TimeZone used by a UCalendar.
619 * A UCalendar uses a timezone for converting from Greenwich time to local time.
620 * @param cal The UCalendar to set.
621 * @param zoneID The desired TimeZone ID. If 0, use the default time zone.
622 * @param len The length of zoneID, or -1 if null-terminated.
623 * @param status A pointer to an UErrorCode to receive any errors.
626 U_STABLE
void U_EXPORT2
627 ucal_setTimeZone(UCalendar
* cal
,
633 * Possible formats for a UCalendar's display name
636 enum UCalendarDisplayNameType
{
637 /** Standard display name */
639 /** Short standard display name */
641 /** Daylight savings display name */
643 /** Short daylight savings display name */
647 /** @stable ICU 2.0 */
648 typedef enum UCalendarDisplayNameType UCalendarDisplayNameType
;
651 * Get the display name for a UCalendar's TimeZone.
652 * A display name is suitable for presentation to a user.
653 * @param cal The UCalendar to query.
654 * @param type The desired display name format; one of UCAL_STANDARD, UCAL_SHORT_STANDARD,
655 * UCAL_DST, UCAL_SHORT_DST
656 * @param locale The desired locale for the display name.
657 * @param result A pointer to a buffer to receive the formatted number.
658 * @param resultLength The maximum size of result.
659 * @param status A pointer to an UErrorCode to receive any errors
660 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
663 U_STABLE
int32_t U_EXPORT2
664 ucal_getTimeZoneDisplayName(const UCalendar
* cal
,
665 UCalendarDisplayNameType type
,
668 int32_t resultLength
,
672 * Determine if a UCalendar is currently in daylight savings time.
673 * Daylight savings time is not used in all parts of the world.
674 * @param cal The UCalendar to query.
675 * @param status A pointer to an UErrorCode to receive any errors
676 * @return TRUE if cal is currently in daylight savings time, FALSE otherwise
679 U_STABLE UBool U_EXPORT2
680 ucal_inDaylightTime(const UCalendar
* cal
,
681 UErrorCode
* status
);
684 * Sets the GregorianCalendar change date. This is the point when the switch from
685 * Julian dates to Gregorian dates occurred. Default is 00:00:00 local time, October
686 * 15, 1582. Previous to this time and date will be Julian dates.
688 * This function works only for Gregorian calendars. If the UCalendar is not
689 * an instance of a Gregorian calendar, then a U_UNSUPPORTED_ERROR
692 * @param cal The calendar object.
693 * @param date The given Gregorian cutover date.
694 * @param pErrorCode Pointer to a standard ICU error code. Its input value must
695 * pass the U_SUCCESS() test, or else the function returns
696 * immediately. Check for U_FAILURE() on output or use with
697 * function chaining. (See User Guide for details.)
699 * @see GregorianCalendar::setGregorianChange
700 * @see ucal_getGregorianChange
703 U_DRAFT
void U_EXPORT2
704 ucal_setGregorianChange(UCalendar
*cal
, UDate date
, UErrorCode
*pErrorCode
);
707 * Gets the Gregorian Calendar change date. This is the point when the switch from
708 * Julian dates to Gregorian dates occurred. Default is 00:00:00 local time, October
709 * 15, 1582. Previous to this time and date will be Julian dates.
711 * This function works only for Gregorian calendars. If the UCalendar is not
712 * an instance of a Gregorian calendar, then a U_UNSUPPORTED_ERROR
715 * @param cal The calendar object.
716 * @param pErrorCode Pointer to a standard ICU error code. Its input value must
717 * pass the U_SUCCESS() test, or else the function returns
718 * immediately. Check for U_FAILURE() on output or use with
719 * function chaining. (See User Guide for details.)
720 * @return The Gregorian cutover time for this calendar.
722 * @see GregorianCalendar::getGregorianChange
723 * @see ucal_setGregorianChange
726 U_DRAFT UDate U_EXPORT2
727 ucal_getGregorianChange(const UCalendar
*cal
, UErrorCode
*pErrorCode
);
730 * Types of UCalendar attributes
733 enum UCalendarAttribute
{
734 /** Lenient parsing */
736 /** First day of week */
737 UCAL_FIRST_DAY_OF_WEEK
,
738 /** Minimum number of days in first week */
739 UCAL_MINIMAL_DAYS_IN_FIRST_WEEK
742 /** @stable ICU 2.0 */
743 typedef enum UCalendarAttribute UCalendarAttribute
;
746 * Get a numeric attribute associated with a UCalendar.
747 * Numeric attributes include the first day of the week, or the minimal numbers
748 * of days in the first week of the month.
749 * @param cal The UCalendar to query.
750 * @param attr The desired attribute; one of UCAL_LENIENT, UCAL_FIRST_DAY_OF_WEEK,
751 * or UCAL_MINIMAL_DAYS_IN_FIRST_WEEK
752 * @return The value of attr.
753 * @see ucal_setAttribute
756 U_STABLE
int32_t U_EXPORT2
757 ucal_getAttribute(const UCalendar
* cal
,
758 UCalendarAttribute attr
);
761 * Set a numeric attribute associated with a UCalendar.
762 * Numeric attributes include the first day of the week, or the minimal numbers
763 * of days in the first week of the month.
764 * @param cal The UCalendar to set.
765 * @param attr The desired attribute; one of UCAL_LENIENT, UCAL_FIRST_DAY_OF_WEEK,
766 * or UCAL_MINIMAL_DAYS_IN_FIRST_WEEK
767 * @param newValue The new value of attr.
768 * @see ucal_getAttribute
771 U_STABLE
void U_EXPORT2
772 ucal_setAttribute(UCalendar
* cal
,
773 UCalendarAttribute attr
,
777 * Get a locale for which calendars are available.
778 * A UCalendar in a locale returned by this function will contain the correct
779 * day and month names for the locale.
780 * @param index The index of the desired locale.
781 * @return A locale for which calendars are available, or 0 if none.
782 * @see ucal_countAvailable
785 U_STABLE
const char* U_EXPORT2
786 ucal_getAvailable(int32_t index
);
789 * Determine how many locales have calendars available.
790 * This function is most useful as determining the loop ending condition for
791 * calls to \ref ucal_getAvailable.
792 * @return The number of locales for which calendars are available.
793 * @see ucal_getAvailable
796 U_STABLE
int32_t U_EXPORT2
797 ucal_countAvailable(void);
800 * Get a UCalendar's current time in millis.
801 * The time is represented as milliseconds from the epoch.
802 * @param cal The UCalendar to query.
803 * @param status A pointer to an UErrorCode to receive any errors
804 * @return The calendar's current time in millis.
805 * @see ucal_setMillis
807 * @see ucal_setDateTime
810 U_STABLE UDate U_EXPORT2
811 ucal_getMillis(const UCalendar
* cal
,
815 * Set a UCalendar's current time in millis.
816 * The time is represented as milliseconds from the epoch.
817 * @param cal The UCalendar to set.
818 * @param dateTime The desired date and time.
819 * @param status A pointer to an UErrorCode to receive any errors
820 * @see ucal_getMillis
822 * @see ucal_setDateTime
825 U_STABLE
void U_EXPORT2
826 ucal_setMillis(UCalendar
* cal
,
828 UErrorCode
* status
);
831 * Set a UCalendar's current date.
832 * The date is represented as a series of 32-bit integers.
833 * @param cal The UCalendar to set.
834 * @param year The desired year.
835 * @param month The desired month; one of UCAL_JANUARY, UCAL_FEBRUARY, UCAL_MARCH, UCAL_APRIL, UCAL_MAY,
836 * UCAL_JUNE, UCAL_JULY, UCAL_AUGUST, UCAL_SEPTEMBER, UCAL_OCTOBER, UCAL_NOVEMBER, UCAL_DECEMBER, UCAL_UNDECIMBER
837 * @param date The desired day of the month.
838 * @param status A pointer to an UErrorCode to receive any errors
839 * @see ucal_getMillis
840 * @see ucal_setMillis
841 * @see ucal_setDateTime
844 U_STABLE
void U_EXPORT2
845 ucal_setDate(UCalendar
* cal
,
852 * Set a UCalendar's current date.
853 * The date is represented as a series of 32-bit integers.
854 * @param cal The UCalendar to set.
855 * @param year The desired year.
856 * @param month The desired month; one of UCAL_JANUARY, UCAL_FEBRUARY, UCAL_MARCH, UCAL_APRIL, UCAL_MAY,
857 * UCAL_JUNE, UCAL_JULY, UCAL_AUGUST, UCAL_SEPTEMBER, UCAL_OCTOBER, UCAL_NOVEMBER, UCAL_DECEMBER, UCAL_UNDECIMBER
858 * @param date The desired day of the month.
859 * @param hour The desired hour of day.
860 * @param minute The desired minute.
861 * @param second The desirec second.
862 * @param status A pointer to an UErrorCode to receive any errors
863 * @see ucal_getMillis
864 * @see ucal_setMillis
868 U_STABLE
void U_EXPORT2
869 ucal_setDateTime(UCalendar
* cal
,
879 * Returns TRUE if two UCalendars are equivalent. Equivalent
880 * UCalendars will behave identically, but they may be set to
882 * @param cal1 The first of the UCalendars to compare.
883 * @param cal2 The second of the UCalendars to compare.
884 * @return TRUE if cal1 and cal2 are equivalent, FALSE otherwise.
887 U_STABLE UBool U_EXPORT2
888 ucal_equivalentTo(const UCalendar
* cal1
,
889 const UCalendar
* cal2
);
892 * Add a specified signed amount to a particular field in a UCalendar.
893 * This can modify more significant fields in the calendar.
894 * @param cal The UCalendar to which to add.
895 * @param field The field to which to add the signed value; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH,
896 * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK,
897 * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND,
898 * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET.
899 * @param amount The signed amount to add to field. If the amount causes the value
900 * to exceed to maximum or minimum values for that field, other fields are modified
901 * to preserve the magnitude of the change.
902 * @param status A pointer to an UErrorCode to receive any errors
906 U_STABLE
void U_EXPORT2
907 ucal_add(UCalendar
* cal
,
908 UCalendarDateFields field
,
913 * Add a specified signed amount to a particular field in a UCalendar.
914 * This will not modify more significant fields in the calendar.
915 * @param cal The UCalendar to which to add.
916 * @param field The field to which to add the signed value; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH,
917 * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK,
918 * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND,
919 * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET.
920 * @param amount The signed amount to add to field. If the amount causes the value
921 * to exceed to maximum or minimum values for that field, the field is pinned to a permissible
923 * @param status A pointer to an UErrorCode to receive any errors
927 U_STABLE
void U_EXPORT2
928 ucal_roll(UCalendar
* cal
,
929 UCalendarDateFields field
,
934 * Get the current value of a field from a UCalendar.
935 * All fields are represented as 32-bit integers.
936 * @param cal The UCalendar to query.
937 * @param field The desired field; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH,
938 * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK,
939 * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND,
940 * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET.
941 * @param status A pointer to an UErrorCode to receive any errors
942 * @return The value of the desired field.
945 * @see ucal_clearField
949 U_STABLE
int32_t U_EXPORT2
950 ucal_get(const UCalendar
* cal
,
951 UCalendarDateFields field
,
952 UErrorCode
* status
);
955 * Set the value of a field in a UCalendar.
956 * All fields are represented as 32-bit integers.
957 * @param cal The UCalendar to set.
958 * @param field The field to set; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH,
959 * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK,
960 * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND,
961 * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET.
962 * @param value The desired value of field.
965 * @see ucal_clearField
969 U_STABLE
void U_EXPORT2
970 ucal_set(UCalendar
* cal
,
971 UCalendarDateFields field
,
975 * Determine if a field in a UCalendar is set.
976 * All fields are represented as 32-bit integers.
977 * @param cal The UCalendar to query.
978 * @param field The desired field; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH,
979 * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK,
980 * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND,
981 * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET.
982 * @return TRUE if field is set, FALSE otherwise.
985 * @see ucal_clearField
989 U_STABLE UBool U_EXPORT2
990 ucal_isSet(const UCalendar
* cal
,
991 UCalendarDateFields field
);
994 * Clear a field in a UCalendar.
995 * All fields are represented as 32-bit integers.
996 * @param cal The UCalendar containing the field to clear.
997 * @param field The field to clear; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH,
998 * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK,
999 * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND,
1000 * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET.
1007 U_STABLE
void U_EXPORT2
1008 ucal_clearField(UCalendar
* cal
,
1009 UCalendarDateFields field
);
1012 * Clear all fields in a UCalendar.
1013 * All fields are represented as 32-bit integers.
1014 * @param calendar The UCalendar to clear.
1018 * @see ucal_clearField
1021 U_STABLE
void U_EXPORT2
1022 ucal_clear(UCalendar
* calendar
);
1025 * Possible limit values for a UCalendar
1028 enum UCalendarLimitType
{
1029 /** Minimum value */
1031 /** Maximum value */
1033 /** Greatest minimum value */
1034 UCAL_GREATEST_MINIMUM
,
1035 /** Leaest maximum value */
1037 /** Actual minimum value */
1038 UCAL_ACTUAL_MINIMUM
,
1039 /** Actual maximum value */
1043 /** @stable ICU 2.0 */
1044 typedef enum UCalendarLimitType UCalendarLimitType
;
1047 * Determine a limit for a field in a UCalendar.
1048 * A limit is a maximum or minimum value for a field.
1049 * @param cal The UCalendar to query.
1050 * @param field The desired field; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH,
1051 * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK,
1052 * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND,
1053 * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET.
1054 * @param type The desired critical point; one of UCAL_MINIMUM, UCAL_MAXIMUM, UCAL_GREATEST_MINIMUM,
1055 * UCAL_LEAST_MAXIMUM, UCAL_ACTUAL_MINIMUM, UCAL_ACTUAL_MAXIMUM
1056 * @param status A pointer to an UErrorCode to receive any errors.
1057 * @return The requested value.
1060 U_STABLE
int32_t U_EXPORT2
1061 ucal_getLimit(const UCalendar
* cal
,
1062 UCalendarDateFields field
,
1063 UCalendarLimitType type
,
1064 UErrorCode
* status
);
1066 #ifdef U_USE_UCAL_OBSOLETE_2_8
1068 * Get an available TimeZone ID.
1069 * A Timezone ID is a string of the form "America/Los Angeles".
1070 * @param rawOffset The desired GMT offset
1071 * @param index The index of the desired TimeZone.
1072 * @param status A pointer to an UErrorCode to receive any errors
1073 * @return The requested TimeZone ID, or 0 if not found
1074 * @see ucal_countAvailableTZIDs
1075 * @obsolete ICU 2.8. Use ucal_openTimeZoneEnumeration instead since this API will be removed in that release.
1077 U_OBSOLETE
const UChar
* U_EXPORT2
1078 ucal_getAvailableTZIDs(int32_t rawOffset
,
1080 UErrorCode
* status
);
1083 * Determine how many TimeZones exist with a certain offset.
1084 * This function is most useful as determining the loop ending condition for
1085 * calls to \ref ucal_getAvailableTZIDs.
1086 * @param rawOffset The desired GMT offset.
1087 * @return The number of TimeZones with rawOffset.
1088 * @see ucal_getAvailableTZIDs
1089 * @obsolete ICU 2.8. Use ucal_openTimeZoneEnumeration instead since this API will be removed in that release.
1091 U_OBSOLETE
int32_t U_EXPORT2
1092 ucal_countAvailableTZIDs(int32_t rawOffset
);
1095 /** Get the locale for this calendar object. You can choose between valid and actual locale.
1096 * @param cal The calendar object
1097 * @param type type of the locale we're looking for (valid or actual)
1098 * @param status error code for the operation
1099 * @return the locale name
1102 U_STABLE
const char * U_EXPORT2
1103 ucal_getLocaleByType(const UCalendar
*cal
, ULocDataLocaleType type
, UErrorCode
* status
);
1105 #endif /* #if !UCONFIG_NO_FORMATTING */