1 /* 2 ******************************************************************************* 3 * Copyright (C) 1996-2015, International Business Machines 4 * Corporation and others. All Rights Reserved. 5 ******************************************************************************* 6 */ 7 8 #ifndef UDAT_H 9 #define UDAT_H 10 11 #include "unicode/utypes.h" 12 13 #if !UCONFIG_NO_FORMATTING 14 15 #include "unicode/localpointer.h" 16 #include "unicode/ucal.h" 17 #include "unicode/unum.h" 18 #include "unicode/udisplaycontext.h" 19 #include "unicode/ufieldpositer.h" 20 /** 21 * \file 22 * \brief C API: DateFormat 23 * 24 * <h2> Date Format C API</h2> 25 * 26 * Date Format C API consists of functions that convert dates and 27 * times from their internal representations to textual form and back again in a 28 * language-independent manner. Converting from the internal representation (milliseconds 29 * since midnight, January 1, 1970) to text is known as "formatting," and converting 30 * from text to millis is known as "parsing." We currently define only one concrete 31 * structure UDateFormat, which can handle pretty much all normal 32 * date formatting and parsing actions. 33 * <P> 34 * Date Format helps you to format and parse dates for any locale. Your code can 35 * be completely independent of the locale conventions for months, days of the 36 * week, or even the calendar format: lunar vs. solar. 37 * <P> 38 * To format a date for the current Locale with default time and date style, 39 * use one of the static factory methods: 40 * <pre> 41 * \code 42 * UErrorCode status = U_ZERO_ERROR; 43 * UChar *myString; 44 * int32_t myStrlen = 0; 45 * UDateFormat* dfmt = udat_open(UDAT_DEFAULT, UDAT_DEFAULT, NULL, NULL, -1, NULL, -1, &status); 46 * myStrlen = udat_format(dfmt, myDate, NULL, myStrlen, NULL, &status); 47 * if (status==U_BUFFER_OVERFLOW_ERROR){ 48 * status=U_ZERO_ERROR; 49 * myString=(UChar*)malloc(sizeof(UChar) * (myStrlen+1) ); 50 * udat_format(dfmt, myDate, myString, myStrlen+1, NULL, &status); 51 * } 52 * \endcode 53 * </pre> 54 * If you are formatting multiple numbers, it is more efficient to get the 55 * format and use it multiple times so that the system doesn't have to fetch the 56 * information about the local language and country conventions multiple times. 57 * <pre> 58 * \code 59 * UErrorCode status = U_ZERO_ERROR; 60 * int32_t i, myStrlen = 0; 61 * UChar* myString; 62 * char buffer[1024]; 63 * UDate myDateArr[] = { 0.0, 100000000.0, 2000000000.0 }; // test values 64 * UDateFormat* df = udat_open(UDAT_DEFAULT, UDAT_DEFAULT, NULL, NULL, -1, NULL, 0, &status); 65 * for (i = 0; i < 3; i++) { 66 * myStrlen = udat_format(df, myDateArr[i], NULL, myStrlen, NULL, &status); 67 * if(status == U_BUFFER_OVERFLOW_ERROR){ 68 * status = U_ZERO_ERROR; 69 * myString = (UChar*)malloc(sizeof(UChar) * (myStrlen+1) ); 70 * udat_format(df, myDateArr[i], myString, myStrlen+1, NULL, &status); 71 * printf("%s\n", u_austrcpy(buffer, myString) ); 72 * free(myString); 73 * } 74 * } 75 * \endcode 76 * </pre> 77 * To get specific fields of a date, you can use UFieldPosition to 78 * get specific fields. 79 * <pre> 80 * \code 81 * UErrorCode status = U_ZERO_ERROR; 82 * UFieldPosition pos; 83 * UChar *myString; 84 * int32_t myStrlen = 0; 85 * char buffer[1024]; 86 * 87 * pos.field = 1; // Same as the DateFormat::EField enum 88 * UDateFormat* dfmt = udat_open(UDAT_DEFAULT, UDAT_DEFAULT, NULL, -1, NULL, 0, &status); 89 * myStrlen = udat_format(dfmt, myDate, NULL, myStrlen, &pos, &status); 90 * if (status==U_BUFFER_OVERFLOW_ERROR){ 91 * status=U_ZERO_ERROR; 92 * myString=(UChar*)malloc(sizeof(UChar) * (myStrlen+1) ); 93 * udat_format(dfmt, myDate, myString, myStrlen+1, &pos, &status); 94 * } 95 * printf("date format: %s\n", u_austrcpy(buffer, myString)); 96 * buffer[pos.endIndex] = 0; // NULL terminate the string. 97 * printf("UFieldPosition position equals %s\n", &buffer[pos.beginIndex]); 98 * \endcode 99 * </pre> 100 * To format a date for a different Locale, specify it in the call to 101 * udat_open() 102 * <pre> 103 * \code 104 * UDateFormat* df = udat_open(UDAT_SHORT, UDAT_SHORT, "fr_FR", NULL, -1, NULL, 0, &status); 105 * \endcode 106 * </pre> 107 * You can use a DateFormat API udat_parse() to parse. 108 * <pre> 109 * \code 110 * UErrorCode status = U_ZERO_ERROR; 111 * int32_t parsepos=0; 112 * UDate myDate = udat_parse(df, myString, u_strlen(myString), &parsepos, &status); 113 * \endcode 114 * </pre> 115 * You can pass in different options for the arguments for date and time style 116 * to control the length of the result; from SHORT to MEDIUM to LONG to FULL. 117 * The exact result depends on the locale, but generally: 118 * see UDateFormatStyle for more details 119 * <ul type=round> 120 * <li> UDAT_SHORT is completely numeric, such as 12/13/52 or 3:30pm 121 * <li> UDAT_MEDIUM is longer, such as Jan 12, 1952 122 * <li> UDAT_LONG is longer, such as January 12, 1952 or 3:30:32pm 123 * <li> UDAT_FULL is pretty completely specified, such as 124 * Tuesday, April 12, 1952 AD or 3:30:42pm PST. 125 * </ul> 126 * You can also set the time zone on the format if you wish. 127 * <P> 128 * You can also use forms of the parse and format methods with Parse Position and 129 * UFieldPosition to allow you to 130 * <ul type=round> 131 * <li> Progressively parse through pieces of a string. 132 * <li> Align any particular field, or find out where it is for selection 133 * on the screen. 134 * </ul> 135 * <p><strong>Date and Time Patterns:</strong></p> 136 * 137 * <p>Date and time formats are specified by <em>date and time pattern</em> strings. 138 * Within date and time pattern strings, all unquoted ASCII letters [A-Za-z] are reserved 139 * as pattern letters representing calendar fields. <code>UDateFormat</code> supports 140 * the date and time formatting algorithm and pattern letters defined by 141 * <a href="http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table">UTS#35 142 * Unicode Locale Data Markup Language (LDML)</a> and further documented for ICU in the 143 * <a href="https://sites.google.com/site/icuprojectuserguide/formatparse/datetime?pli=1#TOC-Date-Field-Symbol-Table">ICU 144 * User Guide</a>.</p> 145 */ 146 147 /** A date formatter. 148 * For usage in C programs. 149 * @stable ICU 2.6 150 */ 151 typedef void* UDateFormat; 152 153 /** The possible date/time format styles 154 * @stable ICU 2.6 155 */ 156 typedef enum UDateFormatStyle { 157 /** Full style */ 158 UDAT_FULL, 159 /** Long style */ 160 UDAT_LONG, 161 /** Medium style */ 162 UDAT_MEDIUM, 163 /** Short style */ 164 UDAT_SHORT, 165 /** Default style */ 166 UDAT_DEFAULT = UDAT_MEDIUM, 167 168 /** Bitfield for relative date */ 169 UDAT_RELATIVE = (1 << 7), 170 171 UDAT_FULL_RELATIVE = UDAT_FULL | UDAT_RELATIVE, 172 173 UDAT_LONG_RELATIVE = UDAT_LONG | UDAT_RELATIVE, 174 175 UDAT_MEDIUM_RELATIVE = UDAT_MEDIUM | UDAT_RELATIVE, 176 177 UDAT_SHORT_RELATIVE = UDAT_SHORT | UDAT_RELATIVE, 178 179 180 /** No style */ 181 UDAT_NONE = -1, 182 183 /** 184 * Use the pattern given in the parameter to udat_open 185 * @see udat_open 186 * @stable ICU 50 187 */ 188 UDAT_PATTERN = -2, 189 190 #ifndef U_HIDE_INTERNAL_API 191 /** @internal alias to UDAT_PATTERN */ 192 UDAT_IGNORE = UDAT_PATTERN 193 #endif /* U_HIDE_INTERNAL_API */ 194 } UDateFormatStyle; 195 196 /* Skeletons for dates. */ 197 198 /** 199 * Constant for date skeleton with year. 200 * @stable ICU 4.0 201 */ 202 #define UDAT_YEAR "y" 203 /** 204 * Constant for date skeleton with quarter. 205 * @stable ICU 51 206 */ 207 #define UDAT_QUARTER "QQQQ" 208 /** 209 * Constant for date skeleton with abbreviated quarter. 210 * @stable ICU 51 211 */ 212 #define UDAT_ABBR_QUARTER "QQQ" 213 /** 214 * Constant for date skeleton with year and quarter. 215 * @stable ICU 4.0 216 */ 217 #define UDAT_YEAR_QUARTER "yQQQQ" 218 /** 219 * Constant for date skeleton with year and abbreviated quarter. 220 * @stable ICU 4.0 221 */ 222 #define UDAT_YEAR_ABBR_QUARTER "yQQQ" 223 /** 224 * Constant for date skeleton with month. 225 * @stable ICU 4.0 226 */ 227 #define UDAT_MONTH "MMMM" 228 /** 229 * Constant for date skeleton with abbreviated month. 230 * @stable ICU 4.0 231 */ 232 #define UDAT_ABBR_MONTH "MMM" 233 /** 234 * Constant for date skeleton with numeric month. 235 * @stable ICU 4.0 236 */ 237 #define UDAT_NUM_MONTH "M" 238 /** 239 * Constant for date skeleton with year and month. 240 * @stable ICU 4.0 241 */ 242 #define UDAT_YEAR_MONTH "yMMMM" 243 /** 244 * Constant for date skeleton with year and abbreviated month. 245 * @stable ICU 4.0 246 */ 247 #define UDAT_YEAR_ABBR_MONTH "yMMM" 248 /** 249 * Constant for date skeleton with year and numeric month. 250 * @stable ICU 4.0 251 */ 252 #define UDAT_YEAR_NUM_MONTH "yM" 253 /** 254 * Constant for date skeleton with day. 255 * @stable ICU 4.0 256 */ 257 #define UDAT_DAY "d" 258 /** 259 * Constant for date skeleton with year, month, and day. 260 * Used in combinations date + time, date + time + zone, or time + zone. 261 * @stable ICU 4.0 262 */ 263 #define UDAT_YEAR_MONTH_DAY "yMMMMd" 264 /** 265 * Constant for date skeleton with year, abbreviated month, and day. 266 * Used in combinations date + time, date + time + zone, or time + zone. 267 * @stable ICU 4.0 268 */ 269 #define UDAT_YEAR_ABBR_MONTH_DAY "yMMMd" 270 /** 271 * Constant for date skeleton with year, numeric month, and day. 272 * Used in combinations date + time, date + time + zone, or time + zone. 273 * @stable ICU 4.0 274 */ 275 #define UDAT_YEAR_NUM_MONTH_DAY "yMd" 276 /** 277 * Constant for date skeleton with weekday. 278 * @stable ICU 51 279 */ 280 #define UDAT_WEEKDAY "EEEE" 281 /** 282 * Constant for date skeleton with abbreviated weekday. 283 * @stable ICU 51 284 */ 285 #define UDAT_ABBR_WEEKDAY "E" 286 /** 287 * Constant for date skeleton with year, month, weekday, and day. 288 * Used in combinations date + time, date + time + zone, or time + zone. 289 * @stable ICU 4.0 290 */ 291 #define UDAT_YEAR_MONTH_WEEKDAY_DAY "yMMMMEEEEd" 292 /** 293 * Constant for date skeleton with year, abbreviated month, weekday, and day. 294 * Used in combinations date + time, date + time + zone, or time + zone. 295 * @stable ICU 4.0 296 */ 297 #define UDAT_YEAR_ABBR_MONTH_WEEKDAY_DAY "yMMMEd" 298 /** 299 * Constant for date skeleton with year, numeric month, weekday, and day. 300 * Used in combinations date + time, date + time + zone, or time + zone. 301 * @stable ICU 4.0 302 */ 303 #define UDAT_YEAR_NUM_MONTH_WEEKDAY_DAY "yMEd" 304 /** 305 * Constant for date skeleton with long month and day. 306 * Used in combinations date + time, date + time + zone, or time + zone. 307 * @stable ICU 4.0 308 */ 309 #define UDAT_MONTH_DAY "MMMMd" 310 /** 311 * Constant for date skeleton with abbreviated month and day. 312 * Used in combinations date + time, date + time + zone, or time + zone. 313 * @stable ICU 4.0 314 */ 315 #define UDAT_ABBR_MONTH_DAY "MMMd" 316 /** 317 * Constant for date skeleton with numeric month and day. 318 * Used in combinations date + time, date + time + zone, or time + zone. 319 * @stable ICU 4.0 320 */ 321 #define UDAT_NUM_MONTH_DAY "Md" 322 /** 323 * Constant for date skeleton with month, weekday, and day. 324 * Used in combinations date + time, date + time + zone, or time + zone. 325 * @stable ICU 4.0 326 */ 327 #define UDAT_MONTH_WEEKDAY_DAY "MMMMEEEEd" 328 /** 329 * Constant for date skeleton with abbreviated month, weekday, and day. 330 * Used in combinations date + time, date + time + zone, or time + zone. 331 * @stable ICU 4.0 332 */ 333 #define UDAT_ABBR_MONTH_WEEKDAY_DAY "MMMEd" 334 /** 335 * Constant for date skeleton with numeric month, weekday, and day. 336 * Used in combinations date + time, date + time + zone, or time + zone. 337 * @stable ICU 4.0 338 */ 339 #define UDAT_NUM_MONTH_WEEKDAY_DAY "MEd" 340 341 /* Skeletons for times. */ 342 343 /** 344 * Constant for date skeleton with hour, with the locale's preferred hour format (12 or 24). 345 * @stable ICU 4.0 346 */ 347 #define UDAT_HOUR "j" 348 /** 349 * Constant for date skeleton with hour in 24-hour presentation. 350 * @stable ICU 51 351 */ 352 #define UDAT_HOUR24 "H" 353 /** 354 * Constant for date skeleton with minute. 355 * @stable ICU 51 356 */ 357 #define UDAT_MINUTE "m" 358 /** 359 * Constant for date skeleton with hour and minute, with the locale's preferred hour format (12 or 24). 360 * Used in combinations date + time, date + time + zone, or time + zone. 361 * @stable ICU 4.0 362 */ 363 #define UDAT_HOUR_MINUTE "jm" 364 /** 365 * Constant for date skeleton with hour and minute in 24-hour presentation. 366 * Used in combinations date + time, date + time + zone, or time + zone. 367 * @stable ICU 4.0 368 */ 369 #define UDAT_HOUR24_MINUTE "Hm" 370 /** 371 * Constant for date skeleton with second. 372 * @stable ICU 51 373 */ 374 #define UDAT_SECOND "s" 375 /** 376 * Constant for date skeleton with hour, minute, and second, 377 * with the locale's preferred hour format (12 or 24). 378 * Used in combinations date + time, date + time + zone, or time + zone. 379 * @stable ICU 4.0 380 */ 381 #define UDAT_HOUR_MINUTE_SECOND "jms" 382 /** 383 * Constant for date skeleton with hour, minute, and second in 384 * 24-hour presentation. 385 * Used in combinations date + time, date + time + zone, or time + zone. 386 * @stable ICU 4.0 387 */ 388 #define UDAT_HOUR24_MINUTE_SECOND "Hms" 389 /** 390 * Constant for date skeleton with minute and second. 391 * Used in combinations date + time, date + time + zone, or time + zone. 392 * @stable ICU 4.0 393 */ 394 #define UDAT_MINUTE_SECOND "ms" 395 396 /* Skeletons for time zones. */ 397 398 /** 399 * Constant for <i>generic location format</i>, such as Los Angeles Time; 400 * used in combinations date + time + zone, or time + zone. 401 * @see <a href="http://unicode.org/reports/tr35/#Date_Format_Patterns">LDML Date Format Patterns</a> 402 * @see <a href="http://unicode.org/reports/tr35/#Time_Zone_Fallback">LDML Time Zone Fallback</a> 403 * @stable ICU 51 404 */ 405 #define UDAT_LOCATION_TZ "VVVV" 406 /** 407 * Constant for <i>generic non-location format</i>, such as Pacific Time; 408 * used in combinations date + time + zone, or time + zone. 409 * @see <a href="http://unicode.org/reports/tr35/#Date_Format_Patterns">LDML Date Format Patterns</a> 410 * @see <a href="http://unicode.org/reports/tr35/#Time_Zone_Fallback">LDML Time Zone Fallback</a> 411 * @stable ICU 51 412 */ 413 #define UDAT_GENERIC_TZ "vvvv" 414 /** 415 * Constant for <i>generic non-location format</i>, abbreviated if possible, such as PT; 416 * used in combinations date + time + zone, or time + zone. 417 * @see <a href="http://unicode.org/reports/tr35/#Date_Format_Patterns">LDML Date Format Patterns</a> 418 * @see <a href="http://unicode.org/reports/tr35/#Time_Zone_Fallback">LDML Time Zone Fallback</a> 419 * @stable ICU 51 420 */ 421 #define UDAT_ABBR_GENERIC_TZ "v" 422 /** 423 * Constant for <i>specific non-location format</i>, such as Pacific Daylight Time; 424 * used in combinations date + time + zone, or time + zone. 425 * @see <a href="http://unicode.org/reports/tr35/#Date_Format_Patterns">LDML Date Format Patterns</a> 426 * @see <a href="http://unicode.org/reports/tr35/#Time_Zone_Fallback">LDML Time Zone Fallback</a> 427 * @stable ICU 51 428 */ 429 #define UDAT_SPECIFIC_TZ "zzzz" 430 /** 431 * Constant for <i>specific non-location format</i>, abbreviated if possible, such as PDT; 432 * used in combinations date + time + zone, or time + zone. 433 * @see <a href="http://unicode.org/reports/tr35/#Date_Format_Patterns">LDML Date Format Patterns</a> 434 * @see <a href="http://unicode.org/reports/tr35/#Time_Zone_Fallback">LDML Time Zone Fallback</a> 435 * @stable ICU 51 436 */ 437 #define UDAT_ABBR_SPECIFIC_TZ "z" 438 /** 439 * Constant for <i>localized GMT/UTC format</i>, such as GMT+8:00 or HPG-8:00; 440 * used in combinations date + time + zone, or time + zone. 441 * @see <a href="http://unicode.org/reports/tr35/#Date_Format_Patterns">LDML Date Format Patterns</a> 442 * @see <a href="http://unicode.org/reports/tr35/#Time_Zone_Fallback">LDML Time Zone Fallback</a> 443 * @stable ICU 51 444 */ 445 #define UDAT_ABBR_UTC_TZ "ZZZZ" 446 447 /* deprecated skeleton constants */ 448 449 #ifndef U_HIDE_DEPRECATED_API 450 /** 451 * Constant for date skeleton with standalone month. 452 * @deprecated ICU 50 Use UDAT_MONTH instead. 453 */ 454 #define UDAT_STANDALONE_MONTH "LLLL" 455 /** 456 * Constant for date skeleton with standalone abbreviated month. 457 * @deprecated ICU 50 Use UDAT_ABBR_MONTH instead. 458 */ 459 #define UDAT_ABBR_STANDALONE_MONTH "LLL" 460 461 /** 462 * Constant for date skeleton with hour, minute, and generic timezone. 463 * @deprecated ICU 50 Use instead UDAT_HOUR_MINUTE UDAT_ABBR_GENERIC_TZ or some other timezone presentation. 464 */ 465 #define UDAT_HOUR_MINUTE_GENERIC_TZ "jmv" 466 /** 467 * Constant for date skeleton with hour, minute, and timezone. 468 * @deprecated ICU 50 Use instead UDAT_HOUR_MINUTE UDAT_ABBR_SPECIFIC_TZ or some other timezone presentation. 469 */ 470 #define UDAT_HOUR_MINUTE_TZ "jmz" 471 /** 472 * Constant for date skeleton with hour and generic timezone. 473 * @deprecated ICU 50 Use instead UDAT_HOUR UDAT_ABBR_GENERIC_TZ or some other timezone presentation. 474 */ 475 #define UDAT_HOUR_GENERIC_TZ "jv" 476 /** 477 * Constant for date skeleton with hour and timezone. 478 * @deprecated ICU 50 Use instead UDAT_HOUR UDAT_ABBR_SPECIFIC_TZ or some other timezone presentation. 479 */ 480 #define UDAT_HOUR_TZ "jz" 481 #endif /* U_HIDE_DEPRECATED_API */ 482 483 /** 484 * FieldPosition and UFieldPosition selectors for format fields 485 * defined by DateFormat and UDateFormat. 486 * @stable ICU 3.0 487 */ 488 typedef enum UDateFormatField { 489 /** 490 * FieldPosition and UFieldPosition selector for 'G' field alignment, 491 * corresponding to the UCAL_ERA field. 492 * @stable ICU 3.0 493 */ 494 UDAT_ERA_FIELD = 0, 495 496 /** 497 * FieldPosition and UFieldPosition selector for 'y' field alignment, 498 * corresponding to the UCAL_YEAR field. 499 * @stable ICU 3.0 500 */ 501 UDAT_YEAR_FIELD = 1, 502 503 /** 504 * FieldPosition and UFieldPosition selector for 'M' field alignment, 505 * corresponding to the UCAL_MONTH field. 506 * @stable ICU 3.0 507 */ 508 UDAT_MONTH_FIELD = 2, 509 510 /** 511 * FieldPosition and UFieldPosition selector for 'd' field alignment, 512 * corresponding to the UCAL_DATE field. 513 * @stable ICU 3.0 514 */ 515 UDAT_DATE_FIELD = 3, 516 517 /** 518 * FieldPosition and UFieldPosition selector for 'k' field alignment, 519 * corresponding to the UCAL_HOUR_OF_DAY field. 520 * UDAT_HOUR_OF_DAY1_FIELD is used for the one-based 24-hour clock. 521 * For example, 23:59 + 01:00 results in 24:59. 522 * @stable ICU 3.0 523 */ 524 UDAT_HOUR_OF_DAY1_FIELD = 4, 525 526 /** 527 * FieldPosition and UFieldPosition selector for 'H' field alignment, 528 * corresponding to the UCAL_HOUR_OF_DAY field. 529 * UDAT_HOUR_OF_DAY0_FIELD is used for the zero-based 24-hour clock. 530 * For example, 23:59 + 01:00 results in 00:59. 531 * @stable ICU 3.0 532 */ 533 UDAT_HOUR_OF_DAY0_FIELD = 5, 534 535 /** 536 * FieldPosition and UFieldPosition selector for 'm' field alignment, 537 * corresponding to the UCAL_MINUTE field. 538 * @stable ICU 3.0 539 */ 540 UDAT_MINUTE_FIELD = 6, 541 542 /** 543 * FieldPosition and UFieldPosition selector for 's' field alignment, 544 * corresponding to the UCAL_SECOND field. 545 * @stable ICU 3.0 546 */ 547 UDAT_SECOND_FIELD = 7, 548 549 /** 550 * FieldPosition and UFieldPosition selector for 'S' field alignment, 551 * corresponding to the UCAL_MILLISECOND field. 552 * 553 * Note: Time formats that use 'S' can display a maximum of three 554 * significant digits for fractional seconds, corresponding to millisecond 555 * resolution and a fractional seconds sub-pattern of SSS. If the 556 * sub-pattern is S or SS, the fractional seconds value will be truncated 557 * (not rounded) to the number of display places specified. If the 558 * fractional seconds sub-pattern is longer than SSS, the additional 559 * display places will be filled with zeros. 560 * @stable ICU 3.0 561 */ 562 UDAT_FRACTIONAL_SECOND_FIELD = 8, 563 564 /** 565 * FieldPosition and UFieldPosition selector for 'E' field alignment, 566 * corresponding to the UCAL_DAY_OF_WEEK field. 567 * @stable ICU 3.0 568 */ 569 UDAT_DAY_OF_WEEK_FIELD = 9, 570 571 /** 572 * FieldPosition and UFieldPosition selector for 'D' field alignment, 573 * corresponding to the UCAL_DAY_OF_YEAR field. 574 * @stable ICU 3.0 575 */ 576 UDAT_DAY_OF_YEAR_FIELD = 10, 577 578 /** 579 * FieldPosition and UFieldPosition selector for 'F' field alignment, 580 * corresponding to the UCAL_DAY_OF_WEEK_IN_MONTH field. 581 * @stable ICU 3.0 582 */ 583 UDAT_DAY_OF_WEEK_IN_MONTH_FIELD = 11, 584 585 /** 586 * FieldPosition and UFieldPosition selector for 'w' field alignment, 587 * corresponding to the UCAL_WEEK_OF_YEAR field. 588 * @stable ICU 3.0 589 */ 590 UDAT_WEEK_OF_YEAR_FIELD = 12, 591 592 /** 593 * FieldPosition and UFieldPosition selector for 'W' field alignment, 594 * corresponding to the UCAL_WEEK_OF_MONTH field. 595 * @stable ICU 3.0 596 */ 597 UDAT_WEEK_OF_MONTH_FIELD = 13, 598 599 /** 600 * FieldPosition and UFieldPosition selector for 'a' field alignment, 601 * corresponding to the UCAL_AM_PM field. 602 * @stable ICU 3.0 603 */ 604 UDAT_AM_PM_FIELD = 14, 605 606 /** 607 * FieldPosition and UFieldPosition selector for 'h' field alignment, 608 * corresponding to the UCAL_HOUR field. 609 * UDAT_HOUR1_FIELD is used for the one-based 12-hour clock. 610 * For example, 11:30 PM + 1 hour results in 12:30 AM. 611 * @stable ICU 3.0 612 */ 613 UDAT_HOUR1_FIELD = 15, 614 615 /** 616 * FieldPosition and UFieldPosition selector for 'K' field alignment, 617 * corresponding to the UCAL_HOUR field. 618 * UDAT_HOUR0_FIELD is used for the zero-based 12-hour clock. 619 * For example, 11:30 PM + 1 hour results in 00:30 AM. 620 * @stable ICU 3.0 621 */ 622 UDAT_HOUR0_FIELD = 16, 623 624 /** 625 * FieldPosition and UFieldPosition selector for 'z' field alignment, 626 * corresponding to the UCAL_ZONE_OFFSET and 627 * UCAL_DST_OFFSET fields. 628 * @stable ICU 3.0 629 */ 630 UDAT_TIMEZONE_FIELD = 17, 631 632 /** 633 * FieldPosition and UFieldPosition selector for 'Y' field alignment, 634 * corresponding to the UCAL_YEAR_WOY field. 635 * @stable ICU 3.0 636 */ 637 UDAT_YEAR_WOY_FIELD = 18, 638 639 /** 640 * FieldPosition and UFieldPosition selector for 'e' field alignment, 641 * corresponding to the UCAL_DOW_LOCAL field. 642 * @stable ICU 3.0 643 */ 644 UDAT_DOW_LOCAL_FIELD = 19, 645 646 /** 647 * FieldPosition and UFieldPosition selector for 'u' field alignment, 648 * corresponding to the UCAL_EXTENDED_YEAR field. 649 * @stable ICU 3.0 650 */ 651 UDAT_EXTENDED_YEAR_FIELD = 20, 652 653 /** 654 * FieldPosition and UFieldPosition selector for 'g' field alignment, 655 * corresponding to the UCAL_JULIAN_DAY field. 656 * @stable ICU 3.0 657 */ 658 UDAT_JULIAN_DAY_FIELD = 21, 659 660 /** 661 * FieldPosition and UFieldPosition selector for 'A' field alignment, 662 * corresponding to the UCAL_MILLISECONDS_IN_DAY field. 663 * @stable ICU 3.0 664 */ 665 UDAT_MILLISECONDS_IN_DAY_FIELD = 22, 666 667 /** 668 * FieldPosition and UFieldPosition selector for 'Z' field alignment, 669 * corresponding to the UCAL_ZONE_OFFSET and 670 * UCAL_DST_OFFSET fields. 671 * @stable ICU 3.0 672 */ 673 UDAT_TIMEZONE_RFC_FIELD = 23, 674 675 /** 676 * FieldPosition and UFieldPosition selector for 'v' field alignment, 677 * corresponding to the UCAL_ZONE_OFFSET field. 678 * @stable ICU 3.4 679 */ 680 UDAT_TIMEZONE_GENERIC_FIELD = 24, 681 /** 682 * FieldPosition selector for 'c' field alignment, 683 * corresponding to the {@link #UCAL_DOW_LOCAL} field. 684 * This displays the stand alone day name, if available. 685 * @stable ICU 3.4 686 */ 687 UDAT_STANDALONE_DAY_FIELD = 25, 688 689 /** 690 * FieldPosition selector for 'L' field alignment, 691 * corresponding to the {@link #UCAL_MONTH} field. 692 * This displays the stand alone month name, if available. 693 * @stable ICU 3.4 694 */ 695 UDAT_STANDALONE_MONTH_FIELD = 26, 696 697 /** 698 * FieldPosition selector for "Q" field alignment, 699 * corresponding to quarters. This is implemented 700 * using the {@link #UCAL_MONTH} field. This 701 * displays the quarter. 702 * @stable ICU 3.6 703 */ 704 UDAT_QUARTER_FIELD = 27, 705 706 /** 707 * FieldPosition selector for the "q" field alignment, 708 * corresponding to stand-alone quarters. This is 709 * implemented using the {@link #UCAL_MONTH} field. 710 * This displays the stand-alone quarter. 711 * @stable ICU 3.6 712 */ 713 UDAT_STANDALONE_QUARTER_FIELD = 28, 714 715 /** 716 * FieldPosition and UFieldPosition selector for 'V' field alignment, 717 * corresponding to the UCAL_ZONE_OFFSET field. 718 * @stable ICU 3.8 719 */ 720 UDAT_TIMEZONE_SPECIAL_FIELD = 29, 721 722 /** 723 * FieldPosition selector for "U" field alignment, 724 * corresponding to cyclic year names. This is implemented 725 * using the {@link #UCAL_YEAR} field. This displays 726 * the cyclic year name, if available. 727 * @stable ICU 49 728 */ 729 UDAT_YEAR_NAME_FIELD = 30, 730 731 /** 732 * FieldPosition selector for 'O' field alignment, 733 * corresponding to the UCAL_ZONE_OFFSET and UCAL_DST_OFFSETfields. 734 * This displays the localized GMT format. 735 * @stable ICU 51 736 */ 737 UDAT_TIMEZONE_LOCALIZED_GMT_OFFSET_FIELD = 31, 738 739 /** 740 * FieldPosition selector for 'X' field alignment, 741 * corresponding to the UCAL_ZONE_OFFSET and UCAL_DST_OFFSETfields. 742 * This displays the ISO 8601 local time offset format or UTC indicator ("Z"). 743 * @stable ICU 51 744 */ 745 UDAT_TIMEZONE_ISO_FIELD = 32, 746 747 /** 748 * FieldPosition selector for 'x' field alignment, 749 * corresponding to the UCAL_ZONE_OFFSET and UCAL_DST_OFFSET fields. 750 * This displays the ISO 8601 local time offset format. 751 * @stable ICU 51 752 */ 753 UDAT_TIMEZONE_ISO_LOCAL_FIELD = 33, 754 755 #ifndef U_HIDE_INTERNAL_API 756 /** 757 * FieldPosition and UFieldPosition selector for 'r' field alignment, 758 * no directly corresponding UCAL_ field. 759 * @internal ICU 53 760 */ 761 UDAT_RELATED_YEAR_FIELD = 34, 762 #endif /* U_HIDE_INTERNAL_API */ 763 764 #ifndef U_HIDE_DRAFT_API 765 /** 766 * FieldPosition and UFieldPosition selector for ':' time separator, 767 * no corresponding UCAL_ field. 768 * @draft ICU 55 769 */ 770 UDAT_TIME_SEPARATOR_FIELD = 35, 771 #endif /* U_HIDE_DRAFT_API */ 772 773 /** 774 * Number of FieldPosition and UFieldPosition selectors for 775 * DateFormat and UDateFormat. 776 * Valid selectors range from 0 to UDAT_FIELD_COUNT-1. 777 * This value is subject to change if new fields are defined 778 * in the future. 779 * @stable ICU 3.0 780 */ 781 UDAT_FIELD_COUNT = 36 782 783 } UDateFormatField; 784 785 786 /** 787 * Maps from a UDateFormatField to the corresponding UCalendarDateFields. 788 * Note: since the mapping is many-to-one, there is no inverse mapping. 789 * @param field the UDateFormatField. 790 * @return the UCalendarDateField. This will be UCAL_FIELD_COUNT in case 791 * of error (e.g., the input field is UDAT_FIELD_COUNT). 792 * @stable ICU 4.4 793 */ 794 U_STABLE UCalendarDateFields U_EXPORT2 795 udat_toCalendarDateField(UDateFormatField field); 796 797 798 /** 799 * Open a new UDateFormat for formatting and parsing dates and times. 800 * A UDateFormat may be used to format dates in calls to {@link #udat_format }, 801 * and to parse dates in calls to {@link #udat_parse }. 802 * @param timeStyle The style used to format times; one of UDAT_FULL, UDAT_LONG, 803 * UDAT_MEDIUM, UDAT_SHORT, UDAT_DEFAULT, or UDAT_NONE (relative time styles 804 * are not currently supported). 805 * When the pattern parameter is used, pass in UDAT_PATTERN for both timeStyle and dateStyle. 806 * @param dateStyle The style used to format dates; one of UDAT_FULL, UDAT_LONG, 807 * UDAT_MEDIUM, UDAT_SHORT, UDAT_DEFAULT, UDAT_FULL_RELATIVE, UDAT_LONG_RELATIVE, 808 * UDAT_MEDIUM_RELATIVE, UDAT_SHORT_RELATIVE, or UDAT_NONE. 809 * When the pattern parameter is used, pass in UDAT_PATTERN for both timeStyle and dateStyle. 810 * As currently implemented, 811 * relative date formatting only affects a limited range of calendar days before or 812 * after the current date, based on the CLDR <field type="day">/<relative> data: For 813 * example, in English, "Yesterday", "Today", and "Tomorrow". Outside of this range, 814 * dates are formatted using the corresponding non-relative style. 815 * @param locale The locale specifying the formatting conventions 816 * @param tzID A timezone ID specifying the timezone to use. If 0, use 817 * the default timezone. 818 * @param tzIDLength The length of tzID, or -1 if null-terminated. 819 * @param pattern A pattern specifying the format to use. 820 * @param patternLength The number of characters in the pattern, or -1 if null-terminated. 821 * @param status A pointer to an UErrorCode to receive any errors 822 * @return A pointer to a UDateFormat to use for formatting dates and times, or 0 if 823 * an error occurred. 824 * @stable ICU 2.0 825 */ 826 U_STABLE UDateFormat* U_EXPORT2 827 udat_open(UDateFormatStyle timeStyle, 828 UDateFormatStyle dateStyle, 829 const char *locale, 830 const UChar *tzID, 831 int32_t tzIDLength, 832 const UChar *pattern, 833 int32_t patternLength, 834 UErrorCode *status); 835 836 837 /** 838 * Close a UDateFormat. 839 * Once closed, a UDateFormat may no longer be used. 840 * @param format The formatter to close. 841 * @stable ICU 2.0 842 */ 843 U_STABLE void U_EXPORT2 844 udat_close(UDateFormat* format); 845 846 847 /** 848 * DateFormat boolean attributes 849 * 850 * @stable ICU 53 851 */ 852 typedef enum UDateFormatBooleanAttribute { 853 /** 854 * indicates whether whitespace is allowed. Includes trailing dot tolerance. 855 * @stable ICU 53 856 */ 857 UDAT_PARSE_ALLOW_WHITESPACE = 0, 858 /** 859 * indicates tolerance of numeric data when String data may be assumed. eg: UDAT_YEAR_NAME_FIELD, 860 * UDAT_STANDALONE_MONTH_FIELD, UDAT_DAY_OF_WEEK_FIELD 861 * @stable ICU 53 862 */ 863 UDAT_PARSE_ALLOW_NUMERIC = 1, 864 #ifndef U_HIDE_DRAFT_API 865 /** 866 * indicates tolerance of a partial literal match 867 * @draft ICU 53 868 */ 869 UDAT_PARSE_PARTIAL_MATCH = 2, 870 /** 871 * indicates tolerance of pattern mismatch between input data and specified format pattern. 872 * e.g. accepting "September" for a month pattern of MMM ("Sep") 873 * @draft ICU 53 874 */ 875 UDAT_PARSE_MULTIPLE_PATTERNS_FOR_MATCH = 3, 876 #endif /* U_HIDE_DRAFT_API */ 877 /** 878 * count boolean date format constants 879 * @stable ICU 53 880 */ 881 UDAT_BOOLEAN_ATTRIBUTE_COUNT = 4 882 } UDateFormatBooleanAttribute; 883 884 /** 885 * Get a boolean attribute associated with a UDateFormat. 886 * An example would be a true value for a key of UDAT_PARSE_ALLOW_WHITESPACE indicating allowing whitespace leniency. 887 * If the formatter does not understand the attribute, -1 is returned. 888 * @param fmt The formatter to query. 889 * @param attr The attribute to query; e.g. UDAT_PARSE_ALLOW_WHITESPACE. 890 * @param status A pointer to an UErrorCode to receive any errors 891 * @return The value of attr. 892 * @stable ICU 53 893 */ 894 U_STABLE UBool U_EXPORT2 895 udat_getBooleanAttribute(const UDateFormat* fmt, UDateFormatBooleanAttribute attr, UErrorCode* status); 896 897 /** 898 * Set a boolean attribute associated with a UDateFormat. 899 * An example of a boolean attribute is parse leniency control. If the formatter does not understand 900 * the attribute, the call is ignored. 901 * @param fmt The formatter to set. 902 * @param attr The attribute to set; one of UDAT_PARSE_ALLOW_WHITESPACE or UDAT_PARSE_ALLOW_NUMERIC 903 * @param newValue The new value of attr. 904 * @param status A pointer to an UErrorCode to receive any errors 905 * @stable ICU 53 906 */ 907 U_STABLE void U_EXPORT2 908 udat_setBooleanAttribute(UDateFormat *fmt, UDateFormatBooleanAttribute attr, UBool newValue, UErrorCode* status); 909 910 911 912 #if U_SHOW_CPLUSPLUS_API 913 914 U_NAMESPACE_BEGIN 915 916 /** 917 * \class LocalUDateFormatPointer 918 * "Smart pointer" class, closes a UDateFormat via udat_close(). 919 * For most methods see the LocalPointerBase base class. 920 * 921 * @see LocalPointerBase 922 * @see LocalPointer 923 * @stable ICU 4.4 924 */ 925 U_DEFINE_LOCAL_OPEN_POINTER(LocalUDateFormatPointer, UDateFormat, udat_close); 926 927 U_NAMESPACE_END 928 929 #endif 930 931 /** 932 * Open a copy of a UDateFormat. 933 * This function performs a deep copy. 934 * @param fmt The format to copy 935 * @param status A pointer to an UErrorCode to receive any errors. 936 * @return A pointer to a UDateFormat identical to fmt. 937 * @stable ICU 2.0 938 */ 939 U_STABLE UDateFormat* U_EXPORT2 940 udat_clone(const UDateFormat *fmt, 941 UErrorCode *status); 942 943 /** 944 * Format a date using a UDateFormat. 945 * The date will be formatted using the conventions specified in {@link #udat_open } 946 * @param format The formatter to use 947 * @param dateToFormat The date to format 948 * @param result A pointer to a buffer to receive the formatted number. 949 * @param resultLength The maximum size of result. 950 * @param position A pointer to a UFieldPosition. On input, position->field 951 * is read. On output, position->beginIndex and position->endIndex indicate 952 * the beginning and ending indices of field number position->field, if such 953 * a field exists. This parameter may be NULL, in which case no field 954 * position data is returned. 955 * @param status A pointer to an UErrorCode to receive any errors 956 * @return The total buffer size needed; if greater than resultLength, the output was truncated. 957 * @see udat_parse 958 * @see UFieldPosition 959 * @stable ICU 2.0 960 */ 961 U_STABLE int32_t U_EXPORT2 962 udat_format( const UDateFormat* format, 963 UDate dateToFormat, 964 UChar* result, 965 int32_t resultLength, 966 UFieldPosition* position, 967 UErrorCode* status); 968 969 #ifndef U_HIDE_DRAFT_API 970 /** 971 * Format a date using an UDateFormat. 972 * The date will be formatted using the conventions specified in {@link #udat_open } 973 * @param format The formatter to use 974 * @param calendar The calendar to format. The calendar instance might be 975 * mutated if fields are not yet fully calculated, though 976 * the function won't change the logical date and time held 977 * by the instance. 978 * @param result A pointer to a buffer to receive the formatted number. 979 * @param capacity The maximum size of result. 980 * @param position A pointer to a UFieldPosition. On input, position->field 981 * is read. On output, position->beginIndex and position->endIndex indicate 982 * the beginning and ending indices of field number position->field, if such 983 * a field exists. This parameter may be NULL, in which case no field 984 * position data is returned. 985 * @param status A pointer to an UErrorCode to receive any errors 986 * @return The total buffer size needed; if greater than resultLength, the output was truncated. 987 * @see udat_format 988 * @see udat_parseCalendar 989 * @see UFieldPosition 990 * @draft ICU 55 991 */ 992 U_DRAFT int32_t U_EXPORT2 993 udat_formatCalendar( const UDateFormat* format, 994 UCalendar* calendar, 995 UChar* result, 996 int32_t capacity, 997 UFieldPosition* position, 998 UErrorCode* status); 999 1000 /** 1001 * Format a date using a UDateFormat. 1002 * The date will be formatted using the conventions specified in {@link #udat_open} 1003 * @param format 1004 * The formatter to use 1005 * @param dateToFormat 1006 * The date to format 1007 * @param result 1008 * A pointer to a buffer to receive the formatted number. 1009 * @param resultLength 1010 * The maximum size of result. 1011 * @param fpositer 1012 * A pointer to a UFieldPositionIterator created by {@link #ufieldpositer_open} 1013 * (may be NULL if field position information is not needed). Any 1014 * iteration information already present in the UFieldPositionIterator 1015 * will be deleted, and the iterator will be reset to apply to the 1016 * fields in the formatted string created by this function call; the 1017 * field values provided by {@link #ufieldpositer_next} will be from the 1018 * UDateFormatField enum. 1019 * @param status 1020 * A pointer to a UErrorCode to receive any errors 1021 * @return 1022 * The total buffer size needed; if greater than resultLength, the output was truncated. 1023 * @see udat_parse 1024 * @see UFieldPositionIterator 1025 * @draft ICU 55 1026 */ 1027 U_DRAFT int32_t U_EXPORT2 1028 udat_formatForFields( const UDateFormat* format, 1029 UDate dateToFormat, 1030 UChar* result, 1031 int32_t resultLength, 1032 UFieldPositionIterator* fpositer, 1033 UErrorCode* status); 1034 1035 /** 1036 * Format a date using a UDateFormat. 1037 * The date will be formatted using the conventions specified in {@link #udat_open } 1038 * @param format 1039 * The formatter to use 1040 * @param calendar 1041 * The calendar to format. The calendar instance might be mutated if fields 1042 * are not yet fully calculated, though the function won't change the logical 1043 * date and time held by the instance. 1044 * @param result 1045 * A pointer to a buffer to receive the formatted number. 1046 * @param capacity 1047 * The maximum size of result. 1048 * @param fpositer 1049 * A pointer to a UFieldPositionIterator created by {@link #ufieldpositer_open} 1050 * (may be NULL if field position information is not needed). Any 1051 * iteration information already present in the UFieldPositionIterator 1052 * will be deleted, and the iterator will be reset to apply to the 1053 * fields in the formatted string created by this function call; the 1054 * field values provided by {@link #ufieldpositer_next} will be from the 1055 * UDateFormatField enum. 1056 * @param status 1057 * A pointer to a UErrorCode to receive any errors 1058 * @return 1059 * The total buffer size needed; if greater than resultLength, the output was truncated. 1060 * @see udat_format 1061 * @see udat_parseCalendar 1062 * @see UFieldPositionIterator 1063 * @draft ICU 55 1064 */ 1065 U_DRAFT int32_t U_EXPORT2 1066 udat_formatCalendarForFields( const UDateFormat* format, 1067 UCalendar* calendar, 1068 UChar* result, 1069 int32_t capacity, 1070 UFieldPositionIterator* fpositer, 1071 UErrorCode* status); 1072 1073 #endif /* U_HIDE_DRAFT_API */ 1074 1075 /** 1076 * Parse a string into an date/time using a UDateFormat. 1077 * The date will be parsed using the conventions specified in {@link #udat_open }. 1078 * <P> 1079 * Note that the normal date formats associated with some calendars - such 1080 * as the Chinese lunar calendar - do not specify enough fields to enable 1081 * dates to be parsed unambiguously. In the case of the Chinese lunar 1082 * calendar, while the year within the current 60-year cycle is specified, 1083 * the number of such cycles since the start date of the calendar (in the 1084 * UCAL_ERA field of the UCalendar object) is not normally part of the format, 1085 * and parsing may assume the wrong era. For cases such as this it is 1086 * recommended that clients parse using udat_parseCalendar with the UCalendar 1087 * passed in set to the current date, or to a date within the era/cycle that 1088 * should be assumed if absent in the format. 1089 * 1090 * @param format The formatter to use. 1091 * @param text The text to parse. 1092 * @param textLength The length of text, or -1 if null-terminated. 1093 * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which 1094 * to begin parsing. If not 0, on output the offset at which parsing ended. 1095 * @param status A pointer to an UErrorCode to receive any errors 1096 * @return The value of the parsed date/time 1097 * @see udat_format 1098 * @stable ICU 2.0 1099 */ 1100 U_STABLE UDate U_EXPORT2 1101 udat_parse(const UDateFormat* format, 1102 const UChar* text, 1103 int32_t textLength, 1104 int32_t *parsePos, 1105 UErrorCode *status); 1106 1107 /** 1108 * Parse a string into an date/time using a UDateFormat. 1109 * The date will be parsed using the conventions specified in {@link #udat_open }. 1110 * @param format The formatter to use. 1111 * @param calendar A calendar set on input to the date and time to be used for 1112 * missing values in the date/time string being parsed, and set 1113 * on output to the parsed date/time. When the calendar type is 1114 * different from the internal calendar held by the UDateFormat 1115 * instance, the internal calendar will be cloned to a work 1116 * calendar set to the same milliseconds and time zone as this 1117 * calendar parameter, field values will be parsed based on the 1118 * work calendar, then the result (milliseconds and time zone) 1119 * will be set in this calendar. 1120 * @param text The text to parse. 1121 * @param textLength The length of text, or -1 if null-terminated. 1122 * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which 1123 * to begin parsing. If not 0, on output the offset at which parsing ended. 1124 * @param status A pointer to an UErrorCode to receive any errors 1125 * @see udat_format 1126 * @stable ICU 2.0 1127 */ 1128 U_STABLE void U_EXPORT2 1129 udat_parseCalendar(const UDateFormat* format, 1130 UCalendar* calendar, 1131 const UChar* text, 1132 int32_t textLength, 1133 int32_t *parsePos, 1134 UErrorCode *status); 1135 1136 /** 1137 * Determine if an UDateFormat will perform lenient parsing. 1138 * With lenient parsing, the parser may use heuristics to interpret inputs that do not 1139 * precisely match the pattern. With strict parsing, inputs must match the pattern. 1140 * @param fmt The formatter to query 1141 * @return TRUE if fmt is set to perform lenient parsing, FALSE otherwise. 1142 * @see udat_setLenient 1143 * @stable ICU 2.0 1144 */ 1145 U_STABLE UBool U_EXPORT2 1146 udat_isLenient(const UDateFormat* fmt); 1147 1148 /** 1149 * Specify whether an UDateFormat will perform lenient parsing. 1150 * With lenient parsing, the parser may use heuristics to interpret inputs that do not 1151 * precisely match the pattern. With strict parsing, inputs must match the pattern. 1152 * @param fmt The formatter to set 1153 * @param isLenient TRUE if fmt should perform lenient parsing, FALSE otherwise. 1154 * @see dat_isLenient 1155 * @stable ICU 2.0 1156 */ 1157 U_STABLE void U_EXPORT2 1158 udat_setLenient( UDateFormat* fmt, 1159 UBool isLenient); 1160 1161 /** 1162 * Get the UCalendar associated with an UDateFormat. 1163 * A UDateFormat uses a UCalendar to convert a raw value to, for example, 1164 * the day of the week. 1165 * @param fmt The formatter to query. 1166 * @return A pointer to the UCalendar used by fmt. 1167 * @see udat_setCalendar 1168 * @stable ICU 2.0 1169 */ 1170 U_STABLE const UCalendar* U_EXPORT2 1171 udat_getCalendar(const UDateFormat* fmt); 1172 1173 /** 1174 * Set the UCalendar associated with an UDateFormat. 1175 * A UDateFormat uses a UCalendar to convert a raw value to, for example, 1176 * the day of the week. 1177 * @param fmt The formatter to set. 1178 * @param calendarToSet A pointer to an UCalendar to be used by fmt. 1179 * @see udat_setCalendar 1180 * @stable ICU 2.0 1181 */ 1182 U_STABLE void U_EXPORT2 1183 udat_setCalendar( UDateFormat* fmt, 1184 const UCalendar* calendarToSet); 1185 1186 /** 1187 * Get the UNumberFormat associated with an UDateFormat. 1188 * A UDateFormat uses a UNumberFormat to format numbers within a date, 1189 * for example the day number. 1190 * @param fmt The formatter to query. 1191 * @return A pointer to the UNumberFormat used by fmt to format numbers. 1192 * @see udat_setNumberFormat 1193 * @stable ICU 2.0 1194 */ 1195 U_STABLE const UNumberFormat* U_EXPORT2 1196 udat_getNumberFormat(const UDateFormat* fmt); 1197 1198 #ifndef U_HIDE_DRAFT_API 1199 /** 1200 * Get the UNumberFormat for specific field associated with an UDateFormat. 1201 * For example: 'y' for year and 'M' for month 1202 * @param fmt The formatter to query. 1203 * @param field the field to query 1204 * @return A pointer to the UNumberFormat used by fmt to format field numbers. 1205 * @see udat_setNumberFormatForField 1206 * @draft ICU 54 1207 */ 1208 U_DRAFT const UNumberFormat* U_EXPORT2 1209 udat_getNumberFormatForField(const UDateFormat* fmt, UChar field); 1210 1211 /** 1212 * Set the UNumberFormat for specific field associated with an UDateFormat. 1213 * It can be a single field like: "y"(year) or "M"(month) 1214 * It can be several field combined together: "yM"(year and month) 1215 * Note: 1216 * 1 symbol field is enough for multiple symbol field (so "y" will override "yy", "yyy") 1217 * If the field is not numeric, then override has no effect (like "MMM" will use abbreviation, not numerical field) 1218 * 1219 * @param fields the fields to set 1220 * @param fmt The formatter to set. 1221 * @param numberFormatToSet A pointer to the UNumberFormat to be used by fmt to format numbers. 1222 * @param status error code passed around (memory allocation or invalid fields) 1223 * @see udat_getNumberFormatForField 1224 * @draft ICU 54 1225 */ 1226 U_DRAFT void U_EXPORT2 1227 udat_adoptNumberFormatForFields( UDateFormat* fmt, 1228 const UChar* fields, 1229 UNumberFormat* numberFormatToSet, 1230 UErrorCode* status); 1231 #endif /* U_HIDE_DRAFT_API */ 1232 1233 /** 1234 * Set the UNumberFormat associated with an UDateFormat. 1235 * A UDateFormat uses a UNumberFormat to format numbers within a date, 1236 * for example the day number. 1237 * This method also clears per field NumberFormat instances previously 1238 * set by {@see udat_setNumberFormatForField} 1239 * @param fmt The formatter to set. 1240 * @param numberFormatToSet A pointer to the UNumberFormat to be used by fmt to format numbers. 1241 * @see udat_getNumberFormat 1242 * @see udat_setNumberFormatForField 1243 * @stable ICU 2.0 1244 */ 1245 U_STABLE void U_EXPORT2 1246 udat_setNumberFormat( UDateFormat* fmt, 1247 const UNumberFormat* numberFormatToSet); 1248 1249 #ifndef U_HIDE_DRAFT_API 1250 /** 1251 * Adopt the UNumberFormat associated with an UDateFormat. 1252 * A UDateFormat uses a UNumberFormat to format numbers within a date, 1253 * for example the day number. 1254 * @param fmt The formatter to set. 1255 * @param numberFormatToAdopt A pointer to the UNumberFormat to be used by fmt to format numbers. 1256 * @see udat_getNumberFormat 1257 * @draft ICU 54 1258 */ 1259 U_DRAFT void U_EXPORT2 1260 udat_adoptNumberFormat( UDateFormat* fmt, 1261 UNumberFormat* numberFormatToAdopt); 1262 #endif /* U_HIDE_DRAFT_API */ 1263 1264 /** 1265 * Get a locale for which date/time formatting patterns are available. 1266 * A UDateFormat in a locale returned by this function will perform the correct 1267 * formatting and parsing for the locale. 1268 * @param localeIndex The index of the desired locale. 1269 * @return A locale for which date/time formatting patterns are available, or 0 if none. 1270 * @see udat_countAvailable 1271 * @stable ICU 2.0 1272 */ 1273 U_STABLE const char* U_EXPORT2 1274 udat_getAvailable(int32_t localeIndex); 1275 1276 /** 1277 * Determine how many locales have date/time formatting patterns available. 1278 * This function is most useful as determining the loop ending condition for 1279 * calls to {@link #udat_getAvailable }. 1280 * @return The number of locales for which date/time formatting patterns are available. 1281 * @see udat_getAvailable 1282 * @stable ICU 2.0 1283 */ 1284 U_STABLE int32_t U_EXPORT2 1285 udat_countAvailable(void); 1286 1287 /** 1288 * Get the year relative to which all 2-digit years are interpreted. 1289 * For example, if the 2-digit start year is 2100, the year 99 will be 1290 * interpreted as 2199. 1291 * @param fmt The formatter to query. 1292 * @param status A pointer to an UErrorCode to receive any errors 1293 * @return The year relative to which all 2-digit years are interpreted. 1294 * @see udat_Set2DigitYearStart 1295 * @stable ICU 2.0 1296 */ 1297 U_STABLE UDate U_EXPORT2 1298 udat_get2DigitYearStart( const UDateFormat *fmt, 1299 UErrorCode *status); 1300 1301 /** 1302 * Set the year relative to which all 2-digit years will be interpreted. 1303 * For example, if the 2-digit start year is 2100, the year 99 will be 1304 * interpreted as 2199. 1305 * @param fmt The formatter to set. 1306 * @param d The year relative to which all 2-digit years will be interpreted. 1307 * @param status A pointer to an UErrorCode to receive any errors 1308 * @see udat_Set2DigitYearStart 1309 * @stable ICU 2.0 1310 */ 1311 U_STABLE void U_EXPORT2 1312 udat_set2DigitYearStart( UDateFormat *fmt, 1313 UDate d, 1314 UErrorCode *status); 1315 1316 /** 1317 * Extract the pattern from a UDateFormat. 1318 * The pattern will follow the pattern syntax rules. 1319 * @param fmt The formatter to query. 1320 * @param localized TRUE if the pattern should be localized, FALSE otherwise. 1321 * @param result A pointer to a buffer to receive the pattern. 1322 * @param resultLength The maximum size of result. 1323 * @param status A pointer to an UErrorCode to receive any errors 1324 * @return The total buffer size needed; if greater than resultLength, the output was truncated. 1325 * @see udat_applyPattern 1326 * @stable ICU 2.0 1327 */ 1328 U_STABLE int32_t U_EXPORT2 1329 udat_toPattern( const UDateFormat *fmt, 1330 UBool localized, 1331 UChar *result, 1332 int32_t resultLength, 1333 UErrorCode *status); 1334 1335 /** 1336 * Set the pattern used by an UDateFormat. 1337 * The pattern should follow the pattern syntax rules. 1338 * @param format The formatter to set. 1339 * @param localized TRUE if the pattern is localized, FALSE otherwise. 1340 * @param pattern The new pattern 1341 * @param patternLength The length of pattern, or -1 if null-terminated. 1342 * @see udat_toPattern 1343 * @stable ICU 2.0 1344 */ 1345 U_STABLE void U_EXPORT2 1346 udat_applyPattern( UDateFormat *format, 1347 UBool localized, 1348 const UChar *pattern, 1349 int32_t patternLength); 1350 1351 /** 1352 * The possible types of date format symbols 1353 * @stable ICU 2.6 1354 */ 1355 typedef enum UDateFormatSymbolType { 1356 /** The era names, for example AD */ 1357 UDAT_ERAS, 1358 /** The month names, for example February */ 1359 UDAT_MONTHS, 1360 /** The short month names, for example Feb. */ 1361 UDAT_SHORT_MONTHS, 1362 /** The CLDR-style format "wide" weekday names, for example Monday */ 1363 UDAT_WEEKDAYS, 1364 /** 1365 * The CLDR-style format "abbreviated" (not "short") weekday names, for example "Mon." 1366 * For the CLDR-style format "short" weekday names, use UDAT_SHORTER_WEEKDAYS. 1367 */ 1368 UDAT_SHORT_WEEKDAYS, 1369 /** The AM/PM names, for example AM */ 1370 UDAT_AM_PMS, 1371 /** The localized characters */ 1372 UDAT_LOCALIZED_CHARS, 1373 /** The long era names, for example Anno Domini */ 1374 UDAT_ERA_NAMES, 1375 /** The narrow month names, for example F */ 1376 UDAT_NARROW_MONTHS, 1377 /** The CLDR-style format "narrow" weekday names, for example "M" */ 1378 UDAT_NARROW_WEEKDAYS, 1379 /** Standalone context versions of months */ 1380 UDAT_STANDALONE_MONTHS, 1381 UDAT_STANDALONE_SHORT_MONTHS, 1382 UDAT_STANDALONE_NARROW_MONTHS, 1383 /** The CLDR-style stand-alone "wide" weekday names */ 1384 UDAT_STANDALONE_WEEKDAYS, 1385 /** 1386 * The CLDR-style stand-alone "abbreviated" (not "short") weekday names. 1387 * For the CLDR-style stand-alone "short" weekday names, use UDAT_STANDALONE_SHORTER_WEEKDAYS. 1388 */ 1389 UDAT_STANDALONE_SHORT_WEEKDAYS, 1390 /** The CLDR-style stand-alone "narrow" weekday names */ 1391 UDAT_STANDALONE_NARROW_WEEKDAYS, 1392 /** The quarters, for example 1st Quarter */ 1393 UDAT_QUARTERS, 1394 /** The short quarter names, for example Q1 */ 1395 UDAT_SHORT_QUARTERS, 1396 /** Standalone context versions of quarters */ 1397 UDAT_STANDALONE_QUARTERS, 1398 UDAT_STANDALONE_SHORT_QUARTERS, 1399 /** 1400 * The CLDR-style short weekday names, e.g. "Su", Mo", etc. 1401 * These are named "SHORTER" to contrast with the constants using _SHORT_ 1402 * above, which actually get the CLDR-style *abbreviated* versions of the 1403 * corresponding names. 1404 * @stable ICU 51 1405 */ 1406 UDAT_SHORTER_WEEKDAYS, 1407 /** 1408 * Standalone version of UDAT_SHORTER_WEEKDAYS. 1409 * @stable ICU 51 1410 */ 1411 UDAT_STANDALONE_SHORTER_WEEKDAYS 1412 #ifndef U_HIDE_DRAFT_API 1413 , 1414 /** 1415 * Cyclic year names (only supported for some calendars, and only for FORMAT usage; 1416 * udat_setSymbols not supported for UDAT_CYCLIC_YEARS_WIDE) 1417 * @draft ICU 54 1418 */ 1419 UDAT_CYCLIC_YEARS_WIDE, 1420 /** 1421 * Cyclic year names (only supported for some calendars, and only for FORMAT usage) 1422 * @draft ICU 54 1423 */ 1424 UDAT_CYCLIC_YEARS_ABBREVIATED, 1425 /** 1426 * Cyclic year names (only supported for some calendars, and only for FORMAT usage; 1427 * udat_setSymbols not supported for UDAT_CYCLIC_YEARS_NARROW) 1428 * @draft ICU 54 1429 */ 1430 UDAT_CYCLIC_YEARS_NARROW, 1431 /** 1432 * Calendar zodiac names (only supported for some calendars, and only for FORMAT usage; 1433 * udat_setSymbols not supported for UDAT_ZODIAC_NAMES_WIDE) 1434 * @draft ICU 54 1435 */ 1436 UDAT_ZODIAC_NAMES_WIDE, 1437 /** 1438 * Calendar zodiac names (only supported for some calendars, and only for FORMAT usage) 1439 * @draft ICU 54 1440 */ 1441 UDAT_ZODIAC_NAMES_ABBREVIATED, 1442 /** 1443 * Calendar zodiac names (only supported for some calendars, and only for FORMAT usage; 1444 * udat_setSymbols not supported for UDAT_ZODIAC_NAMES_NARROW) 1445 * @draft ICU 54 1446 */ 1447 UDAT_ZODIAC_NAMES_NARROW 1448 #endif /* U_HIDE_DRAFT_API */ 1449 } UDateFormatSymbolType; 1450 1451 struct UDateFormatSymbols; 1452 /** Date format symbols. 1453 * For usage in C programs. 1454 * @stable ICU 2.6 1455 */ 1456 typedef struct UDateFormatSymbols UDateFormatSymbols; 1457 1458 /** 1459 * Get the symbols associated with an UDateFormat. 1460 * The symbols are what a UDateFormat uses to represent locale-specific data, 1461 * for example month or day names. 1462 * @param fmt The formatter to query. 1463 * @param type The type of symbols to get. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS, 1464 * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS 1465 * @param symbolIndex The desired symbol of type type. 1466 * @param result A pointer to a buffer to receive the pattern. 1467 * @param resultLength The maximum size of result. 1468 * @param status A pointer to an UErrorCode to receive any errors 1469 * @return The total buffer size needed; if greater than resultLength, the output was truncated. 1470 * @see udat_countSymbols 1471 * @see udat_setSymbols 1472 * @stable ICU 2.0 1473 */ 1474 U_STABLE int32_t U_EXPORT2 1475 udat_getSymbols(const UDateFormat *fmt, 1476 UDateFormatSymbolType type, 1477 int32_t symbolIndex, 1478 UChar *result, 1479 int32_t resultLength, 1480 UErrorCode *status); 1481 1482 /** 1483 * Count the number of particular symbols for an UDateFormat. 1484 * This function is most useful as for detemining the loop termination condition 1485 * for calls to {@link #udat_getSymbols }. 1486 * @param fmt The formatter to query. 1487 * @param type The type of symbols to count. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS, 1488 * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS 1489 * @return The number of symbols of type type. 1490 * @see udat_getSymbols 1491 * @see udat_setSymbols 1492 * @stable ICU 2.0 1493 */ 1494 U_STABLE int32_t U_EXPORT2 1495 udat_countSymbols( const UDateFormat *fmt, 1496 UDateFormatSymbolType type); 1497 1498 /** 1499 * Set the symbols associated with an UDateFormat. 1500 * The symbols are what a UDateFormat uses to represent locale-specific data, 1501 * for example month or day names. 1502 * @param format The formatter to set 1503 * @param type The type of symbols to set. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS, 1504 * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS 1505 * @param symbolIndex The index of the symbol to set of type type. 1506 * @param value The new value 1507 * @param valueLength The length of value, or -1 if null-terminated 1508 * @param status A pointer to an UErrorCode to receive any errors 1509 * @see udat_getSymbols 1510 * @see udat_countSymbols 1511 * @stable ICU 2.0 1512 */ 1513 U_STABLE void U_EXPORT2 1514 udat_setSymbols( UDateFormat *format, 1515 UDateFormatSymbolType type, 1516 int32_t symbolIndex, 1517 UChar *value, 1518 int32_t valueLength, 1519 UErrorCode *status); 1520 1521 /** 1522 * Get the locale for this date format object. 1523 * You can choose between valid and actual locale. 1524 * @param fmt The formatter to get the locale from 1525 * @param type type of the locale we're looking for (valid or actual) 1526 * @param status error code for the operation 1527 * @return the locale name 1528 * @stable ICU 2.8 1529 */ 1530 U_STABLE const char* U_EXPORT2 1531 udat_getLocaleByType(const UDateFormat *fmt, 1532 ULocDataLocaleType type, 1533 UErrorCode* status); 1534 1535 /** 1536 * Set a particular UDisplayContext value in the formatter, such as 1537 * UDISPCTX_CAPITALIZATION_FOR_STANDALONE. 1538 * @param fmt The formatter for which to set a UDisplayContext value. 1539 * @param value The UDisplayContext value to set. 1540 * @param status A pointer to an UErrorCode to receive any errors 1541 * @stable ICU 51 1542 */ 1543 U_DRAFT void U_EXPORT2 1544 udat_setContext(UDateFormat* fmt, UDisplayContext value, UErrorCode* status); 1545 1546 /** 1547 * Get the formatter's UDisplayContext value for the specified UDisplayContextType, 1548 * such as UDISPCTX_TYPE_CAPITALIZATION. 1549 * @param fmt The formatter to query. 1550 * @param type The UDisplayContextType whose value to return 1551 * @param status A pointer to an UErrorCode to receive any errors 1552 * @return The UDisplayContextValue for the specified type. 1553 * @stable ICU 53 1554 */ 1555 U_STABLE UDisplayContext U_EXPORT2 1556 udat_getContext(const UDateFormat* fmt, UDisplayContextType type, UErrorCode* status); 1557 1558 #ifndef U_HIDE_INTERNAL_API 1559 /** 1560 * Extract the date pattern from a UDateFormat set for relative date formatting. 1561 * The pattern will follow the pattern syntax rules. 1562 * @param fmt The formatter to query. 1563 * @param result A pointer to a buffer to receive the pattern. 1564 * @param resultLength The maximum size of result. 1565 * @param status A pointer to a UErrorCode to receive any errors 1566 * @return The total buffer size needed; if greater than resultLength, the output was truncated. 1567 * @see udat_applyPatternRelative 1568 * @internal ICU 4.2 technology preview 1569 */ 1570 U_INTERNAL int32_t U_EXPORT2 1571 udat_toPatternRelativeDate(const UDateFormat *fmt, 1572 UChar *result, 1573 int32_t resultLength, 1574 UErrorCode *status); 1575 1576 /** 1577 * Extract the time pattern from a UDateFormat set for relative date formatting. 1578 * The pattern will follow the pattern syntax rules. 1579 * @param fmt The formatter to query. 1580 * @param result A pointer to a buffer to receive the pattern. 1581 * @param resultLength The maximum size of result. 1582 * @param status A pointer to a UErrorCode to receive any errors 1583 * @return The total buffer size needed; if greater than resultLength, the output was truncated. 1584 * @see udat_applyPatternRelative 1585 * @internal ICU 4.2 technology preview 1586 */ 1587 U_INTERNAL int32_t U_EXPORT2 1588 udat_toPatternRelativeTime(const UDateFormat *fmt, 1589 UChar *result, 1590 int32_t resultLength, 1591 UErrorCode *status); 1592 1593 /** 1594 * Set the date & time patterns used by a UDateFormat set for relative date formatting. 1595 * The patterns should follow the pattern syntax rules. 1596 * @param format The formatter to set. 1597 * @param datePattern The new date pattern 1598 * @param datePatternLength The length of datePattern, or -1 if null-terminated. 1599 * @param timePattern The new time pattern 1600 * @param timePatternLength The length of timePattern, or -1 if null-terminated. 1601 * @param status A pointer to a UErrorCode to receive any errors 1602 * @see udat_toPatternRelativeDate, udat_toPatternRelativeTime 1603 * @internal ICU 4.2 technology preview 1604 */ 1605 U_INTERNAL void U_EXPORT2 1606 udat_applyPatternRelative(UDateFormat *format, 1607 const UChar *datePattern, 1608 int32_t datePatternLength, 1609 const UChar *timePattern, 1610 int32_t timePatternLength, 1611 UErrorCode *status); 1612 1613 /** 1614 * @internal 1615 * @see udat_open 1616 */ 1617 typedef UDateFormat* (U_EXPORT2 *UDateFormatOpener) (UDateFormatStyle timeStyle, 1618 UDateFormatStyle dateStyle, 1619 const char *locale, 1620 const UChar *tzID, 1621 int32_t tzIDLength, 1622 const UChar *pattern, 1623 int32_t patternLength, 1624 UErrorCode *status); 1625 1626 /** 1627 * Register a provider factory 1628 * @internal ICU 49 1629 */ 1630 U_INTERNAL void U_EXPORT2 1631 udat_registerOpener(UDateFormatOpener opener, UErrorCode *status); 1632 1633 /** 1634 * Un-Register a provider factory 1635 * @internal ICU 49 1636 */ 1637 U_INTERNAL UDateFormatOpener U_EXPORT2 1638 udat_unregisterOpener(UDateFormatOpener opener, UErrorCode *status); 1639 #endif /* U_HIDE_INTERNAL_API */ 1640 1641 1642 #endif /* #if !UCONFIG_NO_FORMATTING */ 1643 1644 #endif 1645