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