1 /* 2 ******************************************************************************* 3 * Copyright (C) 1996-2007, International Business Machines Corporation and 4 * others. All Rights Reserved. 5 ******************************************************************************* 6 */ 7 8 #ifndef UCAL_H 9 #define UCAL_H 10 11 #include "unicode/utypes.h" 12 #include "unicode/uenum.h" 13 #include "unicode/uloc.h" 14 15 #if !UCONFIG_NO_FORMATTING 16 17 /** 18 * \file 19 * \brief C API: Calendar 20 * 21 * <h2>Calendar C API</h2> 22 * 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> .) 29 * 30 * <p> 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 34 * UCAL_GREGORIAN. 35 * <p> 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 42 * <pre> 43 * \code 44 * UCalendar *caldef; 45 * UChar *tzId; 46 * UErrorCode status; 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); 50 * \endcode 51 * </pre> 52 * \htmlonly</blockquote>\endhtmlonly 53 * 54 * <p> 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). 58 * 59 * <p> 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). 65 * 66 * <p> 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. 71 * 72 * <p> 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. 78 * 79 * \htmlonly<blockquote>\endhtmlonly 80 * <pre> 81 * \code 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 85 * UCAL_DAY_OF_YEAR 86 * UCAL_DAY_OF_WEEK + UCAL_WEEK_OF_YEAR 87 * \endcode 88 * </pre> 89 * \htmlonly</blockquote>\endhtmlonly 90 * 91 * For the time of day: 92 * 93 * \htmlonly<blockquote>\endhtmlonly 94 * <pre> 95 * \code 96 * UCAL_HOUR_OF_DAY 97 * UCAL_AM_PM + UCAL_HOUR 98 * \endcode 99 * </pre> 100 * \htmlonly</blockquote>\endhtmlonly 101 * 102 * <p> 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. 107 * 108 * <p> 109 * <strong>Note:</strong> There are certain possible ambiguities in 110 * interpretation of certain singular times, which are resolved in the 111 * following ways: 112 * <ol> 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 115 * 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 119 * </ol> 120 * 121 * <p> 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} 125 * to format dates. 126 * 127 * <p> 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>. 132 * 133 * <p> 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>. 138 * 139 * @stable ICU 2.0 140 */ 141 142 /** A calendar. 143 * For usage in C programs. 144 * @stable ICU 2.0 145 */ 146 typedef void* UCalendar; 147 148 /** Possible types of UCalendars 149 * @stable ICU 2.0 150 */ 151 enum UCalendarType { 152 /** A traditional calendar for the locale */ 153 UCAL_TRADITIONAL, 154 /** The Gregorian calendar */ 155 UCAL_GREGORIAN 156 }; 157 158 /** @stable ICU 2.0 */ 159 typedef enum UCalendarType UCalendarType; 160 161 /** Possible fields in a UCalendar 162 * @stable ICU 2.0 163 */ 164 enum UCalendarDateFields { 165 /** 166 * Field number indicating the era, e.g., AD or BC in the Gregorian (Julian) calendar. 167 * This is a calendar-specific value. 168 * @stable ICU 2.6 169 */ 170 UCAL_ERA, 171 172 /** 173 * Field number indicating the year. This is a calendar-specific value. 174 * @stable ICU 2.6 175 */ 176 UCAL_YEAR, 177 178 /** 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. 182 * @see #UCAL_JANUARY 183 * @see #UCAL_FEBRUARY 184 * @see #UCAL_MARCH 185 * @see #UCAL_APRIL 186 * @see #UCAL_MAY 187 * @see #UCAL_JUNE 188 * @see #UCAL_JULY 189 * @see #UCAL_AUGUST 190 * @see #UCAL_SEPTEMBER 191 * @see #UCAL_OCTOBER 192 * @see #UCAL_NOVEMBER 193 * @see #UCAL_DECEMBER 194 * @see #UCAL_UNDECIMBER 195 * @stable ICU 2.6 196 */ 197 UCAL_MONTH, 198 199 /** 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 205 * the year. 206 * @see ucal_getAttribute 207 * @see ucal_setAttribute 208 * @stable ICU 2.6 209 */ 210 UCAL_WEEK_OF_YEAR, 211 212 /** 213 * Field number indicating the 214 * week number within the current month. The first week of the month, as 215 * defined by <code>UCAL_FIRST_DAY_OF_WEEK</code> and <code>UCAL_MINIMAL_DAYS_IN_FIRST_WEEK</code> 216 * attributes, has value 1. Subclasses define 217 * the value of <code>WEEK_OF_MONTH</code> for days before the first week of 218 * the month. 219 * @see ucal_getAttribute 220 * @see ucal_setAttribute 221 * @see #UCAL_FIRST_DAY_OF_WEEK 222 * @see #UCAL_MINIMAL_DAYS_IN_FIRST_WEEK 223 * @stable ICU 2.6 224 */ 225 UCAL_WEEK_OF_MONTH, 226 227 /** 228 * Field number indicating the 229 * day of the month. This is a synonym for <code>DAY_OF_MONTH</code>. 230 * The first day of the month has value 1. 231 * @see #UCAL_DAY_OF_MONTH 232 * @stable ICU 2.6 233 */ 234 UCAL_DATE, 235 236 /** 237 * Field number indicating the day 238 * number within the current year. The first day of the year has value 1. 239 * @stable ICU 2.6 240 */ 241 UCAL_DAY_OF_YEAR, 242 243 /** 244 * Field number indicating the day 245 * of the week. This field takes values <code>SUNDAY</code>, 246 * <code>MONDAY</code>, <code>TUESDAY</code>, <code>WEDNESDAY</code>, 247 * <code>THURSDAY</code>, <code>FRIDAY</code>, and <code>SATURDAY</code>. 248 * @see #UCAL_SUNDAY 249 * @see #UCAL_MONDAY 250 * @see #UCAL_TUESDAY 251 * @see #UCAL_WEDNESDAY 252 * @see #UCAL_THURSDAY 253 * @see #UCAL_FRIDAY 254 * @see #UCAL_SATURDAY 255 * @stable ICU 2.6 256 */ 257 UCAL_DAY_OF_WEEK, 258 259 /** 260 * Field number indicating the 261 * ordinal number of the day of the week within the current month. Together 262 * with the <code>DAY_OF_WEEK</code> field, this uniquely specifies a day 263 * within a month. Unlike <code>WEEK_OF_MONTH</code> and 264 * <code>WEEK_OF_YEAR</code>, this field's value does <em>not</em> depend on 265 * <code>getFirstDayOfWeek()</code> or 266 * <code>getMinimalDaysInFirstWeek()</code>. <code>DAY_OF_MONTH 1</code> 267 * through <code>7</code> always correspond to <code>DAY_OF_WEEK_IN_MONTH 268 * 1</code>; <code>8</code> through <code>15</code> correspond to 269 * <code>DAY_OF_WEEK_IN_MONTH 2</code>, and so on. 270 * <code>DAY_OF_WEEK_IN_MONTH 0</code> indicates the week before 271 * <code>DAY_OF_WEEK_IN_MONTH 1</code>. Negative values count back from the 272 * end of the month, so the last Sunday of a month is specified as 273 * <code>DAY_OF_WEEK = SUNDAY, DAY_OF_WEEK_IN_MONTH = -1</code>. Because 274 * negative values count backward they will usually be aligned differently 275 * within the month than positive values. For example, if a month has 31 276 * days, <code>DAY_OF_WEEK_IN_MONTH -1</code> will overlap 277 * <code>DAY_OF_WEEK_IN_MONTH 5</code> and the end of <code>4</code>. 278 * @see #UCAL_DAY_OF_WEEK 279 * @see #UCAL_WEEK_OF_MONTH 280 * @stable ICU 2.6 281 */ 282 UCAL_DAY_OF_WEEK_IN_MONTH, 283 284 /** 285 * Field number indicating 286 * whether the <code>HOUR</code> is before or after noon. 287 * E.g., at 10:04:15.250 PM the <code>AM_PM</code> is <code>PM</code>. 288 * @see #UCAL_AM 289 * @see #UCAL_PM 290 * @see #UCAL_HOUR 291 * @stable ICU 2.6 292 */ 293 UCAL_AM_PM, 294 295 /** 296 * Field number indicating the 297 * hour of the morning or afternoon. <code>HOUR</code> is used for the 12-hour 298 * clock. 299 * E.g., at 10:04:15.250 PM the <code>HOUR</code> is 10. 300 * @see #UCAL_AM_PM 301 * @see #UCAL_HOUR_OF_DAY 302 * @stable ICU 2.6 303 */ 304 UCAL_HOUR, 305 306 /** 307 * Field number indicating the 308 * hour of the day. <code>HOUR_OF_DAY</code> is used for the 24-hour clock. 309 * E.g., at 10:04:15.250 PM the <code>HOUR_OF_DAY</code> is 22. 310 * @see #UCAL_HOUR 311 * @stable ICU 2.6 312 */ 313 UCAL_HOUR_OF_DAY, 314 315 /** 316 * Field number indicating the 317 * minute within the hour. 318 * E.g., at 10:04:15.250 PM the <code>UCAL_MINUTE</code> is 4. 319 * @stable ICU 2.6 320 */ 321 UCAL_MINUTE, 322 323 /** 324 * Field number indicating the 325 * second within the minute. 326 * E.g., at 10:04:15.250 PM the <code>UCAL_SECOND</code> is 15. 327 * @stable ICU 2.6 328 */ 329 UCAL_SECOND, 330 331 /** 332 * Field number indicating the 333 * millisecond within the second. 334 * E.g., at 10:04:15.250 PM the <code>UCAL_MILLISECOND</code> is 250. 335 * @stable ICU 2.6 336 */ 337 UCAL_MILLISECOND, 338 339 /** 340 * Field number indicating the 341 * raw offset from GMT in milliseconds. 342 * @stable ICU 2.6 343 */ 344 UCAL_ZONE_OFFSET, 345 346 /** 347 * Field number indicating the 348 * daylight savings offset in milliseconds. 349 * @stable ICU 2.6 350 */ 351 UCAL_DST_OFFSET, 352 353 /** 354 * Field number 355 * indicating the extended year corresponding to the 356 * <code>UCAL_WEEK_OF_YEAR</code> field. This may be one greater or less 357 * than the value of <code>UCAL_EXTENDED_YEAR</code>. 358 * @stable ICU 2.6 359 */ 360 UCAL_YEAR_WOY, 361 362 /** 363 * Field number 364 * indicating the localized day of week. This will be a value from 1 365 * to 7 inclusive, with 1 being the localized first day of the week. 366 * @stable ICU 2.6 367 */ 368 UCAL_DOW_LOCAL, 369 370 /** 371 * Year of this calendar system, encompassing all supra-year fields. For example, 372 * in Gregorian/Julian calendars, positive Extended Year values indicate years AD, 373 * 1 BC = 0 extended, 2 BC = -1 extended, and so on. 374 * @stable ICU 2.8 375 */ 376 UCAL_EXTENDED_YEAR, 377 378 /** 379 * Field number 380 * indicating the modified Julian day number. This is different from 381 * the conventional Julian day number in two regards. First, it 382 * demarcates days at local zone midnight, rather than noon GMT. 383 * Second, it is a local number; that is, it depends on the local time 384 * zone. It can be thought of as a single number that encompasses all 385 * the date-related fields. 386 * @stable ICU 2.8 387 */ 388 UCAL_JULIAN_DAY, 389 390 /** 391 * Ranges from 0 to 23:59:59.999 (regardless of DST). This field behaves <em>exactly</em> 392 * like a composite of all time-related fields, not including the zone fields. As such, 393 * it also reflects discontinuities of those fields on DST transition days. On a day 394 * of DST onset, it will jump forward. On a day of DST cessation, it will jump 395 * backward. This reflects the fact that it must be combined with the DST_OFFSET field 396 * to obtain a unique local time value. 397 * @stable ICU 2.8 398 */ 399 UCAL_MILLISECONDS_IN_DAY, 400 401 /** 402 * Field count 403 * @stable ICU 2.6 404 */ 405 UCAL_FIELD_COUNT, 406 407 /** 408 * Field number indicating the 409 * day of the month. This is a synonym for <code>UCAL_DATE</code>. 410 * The first day of the month has value 1. 411 * @see #UCAL_DATE 412 * Synonym for UCAL_DATE 413 * @stable ICU 2.8 414 **/ 415 UCAL_DAY_OF_MONTH=UCAL_DATE 416 }; 417 418 /** @stable ICU 2.0 */ 419 typedef enum UCalendarDateFields UCalendarDateFields; 420 /** 421 * Useful constant for days of week. Note: Calendar day-of-week is 1-based. Clients 422 * who create locale resources for the field of first-day-of-week should be aware of 423 * this. For instance, in US locale, first-day-of-week is set to 1, i.e., UCAL_SUNDAY. 424 */ 425 /** Possible days of the week in a UCalendar 426 * @stable ICU 2.0 427 */ 428 enum UCalendarDaysOfWeek { 429 /** Sunday */ 430 UCAL_SUNDAY = 1, 431 /** Monday */ 432 UCAL_MONDAY, 433 /** Tuesday */ 434 UCAL_TUESDAY, 435 /** Wednesday */ 436 UCAL_WEDNESDAY, 437 /** Thursday */ 438 UCAL_THURSDAY, 439 /** Friday */ 440 UCAL_FRIDAY, 441 /** Saturday */ 442 UCAL_SATURDAY 443 }; 444 445 /** @stable ICU 2.0 */ 446 typedef enum UCalendarDaysOfWeek UCalendarDaysOfWeek; 447 448 /** Possible months in a UCalendar. Note: Calendar month is 0-based. 449 * @stable ICU 2.0 450 */ 451 enum UCalendarMonths { 452 /** January */ 453 UCAL_JANUARY, 454 /** February */ 455 UCAL_FEBRUARY, 456 /** March */ 457 UCAL_MARCH, 458 /** April */ 459 UCAL_APRIL, 460 /** May */ 461 UCAL_MAY, 462 /** June */ 463 UCAL_JUNE, 464 /** July */ 465 UCAL_JULY, 466 /** August */ 467 UCAL_AUGUST, 468 /** September */ 469 UCAL_SEPTEMBER, 470 /** October */ 471 UCAL_OCTOBER, 472 /** November */ 473 UCAL_NOVEMBER, 474 /** December */ 475 UCAL_DECEMBER, 476 /** Value of the <code>UCAL_MONTH</code> field indicating the 477 * thirteenth month of the year. Although the Gregorian calendar 478 * does not use this value, lunar calendars do. 479 */ 480 UCAL_UNDECIMBER 481 }; 482 483 /** @stable ICU 2.0 */ 484 typedef enum UCalendarMonths UCalendarMonths; 485 486 /** Possible AM/PM values in a UCalendar 487 * @stable ICU 2.0 488 */ 489 enum UCalendarAMPMs { 490 /** AM */ 491 UCAL_AM, 492 /** PM */ 493 UCAL_PM 494 }; 495 496 /** @stable ICU 2.0 */ 497 typedef enum UCalendarAMPMs UCalendarAMPMs; 498 499 /** 500 * Create an enumeration over all time zones. 501 * 502 * @param ec input/output error code 503 * 504 * @return an enumeration object that the caller must dispose of using 505 * uenum_close(), or NULL upon failure. In case of failure *ec will 506 * indicate the error. 507 * 508 * @stable ICU 2.6 509 */ 510 U_STABLE UEnumeration* U_EXPORT2 511 ucal_openTimeZones(UErrorCode* ec); 512 513 /** 514 * Create an enumeration over all time zones associated with the given 515 * country. Some zones are affiliated with no country (e.g., "UTC"); 516 * these may also be retrieved, as a group. 517 * 518 * @param country the ISO 3166 two-letter country code, or NULL to 519 * retrieve zones not affiliated with any country 520 * 521 * @param ec input/output error code 522 * 523 * @return an enumeration object that the caller must dispose of using 524 * uenum_close(), or NULL upon failure. In case of failure *ec will 525 * indicate the error. 526 * 527 * @stable ICU 2.6 528 */ 529 U_STABLE UEnumeration* U_EXPORT2 530 ucal_openCountryTimeZones(const char* country, UErrorCode* ec); 531 532 /** 533 * Return the default time zone. The default is determined initially 534 * by querying the host operating system. It may be changed with 535 * ucal_setDefaultTimeZone() or with the C++ TimeZone API. 536 * 537 * @param result A buffer to receive the result, or NULL 538 * 539 * @param resultCapacity The capacity of the result buffer 540 * 541 * @param ec input/output error code 542 * 543 * @return The result string length, not including the terminating 544 * null 545 * 546 * @stable ICU 2.6 547 */ 548 U_STABLE int32_t U_EXPORT2 549 ucal_getDefaultTimeZone(UChar* result, int32_t resultCapacity, UErrorCode* ec); 550 551 /** 552 * Set the default time zone. 553 * 554 * @param zoneID null-terminated time zone ID 555 * 556 * @param ec input/output error code 557 * 558 * @stable ICU 2.6 559 */ 560 U_STABLE void U_EXPORT2 561 ucal_setDefaultTimeZone(const UChar* zoneID, UErrorCode* ec); 562 563 /** 564 * Return the amount of time in milliseconds that the clock is 565 * advanced during daylight savings time for the given time zone, or 566 * zero if the time zone does not observe daylight savings time. 567 * 568 * @param zoneID null-terminated time zone ID 569 * 570 * @param ec input/output error code 571 * 572 * @return the number of milliseconds the time is advanced with 573 * respect to standard time when the daylight savings rules are in 574 * effect. This is always a non-negative number, most commonly either 575 * 3,600,000 (one hour) or zero. 576 * 577 * @stable ICU 2.6 578 */ 579 U_STABLE int32_t U_EXPORT2 580 ucal_getDSTSavings(const UChar* zoneID, UErrorCode* ec); 581 582 /** 583 * Get the current date and time. 584 * The value returned is represented as milliseconds from the epoch. 585 * @return The current date and time. 586 * @stable ICU 2.0 587 */ 588 U_STABLE UDate U_EXPORT2 589 ucal_getNow(void); 590 591 /** 592 * Open a UCalendar. 593 * A UCalendar may be used to convert a millisecond value to a year, 594 * month, and day. 595 * @param zoneID The desired TimeZone ID. If 0, use the default time zone. 596 * @param len The length of zoneID, or -1 if null-terminated. 597 * @param locale The desired locale 598 * @param type The type of UCalendar to open. 599 * @param status A pointer to an UErrorCode to receive any errors 600 * @return A pointer to a UCalendar, or 0 if an error occurred. 601 * @stable ICU 2.0 602 */ 603 U_STABLE UCalendar* U_EXPORT2 604 ucal_open(const UChar* zoneID, 605 int32_t len, 606 const char* locale, 607 UCalendarType type, 608 UErrorCode* status); 609 610 /** 611 * Close a UCalendar. 612 * Once closed, a UCalendar may no longer be used. 613 * @param cal The UCalendar to close. 614 * @stable ICU 2.0 615 */ 616 U_STABLE void U_EXPORT2 617 ucal_close(UCalendar *cal); 618 619 /** 620 * Set the TimeZone used by a UCalendar. 621 * A UCalendar uses a timezone for converting from Greenwich time to local time. 622 * @param cal The UCalendar to set. 623 * @param zoneID The desired TimeZone ID. If 0, use the default time zone. 624 * @param len The length of zoneID, or -1 if null-terminated. 625 * @param status A pointer to an UErrorCode to receive any errors. 626 * @stable ICU 2.0 627 */ 628 U_STABLE void U_EXPORT2 629 ucal_setTimeZone(UCalendar* cal, 630 const UChar* zoneID, 631 int32_t len, 632 UErrorCode* status); 633 634 /** 635 * Possible formats for a UCalendar's display name 636 * @stable ICU 2.0 637 */ 638 enum UCalendarDisplayNameType { 639 /** Standard display name */ 640 UCAL_STANDARD, 641 /** Short standard display name */ 642 UCAL_SHORT_STANDARD, 643 /** Daylight savings display name */ 644 UCAL_DST, 645 /** Short daylight savings display name */ 646 UCAL_SHORT_DST 647 }; 648 649 /** @stable ICU 2.0 */ 650 typedef enum UCalendarDisplayNameType UCalendarDisplayNameType; 651 652 /** 653 * Get the display name for a UCalendar's TimeZone. 654 * A display name is suitable for presentation to a user. 655 * @param cal The UCalendar to query. 656 * @param type The desired display name format; one of UCAL_STANDARD, UCAL_SHORT_STANDARD, 657 * UCAL_DST, UCAL_SHORT_DST 658 * @param locale The desired locale for the display name. 659 * @param result A pointer to a buffer to receive the formatted number. 660 * @param resultLength The maximum size of result. 661 * @param status A pointer to an UErrorCode to receive any errors 662 * @return The total buffer size needed; if greater than resultLength, the output was truncated. 663 * @stable ICU 2.0 664 */ 665 U_STABLE int32_t U_EXPORT2 666 ucal_getTimeZoneDisplayName(const UCalendar* cal, 667 UCalendarDisplayNameType type, 668 const char* locale, 669 UChar* result, 670 int32_t resultLength, 671 UErrorCode* status); 672 673 /** 674 * Determine if a UCalendar is currently in daylight savings time. 675 * Daylight savings time is not used in all parts of the world. 676 * @param cal The UCalendar to query. 677 * @param status A pointer to an UErrorCode to receive any errors 678 * @return TRUE if cal is currently in daylight savings time, FALSE otherwise 679 * @stable ICU 2.0 680 */ 681 U_STABLE UBool U_EXPORT2 682 ucal_inDaylightTime(const UCalendar* cal, 683 UErrorCode* status ); 684 685 /** 686 * Sets the GregorianCalendar change date. This is the point when the switch from 687 * Julian dates to Gregorian dates occurred. Default is 00:00:00 local time, October 688 * 15, 1582. Previous to this time and date will be Julian dates. 689 * 690 * This function works only for Gregorian calendars. If the UCalendar is not 691 * an instance of a Gregorian calendar, then a U_UNSUPPORTED_ERROR 692 * error code is set. 693 * 694 * @param cal The calendar object. 695 * @param date The given Gregorian cutover date. 696 * @param pErrorCode Pointer to a standard ICU error code. Its input value must 697 * pass the U_SUCCESS() test, or else the function returns 698 * immediately. Check for U_FAILURE() on output or use with 699 * function chaining. (See User Guide for details.) 700 * 701 * @see GregorianCalendar::setGregorianChange 702 * @see ucal_getGregorianChange 703 * @stable ICU 3.6 704 */ 705 U_STABLE void U_EXPORT2 706 ucal_setGregorianChange(UCalendar *cal, UDate date, UErrorCode *pErrorCode); 707 708 /** 709 * Gets the Gregorian Calendar change date. This is the point when the switch from 710 * Julian dates to Gregorian dates occurred. Default is 00:00:00 local time, October 711 * 15, 1582. Previous to this time and date will be Julian dates. 712 * 713 * This function works only for Gregorian calendars. If the UCalendar is not 714 * an instance of a Gregorian calendar, then a U_UNSUPPORTED_ERROR 715 * error code is set. 716 * 717 * @param cal The calendar object. 718 * @param pErrorCode Pointer to a standard ICU error code. Its input value must 719 * pass the U_SUCCESS() test, or else the function returns 720 * immediately. Check for U_FAILURE() on output or use with 721 * function chaining. (See User Guide for details.) 722 * @return The Gregorian cutover time for this calendar. 723 * 724 * @see GregorianCalendar::getGregorianChange 725 * @see ucal_setGregorianChange 726 * @stable ICU 3.6 727 */ 728 U_STABLE UDate U_EXPORT2 729 ucal_getGregorianChange(const UCalendar *cal, UErrorCode *pErrorCode); 730 731 /** 732 * Types of UCalendar attributes 733 * @stable ICU 2.0 734 */ 735 enum UCalendarAttribute { 736 /** Lenient parsing */ 737 UCAL_LENIENT, 738 /** First day of week */ 739 UCAL_FIRST_DAY_OF_WEEK, 740 /** Minimum number of days in first week */ 741 UCAL_MINIMAL_DAYS_IN_FIRST_WEEK 742 }; 743 744 /** @stable ICU 2.0 */ 745 typedef enum UCalendarAttribute UCalendarAttribute; 746 747 /** 748 * Get a numeric attribute associated with a UCalendar. 749 * Numeric attributes include the first day of the week, or the minimal numbers 750 * of days in the first week of the month. 751 * @param cal The UCalendar to query. 752 * @param attr The desired attribute; one of UCAL_LENIENT, UCAL_FIRST_DAY_OF_WEEK, 753 * or UCAL_MINIMAL_DAYS_IN_FIRST_WEEK 754 * @return The value of attr. 755 * @see ucal_setAttribute 756 * @stable ICU 2.0 757 */ 758 U_STABLE int32_t U_EXPORT2 759 ucal_getAttribute(const UCalendar* cal, 760 UCalendarAttribute attr); 761 762 /** 763 * Set a numeric attribute associated with a UCalendar. 764 * Numeric attributes include the first day of the week, or the minimal numbers 765 * of days in the first week of the month. 766 * @param cal The UCalendar to set. 767 * @param attr The desired attribute; one of UCAL_LENIENT, UCAL_FIRST_DAY_OF_WEEK, 768 * or UCAL_MINIMAL_DAYS_IN_FIRST_WEEK 769 * @param newValue The new value of attr. 770 * @see ucal_getAttribute 771 * @stable ICU 2.0 772 */ 773 U_STABLE void U_EXPORT2 774 ucal_setAttribute(UCalendar* cal, 775 UCalendarAttribute attr, 776 int32_t newValue); 777 778 /** 779 * Get a locale for which calendars are available. 780 * A UCalendar in a locale returned by this function will contain the correct 781 * day and month names for the locale. 782 * @param index The index of the desired locale. 783 * @return A locale for which calendars are available, or 0 if none. 784 * @see ucal_countAvailable 785 * @stable ICU 2.0 786 */ 787 U_STABLE const char* U_EXPORT2 788 ucal_getAvailable(int32_t index); 789 790 /** 791 * Determine how many locales have calendars available. 792 * This function is most useful as determining the loop ending condition for 793 * calls to \ref ucal_getAvailable. 794 * @return The number of locales for which calendars are available. 795 * @see ucal_getAvailable 796 * @stable ICU 2.0 797 */ 798 U_STABLE int32_t U_EXPORT2 799 ucal_countAvailable(void); 800 801 /** 802 * Get a UCalendar's current time in millis. 803 * The time is represented as milliseconds from the epoch. 804 * @param cal The UCalendar to query. 805 * @param status A pointer to an UErrorCode to receive any errors 806 * @return The calendar's current time in millis. 807 * @see ucal_setMillis 808 * @see ucal_setDate 809 * @see ucal_setDateTime 810 * @stable ICU 2.0 811 */ 812 U_STABLE UDate U_EXPORT2 813 ucal_getMillis(const UCalendar* cal, 814 UErrorCode* status); 815 816 /** 817 * Set a UCalendar's current time in millis. 818 * The time is represented as milliseconds from the epoch. 819 * @param cal The UCalendar to set. 820 * @param dateTime The desired date and time. 821 * @param status A pointer to an UErrorCode to receive any errors 822 * @see ucal_getMillis 823 * @see ucal_setDate 824 * @see ucal_setDateTime 825 * @stable ICU 2.0 826 */ 827 U_STABLE void U_EXPORT2 828 ucal_setMillis(UCalendar* cal, 829 UDate dateTime, 830 UErrorCode* status ); 831 832 /** 833 * Set a UCalendar's current date. 834 * The date is represented as a series of 32-bit integers. 835 * @param cal The UCalendar to set. 836 * @param year The desired year. 837 * @param month The desired month; one of UCAL_JANUARY, UCAL_FEBRUARY, UCAL_MARCH, UCAL_APRIL, UCAL_MAY, 838 * UCAL_JUNE, UCAL_JULY, UCAL_AUGUST, UCAL_SEPTEMBER, UCAL_OCTOBER, UCAL_NOVEMBER, UCAL_DECEMBER, UCAL_UNDECIMBER 839 * @param date The desired day of the month. 840 * @param status A pointer to an UErrorCode to receive any errors 841 * @see ucal_getMillis 842 * @see ucal_setMillis 843 * @see ucal_setDateTime 844 * @stable ICU 2.0 845 */ 846 U_STABLE void U_EXPORT2 847 ucal_setDate(UCalendar* cal, 848 int32_t year, 849 int32_t month, 850 int32_t date, 851 UErrorCode* status); 852 853 /** 854 * Set a UCalendar's current date. 855 * The date is represented as a series of 32-bit integers. 856 * @param cal The UCalendar to set. 857 * @param year The desired year. 858 * @param month The desired month; one of UCAL_JANUARY, UCAL_FEBRUARY, UCAL_MARCH, UCAL_APRIL, UCAL_MAY, 859 * UCAL_JUNE, UCAL_JULY, UCAL_AUGUST, UCAL_SEPTEMBER, UCAL_OCTOBER, UCAL_NOVEMBER, UCAL_DECEMBER, UCAL_UNDECIMBER 860 * @param date The desired day of the month. 861 * @param hour The desired hour of day. 862 * @param minute The desired minute. 863 * @param second The desirec second. 864 * @param status A pointer to an UErrorCode to receive any errors 865 * @see ucal_getMillis 866 * @see ucal_setMillis 867 * @see ucal_setDate 868 * @stable ICU 2.0 869 */ 870 U_STABLE void U_EXPORT2 871 ucal_setDateTime(UCalendar* cal, 872 int32_t year, 873 int32_t month, 874 int32_t date, 875 int32_t hour, 876 int32_t minute, 877 int32_t second, 878 UErrorCode* status); 879 880 /** 881 * Returns TRUE if two UCalendars are equivalent. Equivalent 882 * UCalendars will behave identically, but they may be set to 883 * different times. 884 * @param cal1 The first of the UCalendars to compare. 885 * @param cal2 The second of the UCalendars to compare. 886 * @return TRUE if cal1 and cal2 are equivalent, FALSE otherwise. 887 * @stable ICU 2.0 888 */ 889 U_STABLE UBool U_EXPORT2 890 ucal_equivalentTo(const UCalendar* cal1, 891 const UCalendar* cal2); 892 893 /** 894 * Add a specified signed amount to a particular field in a UCalendar. 895 * This can modify more significant fields in the calendar. 896 * @param cal The UCalendar to which to add. 897 * @param field The field to which to add the signed value; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH, 898 * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK, 899 * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND, 900 * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET. 901 * @param amount The signed amount to add to field. If the amount causes the value 902 * to exceed to maximum or minimum values for that field, other fields are modified 903 * to preserve the magnitude of the change. 904 * @param status A pointer to an UErrorCode to receive any errors 905 * @see ucal_roll 906 * @stable ICU 2.0 907 */ 908 U_STABLE void U_EXPORT2 909 ucal_add(UCalendar* cal, 910 UCalendarDateFields field, 911 int32_t amount, 912 UErrorCode* status); 913 914 /** 915 * Add a specified signed amount to a particular field in a UCalendar. 916 * This will not modify more significant fields in the calendar. 917 * @param cal The UCalendar to which to add. 918 * @param field The field to which to add the signed value; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH, 919 * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK, 920 * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND, 921 * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET. 922 * @param amount The signed amount to add to field. If the amount causes the value 923 * to exceed to maximum or minimum values for that field, the field is pinned to a permissible 924 * value. 925 * @param status A pointer to an UErrorCode to receive any errors 926 * @see ucal_add 927 * @stable ICU 2.0 928 */ 929 U_STABLE void U_EXPORT2 930 ucal_roll(UCalendar* cal, 931 UCalendarDateFields field, 932 int32_t amount, 933 UErrorCode* status); 934 935 /** 936 * Get the current value of a field from a UCalendar. 937 * All fields are represented as 32-bit integers. 938 * @param cal The UCalendar to query. 939 * @param field The desired field; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH, 940 * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK, 941 * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND, 942 * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET. 943 * @param status A pointer to an UErrorCode to receive any errors 944 * @return The value of the desired field. 945 * @see ucal_set 946 * @see ucal_isSet 947 * @see ucal_clearField 948 * @see ucal_clear 949 * @stable ICU 2.0 950 */ 951 U_STABLE int32_t U_EXPORT2 952 ucal_get(const UCalendar* cal, 953 UCalendarDateFields field, 954 UErrorCode* status ); 955 956 /** 957 * Set the value of a field in a UCalendar. 958 * All fields are represented as 32-bit integers. 959 * @param cal The UCalendar to set. 960 * @param field The field to set; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH, 961 * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK, 962 * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND, 963 * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET. 964 * @param value The desired value of field. 965 * @see ucal_get 966 * @see ucal_isSet 967 * @see ucal_clearField 968 * @see ucal_clear 969 * @stable ICU 2.0 970 */ 971 U_STABLE void U_EXPORT2 972 ucal_set(UCalendar* cal, 973 UCalendarDateFields field, 974 int32_t value); 975 976 /** 977 * Determine if a field in a UCalendar is set. 978 * All fields are represented as 32-bit integers. 979 * @param cal The UCalendar to query. 980 * @param field The desired field; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH, 981 * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK, 982 * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND, 983 * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET. 984 * @return TRUE if field is set, FALSE otherwise. 985 * @see ucal_get 986 * @see ucal_set 987 * @see ucal_clearField 988 * @see ucal_clear 989 * @stable ICU 2.0 990 */ 991 U_STABLE UBool U_EXPORT2 992 ucal_isSet(const UCalendar* cal, 993 UCalendarDateFields field); 994 995 /** 996 * Clear a field in a UCalendar. 997 * All fields are represented as 32-bit integers. 998 * @param cal The UCalendar containing the field to clear. 999 * @param field The field to clear; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH, 1000 * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK, 1001 * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND, 1002 * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET. 1003 * @see ucal_get 1004 * @see ucal_set 1005 * @see ucal_isSet 1006 * @see ucal_clear 1007 * @stable ICU 2.0 1008 */ 1009 U_STABLE void U_EXPORT2 1010 ucal_clearField(UCalendar* cal, 1011 UCalendarDateFields field); 1012 1013 /** 1014 * Clear all fields in a UCalendar. 1015 * All fields are represented as 32-bit integers. 1016 * @param calendar The UCalendar to clear. 1017 * @see ucal_get 1018 * @see ucal_set 1019 * @see ucal_isSet 1020 * @see ucal_clearField 1021 * @stable ICU 2.0 1022 */ 1023 U_STABLE void U_EXPORT2 1024 ucal_clear(UCalendar* calendar); 1025 1026 /** 1027 * Possible limit values for a UCalendar 1028 * @stable ICU 2.0 1029 */ 1030 enum UCalendarLimitType { 1031 /** Minimum value */ 1032 UCAL_MINIMUM, 1033 /** Maximum value */ 1034 UCAL_MAXIMUM, 1035 /** Greatest minimum value */ 1036 UCAL_GREATEST_MINIMUM, 1037 /** Leaest maximum value */ 1038 UCAL_LEAST_MAXIMUM, 1039 /** Actual minimum value */ 1040 UCAL_ACTUAL_MINIMUM, 1041 /** Actual maximum value */ 1042 UCAL_ACTUAL_MAXIMUM 1043 }; 1044 1045 /** @stable ICU 2.0 */ 1046 typedef enum UCalendarLimitType UCalendarLimitType; 1047 1048 /** 1049 * Determine a limit for a field in a UCalendar. 1050 * A limit is a maximum or minimum value for a field. 1051 * @param cal The UCalendar to query. 1052 * @param field The desired field; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH, 1053 * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK, 1054 * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND, 1055 * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET. 1056 * @param type The desired critical point; one of UCAL_MINIMUM, UCAL_MAXIMUM, UCAL_GREATEST_MINIMUM, 1057 * UCAL_LEAST_MAXIMUM, UCAL_ACTUAL_MINIMUM, UCAL_ACTUAL_MAXIMUM 1058 * @param status A pointer to an UErrorCode to receive any errors. 1059 * @return The requested value. 1060 * @stable ICU 2.0 1061 */ 1062 U_STABLE int32_t U_EXPORT2 1063 ucal_getLimit(const UCalendar* cal, 1064 UCalendarDateFields field, 1065 UCalendarLimitType type, 1066 UErrorCode* status); 1067 1068 /** Get the locale for this calendar object. You can choose between valid and actual locale. 1069 * @param cal The calendar object 1070 * @param type type of the locale we're looking for (valid or actual) 1071 * @param status error code for the operation 1072 * @return the locale name 1073 * @stable ICU 2.8 1074 */ 1075 U_STABLE const char * U_EXPORT2 1076 ucal_getLocaleByType(const UCalendar *cal, ULocDataLocaleType type, UErrorCode* status); 1077 1078 /** 1079 * Returns the timezone data version currently used by ICU. 1080 * @param status error code for the operation 1081 * @return the version string, such as "2007f" 1082 * @draft ICU 3.8 1083 */ 1084 U_DRAFT const char * U_EXPORT2 1085 ucal_getTZDataVersion(UErrorCode* status); 1086 1087 #endif /* #if !UCONFIG_NO_FORMATTING */ 1088 1089 #endif 1090