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