1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *******************************************************************************
5 * Copyright (C) 1996-2016, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 *******************************************************************************
13 #include "unicode/utypes.h"
15 #if !UCONFIG_NO_FORMATTING
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"
24 * \brief C API: DateFormat
26 * <h2> Date Format C API</h2>
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.
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.
40 * To format a date for the current Locale with default time and date style,
41 * use one of the static factory methods:
44 * UErrorCode status = U_ZERO_ERROR;
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);
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.
61 * UErrorCode status = U_ZERO_ERROR;
62 * int32_t i, myStrlen = 0;
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) );
79 * To get specific fields of a date, you can use UFieldPosition to
80 * get specific fields.
83 * UErrorCode status = U_ZERO_ERROR;
86 * int32_t myStrlen = 0;
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);
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]);
102 * To format a date for a different Locale, specify it in the call to
106 * UDateFormat* df = udat_open(UDAT_SHORT, UDAT_SHORT, "fr_FR", NULL, -1, NULL, 0, &status);
109 * You can use a DateFormat API udat_parse() to parse.
112 * UErrorCode status = U_ZERO_ERROR;
113 * int32_t parsepos=0;
114 * UDate myDate = udat_parse(df, myString, u_strlen(myString), &parsepos, &status);
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
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.
128 * You can also set the time zone on the format if you wish.
130 * You can also use forms of the parse and format methods with Parse Position and
131 * UFieldPosition to allow you to
133 * <li> Progressively parse through pieces of a string.
134 * <li> Align any particular field, or find out where it is for selection
137 * <p><strong>Date and Time Patterns:</strong></p>
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>
149 /** A date formatter.
150 * For usage in C programs.
153 typedef void* UDateFormat
;
155 /** The possible date/time format styles
158 typedef enum UDateFormatStyle
{
168 UDAT_DEFAULT
= UDAT_MEDIUM
,
170 /** Bitfield for relative date */
171 UDAT_RELATIVE
= (1 << 7),
173 UDAT_FULL_RELATIVE
= UDAT_FULL
| UDAT_RELATIVE
,
175 UDAT_LONG_RELATIVE
= UDAT_LONG
| UDAT_RELATIVE
,
177 UDAT_MEDIUM_RELATIVE
= UDAT_MEDIUM
| UDAT_RELATIVE
,
179 UDAT_SHORT_RELATIVE
= UDAT_SHORT
| UDAT_RELATIVE
,
186 * Use the pattern given in the parameter to udat_open
192 #ifndef U_HIDE_INTERNAL_API
193 /** @internal alias to UDAT_PATTERN */
194 UDAT_IGNORE
= UDAT_PATTERN
195 #endif /* U_HIDE_INTERNAL_API */
198 /* Skeletons for dates. */
201 * Constant for date skeleton with year.
204 #define UDAT_YEAR "y"
206 * Constant for date skeleton with quarter.
209 #define UDAT_QUARTER "QQQQ"
211 * Constant for date skeleton with abbreviated quarter.
214 #define UDAT_ABBR_QUARTER "QQQ"
216 * Constant for date skeleton with year and quarter.
219 #define UDAT_YEAR_QUARTER "yQQQQ"
221 * Constant for date skeleton with year and abbreviated quarter.
224 #define UDAT_YEAR_ABBR_QUARTER "yQQQ"
226 * Constant for date skeleton with month.
229 #define UDAT_MONTH "MMMM"
231 * Constant for date skeleton with abbreviated month.
234 #define UDAT_ABBR_MONTH "MMM"
236 * Constant for date skeleton with numeric month.
239 #define UDAT_NUM_MONTH "M"
241 * Constant for date skeleton with year and month.
244 #define UDAT_YEAR_MONTH "yMMMM"
246 * Constant for date skeleton with year and abbreviated month.
249 #define UDAT_YEAR_ABBR_MONTH "yMMM"
251 * Constant for date skeleton with year and numeric month.
254 #define UDAT_YEAR_NUM_MONTH "yM"
256 * Constant for date skeleton with day.
261 * Constant for date skeleton with year, month, and day.
262 * Used in combinations date + time, date + time + zone, or time + zone.
265 #define UDAT_YEAR_MONTH_DAY "yMMMMd"
267 * Constant for date skeleton with year, abbreviated month, and day.
268 * Used in combinations date + time, date + time + zone, or time + zone.
271 #define UDAT_YEAR_ABBR_MONTH_DAY "yMMMd"
273 * Constant for date skeleton with year, numeric month, and day.
274 * Used in combinations date + time, date + time + zone, or time + zone.
277 #define UDAT_YEAR_NUM_MONTH_DAY "yMd"
279 * Constant for date skeleton with weekday.
282 #define UDAT_WEEKDAY "EEEE"
284 * Constant for date skeleton with abbreviated weekday.
287 #define UDAT_ABBR_WEEKDAY "E"
289 * Constant for date skeleton with year, month, weekday, and day.
290 * Used in combinations date + time, date + time + zone, or time + zone.
293 #define UDAT_YEAR_MONTH_WEEKDAY_DAY "yMMMMEEEEd"
295 * Constant for date skeleton with year, abbreviated month, weekday, and day.
296 * Used in combinations date + time, date + time + zone, or time + zone.
299 #define UDAT_YEAR_ABBR_MONTH_WEEKDAY_DAY "yMMMEd"
301 * Constant for date skeleton with year, numeric month, weekday, and day.
302 * Used in combinations date + time, date + time + zone, or time + zone.
305 #define UDAT_YEAR_NUM_MONTH_WEEKDAY_DAY "yMEd"
307 * Constant for date skeleton with long month and day.
308 * Used in combinations date + time, date + time + zone, or time + zone.
311 #define UDAT_MONTH_DAY "MMMMd"
313 * Constant for date skeleton with abbreviated month and day.
314 * Used in combinations date + time, date + time + zone, or time + zone.
317 #define UDAT_ABBR_MONTH_DAY "MMMd"
319 * Constant for date skeleton with numeric month and day.
320 * Used in combinations date + time, date + time + zone, or time + zone.
323 #define UDAT_NUM_MONTH_DAY "Md"
325 * Constant for date skeleton with month, weekday, and day.
326 * Used in combinations date + time, date + time + zone, or time + zone.
329 #define UDAT_MONTH_WEEKDAY_DAY "MMMMEEEEd"
331 * Constant for date skeleton with abbreviated month, weekday, and day.
332 * Used in combinations date + time, date + time + zone, or time + zone.
335 #define UDAT_ABBR_MONTH_WEEKDAY_DAY "MMMEd"
337 * Constant for date skeleton with numeric month, weekday, and day.
338 * Used in combinations date + time, date + time + zone, or time + zone.
341 #define UDAT_NUM_MONTH_WEEKDAY_DAY "MEd"
343 /* Skeletons for times. */
346 * Constant for date skeleton with hour, with the locale's preferred hour format (12 or 24).
349 #define UDAT_HOUR "j"
351 * Constant for date skeleton with hour in 24-hour presentation.
354 #define UDAT_HOUR24 "H"
356 * Constant for date skeleton with minute.
359 #define UDAT_MINUTE "m"
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.
365 #define UDAT_HOUR_MINUTE "jm"
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.
371 #define UDAT_HOUR24_MINUTE "Hm"
373 * Constant for date skeleton with second.
376 #define UDAT_SECOND "s"
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.
383 #define UDAT_HOUR_MINUTE_SECOND "jms"
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.
390 #define UDAT_HOUR24_MINUTE_SECOND "Hms"
392 * Constant for date skeleton with minute and second.
393 * Used in combinations date + time, date + time + zone, or time + zone.
396 #define UDAT_MINUTE_SECOND "ms"
398 /* Skeletons for time zones. */
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>
407 #define UDAT_LOCATION_TZ "VVVV"
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>
415 #define UDAT_GENERIC_TZ "vvvv"
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>
423 #define UDAT_ABBR_GENERIC_TZ "v"
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>
431 #define UDAT_SPECIFIC_TZ "zzzz"
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>
439 #define UDAT_ABBR_SPECIFIC_TZ "z"
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>
447 #define UDAT_ABBR_UTC_TZ "ZZZZ"
449 /* deprecated skeleton constants */
451 #ifndef U_HIDE_DEPRECATED_API
453 * Constant for date skeleton with standalone month.
454 * @deprecated ICU 50 Use UDAT_MONTH instead.
456 #define UDAT_STANDALONE_MONTH "LLLL"
458 * Constant for date skeleton with standalone abbreviated month.
459 * @deprecated ICU 50 Use UDAT_ABBR_MONTH instead.
461 #define UDAT_ABBR_STANDALONE_MONTH "LLL"
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.
467 #define UDAT_HOUR_MINUTE_GENERIC_TZ "jmv"
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.
472 #define UDAT_HOUR_MINUTE_TZ "jmz"
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.
477 #define UDAT_HOUR_GENERIC_TZ "jv"
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.
482 #define UDAT_HOUR_TZ "jz"
483 #endif /* U_HIDE_DEPRECATED_API */
486 * FieldPosition and UFieldPosition selectors for format fields
487 * defined by DateFormat and UDateFormat.
490 typedef enum UDateFormatField
{
492 * FieldPosition and UFieldPosition selector for 'G' field alignment,
493 * corresponding to the UCAL_ERA field.
499 * FieldPosition and UFieldPosition selector for 'y' field alignment,
500 * corresponding to the UCAL_YEAR field.
506 * FieldPosition and UFieldPosition selector for 'M' field alignment,
507 * corresponding to the UCAL_MONTH field.
510 UDAT_MONTH_FIELD
= 2,
513 * FieldPosition and UFieldPosition selector for 'd' field alignment,
514 * corresponding to the UCAL_DATE field.
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.
526 UDAT_HOUR_OF_DAY1_FIELD
= 4,
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.
535 UDAT_HOUR_OF_DAY0_FIELD
= 5,
538 * FieldPosition and UFieldPosition selector for 'm' field alignment,
539 * corresponding to the UCAL_MINUTE field.
542 UDAT_MINUTE_FIELD
= 6,
545 * FieldPosition and UFieldPosition selector for 's' field alignment,
546 * corresponding to the UCAL_SECOND field.
549 UDAT_SECOND_FIELD
= 7,
552 * FieldPosition and UFieldPosition selector for 'S' field alignment,
553 * corresponding to the UCAL_MILLISECOND field.
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.
564 UDAT_FRACTIONAL_SECOND_FIELD
= 8,
567 * FieldPosition and UFieldPosition selector for 'E' field alignment,
568 * corresponding to the UCAL_DAY_OF_WEEK field.
571 UDAT_DAY_OF_WEEK_FIELD
= 9,
574 * FieldPosition and UFieldPosition selector for 'D' field alignment,
575 * corresponding to the UCAL_DAY_OF_YEAR field.
578 UDAT_DAY_OF_YEAR_FIELD
= 10,
581 * FieldPosition and UFieldPosition selector for 'F' field alignment,
582 * corresponding to the UCAL_DAY_OF_WEEK_IN_MONTH field.
585 UDAT_DAY_OF_WEEK_IN_MONTH_FIELD
= 11,
588 * FieldPosition and UFieldPosition selector for 'w' field alignment,
589 * corresponding to the UCAL_WEEK_OF_YEAR field.
592 UDAT_WEEK_OF_YEAR_FIELD
= 12,
595 * FieldPosition and UFieldPosition selector for 'W' field alignment,
596 * corresponding to the UCAL_WEEK_OF_MONTH field.
599 UDAT_WEEK_OF_MONTH_FIELD
= 13,
602 * FieldPosition and UFieldPosition selector for 'a' field alignment,
603 * corresponding to the UCAL_AM_PM field.
606 UDAT_AM_PM_FIELD
= 14,
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.
615 UDAT_HOUR1_FIELD
= 15,
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.
624 UDAT_HOUR0_FIELD
= 16,
627 * FieldPosition and UFieldPosition selector for 'z' field alignment,
628 * corresponding to the UCAL_ZONE_OFFSET and
629 * UCAL_DST_OFFSET fields.
632 UDAT_TIMEZONE_FIELD
= 17,
635 * FieldPosition and UFieldPosition selector for 'Y' field alignment,
636 * corresponding to the UCAL_YEAR_WOY field.
639 UDAT_YEAR_WOY_FIELD
= 18,
642 * FieldPosition and UFieldPosition selector for 'e' field alignment,
643 * corresponding to the UCAL_DOW_LOCAL field.
646 UDAT_DOW_LOCAL_FIELD
= 19,
649 * FieldPosition and UFieldPosition selector for 'u' field alignment,
650 * corresponding to the UCAL_EXTENDED_YEAR field.
653 UDAT_EXTENDED_YEAR_FIELD
= 20,
656 * FieldPosition and UFieldPosition selector for 'g' field alignment,
657 * corresponding to the UCAL_JULIAN_DAY field.
660 UDAT_JULIAN_DAY_FIELD
= 21,
663 * FieldPosition and UFieldPosition selector for 'A' field alignment,
664 * corresponding to the UCAL_MILLISECONDS_IN_DAY field.
667 UDAT_MILLISECONDS_IN_DAY_FIELD
= 22,
670 * FieldPosition and UFieldPosition selector for 'Z' field alignment,
671 * corresponding to the UCAL_ZONE_OFFSET and
672 * UCAL_DST_OFFSET fields.
675 UDAT_TIMEZONE_RFC_FIELD
= 23,
678 * FieldPosition and UFieldPosition selector for 'v' field alignment,
679 * corresponding to the UCAL_ZONE_OFFSET field.
682 UDAT_TIMEZONE_GENERIC_FIELD
= 24,
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.
689 UDAT_STANDALONE_DAY_FIELD
= 25,
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.
697 UDAT_STANDALONE_MONTH_FIELD
= 26,
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.
706 UDAT_QUARTER_FIELD
= 27,
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.
715 UDAT_STANDALONE_QUARTER_FIELD
= 28,
718 * FieldPosition and UFieldPosition selector for 'V' field alignment,
719 * corresponding to the UCAL_ZONE_OFFSET field.
722 UDAT_TIMEZONE_SPECIAL_FIELD
= 29,
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.
731 UDAT_YEAR_NAME_FIELD
= 30,
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.
739 UDAT_TIMEZONE_LOCALIZED_GMT_OFFSET_FIELD
= 31,
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").
747 UDAT_TIMEZONE_ISO_FIELD
= 32,
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.
755 UDAT_TIMEZONE_ISO_LOCAL_FIELD
= 33,
757 #ifndef U_HIDE_INTERNAL_API
759 * FieldPosition and UFieldPosition selector for 'r' field alignment,
760 * no directly corresponding UCAL_ field.
763 UDAT_RELATED_YEAR_FIELD
= 34,
764 #endif /* U_HIDE_INTERNAL_API */
767 * FieldPosition selector for 'b' field alignment.
768 * Displays midnight and noon for 12am and 12pm, respectively, if available;
769 * otherwise fall back to AM / PM.
772 UDAT_AM_PM_MIDNIGHT_NOON_FIELD
= 35,
774 /* FieldPosition selector for 'B' field alignment.
775 * Displays flexible day periods, such as "in the morning", if available.
778 UDAT_FLEXIBLE_DAY_PERIOD_FIELD
= 36,
780 #ifndef U_HIDE_INTERNAL_API
782 * FieldPosition and UFieldPosition selector for time separator,
783 * no corresponding UCAL_ field. No pattern character is currently
787 UDAT_TIME_SEPARATOR_FIELD
= 37,
788 #endif /* U_HIDE_INTERNAL_API */
790 #ifndef U_HIDE_DEPRECATED_API
792 * Number of FieldPosition and UFieldPosition selectors for
793 * DateFormat and UDateFormat.
794 * Valid selectors range from 0 to UDAT_FIELD_COUNT-1.
795 * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
797 UDAT_FIELD_COUNT
= 38
798 #endif /* U_HIDE_DEPRECATED_API */
802 #ifndef U_HIDE_INTERNAL_API
804 * Is a pattern character defined for UDAT_TIME_SEPARATOR_FIELD?
805 * In ICU 55 it was COLON, but that was withdrawn in ICU 56.
808 #define UDAT_HAS_PATTERN_CHAR_FOR_TIME_SEPARATOR 0
809 #endif /* U_HIDE_INTERNAL_API */
813 * Maps from a UDateFormatField to the corresponding UCalendarDateFields.
814 * Note: since the mapping is many-to-one, there is no inverse mapping.
815 * @param field the UDateFormatField.
816 * @return the UCalendarDateField. This will be UCAL_FIELD_COUNT in case
817 * of error (e.g., the input field is UDAT_FIELD_COUNT).
820 U_CAPI UCalendarDateFields U_EXPORT2
821 udat_toCalendarDateField(UDateFormatField field
);
825 * Open a new UDateFormat for formatting and parsing dates and times.
826 * A UDateFormat may be used to format dates in calls to {@link #udat_format },
827 * and to parse dates in calls to {@link #udat_parse }.
828 * @param timeStyle The style used to format times; one of UDAT_FULL, UDAT_LONG,
829 * UDAT_MEDIUM, UDAT_SHORT, UDAT_DEFAULT, or UDAT_NONE (relative time styles
830 * are not currently supported).
831 * When the pattern parameter is used, pass in UDAT_PATTERN for both timeStyle and dateStyle.
832 * @param dateStyle The style used to format dates; one of UDAT_FULL, UDAT_LONG,
833 * UDAT_MEDIUM, UDAT_SHORT, UDAT_DEFAULT, UDAT_FULL_RELATIVE, UDAT_LONG_RELATIVE,
834 * UDAT_MEDIUM_RELATIVE, UDAT_SHORT_RELATIVE, or UDAT_NONE.
835 * When the pattern parameter is used, pass in UDAT_PATTERN for both timeStyle and dateStyle.
836 * As currently implemented,
837 * relative date formatting only affects a limited range of calendar days before or
838 * after the current date, based on the CLDR <field type="day">/<relative> data: For
839 * example, in English, "Yesterday", "Today", and "Tomorrow". Outside of this range,
840 * dates are formatted using the corresponding non-relative style.
841 * @param locale The locale specifying the formatting conventions
842 * @param tzID A timezone ID specifying the timezone to use. If 0, use
843 * the default timezone.
844 * @param tzIDLength The length of tzID, or -1 if null-terminated.
845 * @param pattern A pattern specifying the format to use.
846 * @param patternLength The number of characters in the pattern, or -1 if null-terminated.
847 * @param status A pointer to an UErrorCode to receive any errors
848 * @return A pointer to a UDateFormat to use for formatting dates and times, or 0 if
852 U_CAPI UDateFormat
* U_EXPORT2
853 udat_open(UDateFormatStyle timeStyle
,
854 UDateFormatStyle dateStyle
,
858 const UChar
*pattern
,
859 int32_t patternLength
,
864 * Close a UDateFormat.
865 * Once closed, a UDateFormat may no longer be used.
866 * @param format The formatter to close.
869 U_CAPI
void U_EXPORT2
870 udat_close(UDateFormat
* format
);
874 * DateFormat boolean attributes
878 typedef enum UDateFormatBooleanAttribute
{
880 * indicates whether whitespace is allowed. Includes trailing dot tolerance.
883 UDAT_PARSE_ALLOW_WHITESPACE
= 0,
885 * indicates tolerance of numeric data when String data may be assumed. eg: UDAT_YEAR_NAME_FIELD,
886 * UDAT_STANDALONE_MONTH_FIELD, UDAT_DAY_OF_WEEK_FIELD
889 UDAT_PARSE_ALLOW_NUMERIC
= 1,
891 * indicates tolerance of a partial literal match
892 * e.g. accepting "--mon-02-march-2011" for a pattern of "'--: 'EEE-WW-MMMM-yyyy"
895 UDAT_PARSE_PARTIAL_LITERAL_MATCH
= 2,
897 * indicates tolerance of pattern mismatch between input data and specified format pattern.
898 * e.g. accepting "September" for a month pattern of MMM ("Sep")
901 UDAT_PARSE_MULTIPLE_PATTERNS_FOR_MATCH
= 3,
903 /* Do not conditionalize the following with #ifndef U_HIDE_DEPRECATED_API,
904 * it is needed for layout of DateFormat object. */
906 * One more than the highest normal UDateFormatBooleanAttribute value.
907 * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
909 UDAT_BOOLEAN_ATTRIBUTE_COUNT
= 4
910 } UDateFormatBooleanAttribute
;
913 * Get a boolean attribute associated with a UDateFormat.
914 * An example would be a true value for a key of UDAT_PARSE_ALLOW_WHITESPACE indicating allowing whitespace leniency.
915 * If the formatter does not understand the attribute, -1 is returned.
916 * @param fmt The formatter to query.
917 * @param attr The attribute to query; e.g. UDAT_PARSE_ALLOW_WHITESPACE.
918 * @param status A pointer to an UErrorCode to receive any errors
919 * @return The value of attr.
922 U_CAPI UBool U_EXPORT2
923 udat_getBooleanAttribute(const UDateFormat
* fmt
, UDateFormatBooleanAttribute attr
, UErrorCode
* status
);
926 * Set a boolean attribute associated with a UDateFormat.
927 * An example of a boolean attribute is parse leniency control. If the formatter does not understand
928 * the attribute, the call is ignored.
929 * @param fmt The formatter to set.
930 * @param attr The attribute to set; one of UDAT_PARSE_ALLOW_WHITESPACE or UDAT_PARSE_ALLOW_NUMERIC
931 * @param newValue The new value of attr.
932 * @param status A pointer to an UErrorCode to receive any errors
935 U_CAPI
void U_EXPORT2
936 udat_setBooleanAttribute(UDateFormat
*fmt
, UDateFormatBooleanAttribute attr
, UBool newValue
, UErrorCode
* status
);
940 #if U_SHOW_CPLUSPLUS_API
945 * \class LocalUDateFormatPointer
946 * "Smart pointer" class, closes a UDateFormat via udat_close().
947 * For most methods see the LocalPointerBase base class.
949 * @see LocalPointerBase
953 U_DEFINE_LOCAL_OPEN_POINTER(LocalUDateFormatPointer
, UDateFormat
, udat_close
);
957 #endif // U_SHOW_CPLUSPLUS_API
960 * Open a copy of a UDateFormat.
961 * This function performs a deep copy.
962 * @param fmt The format to copy
963 * @param status A pointer to an UErrorCode to receive any errors.
964 * @return A pointer to a UDateFormat identical to fmt.
967 U_CAPI UDateFormat
* U_EXPORT2
968 udat_clone(const UDateFormat
*fmt
,
972 * Format a date using a UDateFormat.
973 * The date will be formatted using the conventions specified in {@link #udat_open }
974 * @param format The formatter to use
975 * @param dateToFormat The date to format
976 * @param result A pointer to a buffer to receive the formatted number.
977 * @param resultLength The maximum size of result.
978 * @param position A pointer to a UFieldPosition. On input, position->field
979 * is read. On output, position->beginIndex and position->endIndex indicate
980 * the beginning and ending indices of field number position->field, if such
981 * a field exists. This parameter may be NULL, in which case no field
982 * position data is returned.
983 * @param status A pointer to an UErrorCode to receive any errors
984 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
986 * @see UFieldPosition
989 U_CAPI
int32_t U_EXPORT2
990 udat_format( const UDateFormat
* format
,
993 int32_t resultLength
,
994 UFieldPosition
* position
,
998 * Format a date using an UDateFormat.
999 * The date will be formatted using the conventions specified in {@link #udat_open }
1000 * @param format The formatter to use
1001 * @param calendar The calendar to format. The calendar instance might be
1002 * mutated if fields are not yet fully calculated, though
1003 * the function won't change the logical date and time held
1005 * @param result A pointer to a buffer to receive the formatted number.
1006 * @param capacity The maximum size of result.
1007 * @param position A pointer to a UFieldPosition. On input, position->field
1008 * is read. On output, position->beginIndex and position->endIndex indicate
1009 * the beginning and ending indices of field number position->field, if such
1010 * a field exists. This parameter may be NULL, in which case no field
1011 * position data is returned.
1012 * @param status A pointer to an UErrorCode to receive any errors
1013 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
1015 * @see udat_parseCalendar
1016 * @see UFieldPosition
1019 U_CAPI
int32_t U_EXPORT2
1020 udat_formatCalendar( const UDateFormat
* format
,
1021 UCalendar
* calendar
,
1024 UFieldPosition
* position
,
1025 UErrorCode
* status
);
1028 * Format a date using a UDateFormat.
1029 * The date will be formatted using the conventions specified in {@link #udat_open}
1031 * The formatter to use
1032 * @param dateToFormat
1033 * The date to format
1035 * A pointer to a buffer to receive the formatted number.
1036 * @param resultLength
1037 * The maximum size of result.
1039 * A pointer to a UFieldPositionIterator created by {@link #ufieldpositer_open}
1040 * (may be NULL if field position information is not needed). Any
1041 * iteration information already present in the UFieldPositionIterator
1042 * will be deleted, and the iterator will be reset to apply to the
1043 * fields in the formatted string created by this function call; the
1044 * field values provided by {@link #ufieldpositer_next} will be from the
1045 * UDateFormatField enum.
1047 * A pointer to a UErrorCode to receive any errors
1049 * The total buffer size needed; if greater than resultLength, the output was truncated.
1051 * @see UFieldPositionIterator
1054 U_CAPI
int32_t U_EXPORT2
1055 udat_formatForFields( const UDateFormat
* format
,
1058 int32_t resultLength
,
1059 UFieldPositionIterator
* fpositer
,
1060 UErrorCode
* status
);
1063 * Format a date using a UDateFormat.
1064 * The date will be formatted using the conventions specified in {@link #udat_open }
1066 * The formatter to use
1068 * The calendar to format. The calendar instance might be mutated if fields
1069 * are not yet fully calculated, though the function won't change the logical
1070 * date and time held by the instance.
1072 * A pointer to a buffer to receive the formatted number.
1074 * The maximum size of result.
1076 * A pointer to a UFieldPositionIterator created by {@link #ufieldpositer_open}
1077 * (may be NULL if field position information is not needed). Any
1078 * iteration information already present in the UFieldPositionIterator
1079 * will be deleted, and the iterator will be reset to apply to the
1080 * fields in the formatted string created by this function call; the
1081 * field values provided by {@link #ufieldpositer_next} will be from the
1082 * UDateFormatField enum.
1084 * A pointer to a UErrorCode to receive any errors
1086 * The total buffer size needed; if greater than resultLength, the output was truncated.
1088 * @see udat_parseCalendar
1089 * @see UFieldPositionIterator
1092 U_CAPI
int32_t U_EXPORT2
1093 udat_formatCalendarForFields( const UDateFormat
* format
,
1094 UCalendar
* calendar
,
1097 UFieldPositionIterator
* fpositer
,
1098 UErrorCode
* status
);
1102 * Parse a string into an date/time using a UDateFormat.
1103 * The date will be parsed using the conventions specified in {@link #udat_open }.
1105 * Note that the normal date formats associated with some calendars - such
1106 * as the Chinese lunar calendar - do not specify enough fields to enable
1107 * dates to be parsed unambiguously. In the case of the Chinese lunar
1108 * calendar, while the year within the current 60-year cycle is specified,
1109 * the number of such cycles since the start date of the calendar (in the
1110 * UCAL_ERA field of the UCalendar object) is not normally part of the format,
1111 * and parsing may assume the wrong era. For cases such as this it is
1112 * recommended that clients parse using udat_parseCalendar with the UCalendar
1113 * passed in set to the current date, or to a date within the era/cycle that
1114 * should be assumed if absent in the format.
1116 * @param format The formatter to use.
1117 * @param text The text to parse.
1118 * @param textLength The length of text, or -1 if null-terminated.
1119 * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which
1120 * to begin parsing. If not 0, on output the offset at which parsing ended.
1121 * @param status A pointer to an UErrorCode to receive any errors
1122 * @return The value of the parsed date/time
1126 U_CAPI UDate U_EXPORT2
1127 udat_parse(const UDateFormat
* format
,
1131 UErrorCode
*status
);
1134 * Parse a string into an date/time using a UDateFormat.
1135 * The date will be parsed using the conventions specified in {@link #udat_open }.
1136 * @param format The formatter to use.
1137 * @param calendar A calendar set on input to the date and time to be used for
1138 * missing values in the date/time string being parsed, and set
1139 * on output to the parsed date/time. When the calendar type is
1140 * different from the internal calendar held by the UDateFormat
1141 * instance, the internal calendar will be cloned to a work
1142 * calendar set to the same milliseconds and time zone as this
1143 * calendar parameter, field values will be parsed based on the
1144 * work calendar, then the result (milliseconds and time zone)
1145 * will be set in this calendar.
1146 * @param text The text to parse.
1147 * @param textLength The length of text, or -1 if null-terminated.
1148 * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which
1149 * to begin parsing. If not 0, on output the offset at which parsing ended.
1150 * @param status A pointer to an UErrorCode to receive any errors
1154 U_CAPI
void U_EXPORT2
1155 udat_parseCalendar(const UDateFormat
* format
,
1156 UCalendar
* calendar
,
1160 UErrorCode
*status
);
1163 * Determine if an UDateFormat will perform lenient parsing.
1164 * With lenient parsing, the parser may use heuristics to interpret inputs that do not
1165 * precisely match the pattern. With strict parsing, inputs must match the pattern.
1166 * @param fmt The formatter to query
1167 * @return TRUE if fmt is set to perform lenient parsing, FALSE otherwise.
1168 * @see udat_setLenient
1171 U_CAPI UBool U_EXPORT2
1172 udat_isLenient(const UDateFormat
* fmt
);
1175 * Specify whether an UDateFormat will perform lenient parsing.
1176 * With lenient parsing, the parser may use heuristics to interpret inputs that do not
1177 * precisely match the pattern. With strict parsing, inputs must match the pattern.
1178 * @param fmt The formatter to set
1179 * @param isLenient TRUE if fmt should perform lenient parsing, FALSE otherwise.
1180 * @see dat_isLenient
1183 U_CAPI
void U_EXPORT2
1184 udat_setLenient( UDateFormat
* fmt
,
1188 * Get the UCalendar associated with an UDateFormat.
1189 * A UDateFormat uses a UCalendar to convert a raw value to, for example,
1190 * the day of the week.
1191 * @param fmt The formatter to query.
1192 * @return A pointer to the UCalendar used by fmt.
1193 * @see udat_setCalendar
1196 U_CAPI
const UCalendar
* U_EXPORT2
1197 udat_getCalendar(const UDateFormat
* fmt
);
1200 * Set the UCalendar associated with an UDateFormat.
1201 * A UDateFormat uses a UCalendar to convert a raw value to, for example,
1202 * the day of the week.
1203 * @param fmt The formatter to set.
1204 * @param calendarToSet A pointer to an UCalendar to be used by fmt.
1205 * @see udat_setCalendar
1208 U_CAPI
void U_EXPORT2
1209 udat_setCalendar( UDateFormat
* fmt
,
1210 const UCalendar
* calendarToSet
);
1213 * Get the UNumberFormat associated with an UDateFormat.
1214 * A UDateFormat uses a UNumberFormat to format numbers within a date,
1215 * for example the day number.
1216 * @param fmt The formatter to query.
1217 * @return A pointer to the UNumberFormat used by fmt to format numbers.
1218 * @see udat_setNumberFormat
1221 U_CAPI
const UNumberFormat
* U_EXPORT2
1222 udat_getNumberFormat(const UDateFormat
* fmt
);
1225 * Get the UNumberFormat for specific field associated with an UDateFormat.
1226 * For example: 'y' for year and 'M' for month
1227 * @param fmt The formatter to query.
1228 * @param field the field to query
1229 * @return A pointer to the UNumberFormat used by fmt to format field numbers.
1230 * @see udat_setNumberFormatForField
1233 U_CAPI
const UNumberFormat
* U_EXPORT2
1234 udat_getNumberFormatForField(const UDateFormat
* fmt
, UChar field
);
1237 * Set the UNumberFormat for specific field associated with an UDateFormat.
1238 * It can be a single field like: "y"(year) or "M"(month)
1239 * It can be several field combined together: "yM"(year and month)
1241 * 1 symbol field is enough for multiple symbol field (so "y" will override "yy", "yyy")
1242 * If the field is not numeric, then override has no effect (like "MMM" will use abbreviation, not numerical field)
1244 * @param fields the fields to set
1245 * @param fmt The formatter to set.
1246 * @param numberFormatToSet A pointer to the UNumberFormat to be used by fmt to format numbers.
1247 * @param status error code passed around (memory allocation or invalid fields)
1248 * @see udat_getNumberFormatForField
1251 U_CAPI
void U_EXPORT2
1252 udat_adoptNumberFormatForFields( UDateFormat
* fmt
,
1253 const UChar
* fields
,
1254 UNumberFormat
* numberFormatToSet
,
1255 UErrorCode
* status
);
1257 * Set the UNumberFormat associated with an UDateFormat.
1258 * A UDateFormat uses a UNumberFormat to format numbers within a date,
1259 * for example the day number.
1260 * This method also clears per field NumberFormat instances previously
1261 * set by {@see udat_setNumberFormatForField}
1262 * @param fmt The formatter to set.
1263 * @param numberFormatToSet A pointer to the UNumberFormat to be used by fmt to format numbers.
1264 * @see udat_getNumberFormat
1265 * @see udat_setNumberFormatForField
1268 U_CAPI
void U_EXPORT2
1269 udat_setNumberFormat( UDateFormat
* fmt
,
1270 const UNumberFormat
* numberFormatToSet
);
1272 * Adopt the UNumberFormat associated with an UDateFormat.
1273 * A UDateFormat uses a UNumberFormat to format numbers within a date,
1274 * for example the day number.
1275 * @param fmt The formatter to set.
1276 * @param numberFormatToAdopt A pointer to the UNumberFormat to be used by fmt to format numbers.
1277 * @see udat_getNumberFormat
1280 U_CAPI
void U_EXPORT2
1281 udat_adoptNumberFormat( UDateFormat
* fmt
,
1282 UNumberFormat
* numberFormatToAdopt
);
1284 * Get a locale for which date/time formatting patterns are available.
1285 * A UDateFormat in a locale returned by this function will perform the correct
1286 * formatting and parsing for the locale.
1287 * @param localeIndex The index of the desired locale.
1288 * @return A locale for which date/time formatting patterns are available, or 0 if none.
1289 * @see udat_countAvailable
1292 U_CAPI
const char* U_EXPORT2
1293 udat_getAvailable(int32_t localeIndex
);
1296 * Determine how many locales have date/time formatting patterns available.
1297 * This function is most useful as determining the loop ending condition for
1298 * calls to {@link #udat_getAvailable }.
1299 * @return The number of locales for which date/time formatting patterns are available.
1300 * @see udat_getAvailable
1303 U_CAPI
int32_t U_EXPORT2
1304 udat_countAvailable(void);
1307 * Get the year relative to which all 2-digit years are interpreted.
1308 * For example, if the 2-digit start year is 2100, the year 99 will be
1309 * interpreted as 2199.
1310 * @param fmt The formatter to query.
1311 * @param status A pointer to an UErrorCode to receive any errors
1312 * @return The year relative to which all 2-digit years are interpreted.
1313 * @see udat_Set2DigitYearStart
1316 U_CAPI UDate U_EXPORT2
1317 udat_get2DigitYearStart( const UDateFormat
*fmt
,
1318 UErrorCode
*status
);
1321 * Set the year relative to which all 2-digit years will be interpreted.
1322 * For example, if the 2-digit start year is 2100, the year 99 will be
1323 * interpreted as 2199.
1324 * @param fmt The formatter to set.
1325 * @param d The year relative to which all 2-digit years will be interpreted.
1326 * @param status A pointer to an UErrorCode to receive any errors
1327 * @see udat_Set2DigitYearStart
1330 U_CAPI
void U_EXPORT2
1331 udat_set2DigitYearStart( UDateFormat
*fmt
,
1333 UErrorCode
*status
);
1336 * Extract the pattern from a UDateFormat.
1337 * The pattern will follow the pattern syntax rules.
1338 * @param fmt The formatter to query.
1339 * @param localized TRUE if the pattern should be localized, FALSE otherwise.
1340 * @param result A pointer to a buffer to receive the pattern.
1341 * @param resultLength The maximum size of result.
1342 * @param status A pointer to an UErrorCode to receive any errors
1343 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
1344 * @see udat_applyPattern
1347 U_CAPI
int32_t U_EXPORT2
1348 udat_toPattern( const UDateFormat
*fmt
,
1351 int32_t resultLength
,
1352 UErrorCode
*status
);
1355 * Set the pattern used by an UDateFormat.
1356 * The pattern should follow the pattern syntax rules.
1357 * @param format The formatter to set.
1358 * @param localized TRUE if the pattern is localized, FALSE otherwise.
1359 * @param pattern The new pattern
1360 * @param patternLength The length of pattern, or -1 if null-terminated.
1361 * @see udat_toPattern
1364 U_CAPI
void U_EXPORT2
1365 udat_applyPattern( UDateFormat
*format
,
1367 const UChar
*pattern
,
1368 int32_t patternLength
);
1371 * The possible types of date format symbols
1374 typedef enum UDateFormatSymbolType
{
1375 /** The era names, for example AD */
1377 /** The month names, for example February */
1379 /** The short month names, for example Feb. */
1381 /** The CLDR-style format "wide" weekday names, for example Monday */
1384 * The CLDR-style format "abbreviated" (not "short") weekday names, for example "Mon."
1385 * For the CLDR-style format "short" weekday names, use UDAT_SHORTER_WEEKDAYS.
1387 UDAT_SHORT_WEEKDAYS
,
1388 /** The AM/PM names, for example AM */
1390 /** The localized characters */
1391 UDAT_LOCALIZED_CHARS
,
1392 /** The long era names, for example Anno Domini */
1394 /** The narrow month names, for example F */
1396 /** The CLDR-style format "narrow" weekday names, for example "M" */
1397 UDAT_NARROW_WEEKDAYS
,
1398 /** Standalone context versions of months */
1399 UDAT_STANDALONE_MONTHS
,
1400 UDAT_STANDALONE_SHORT_MONTHS
,
1401 UDAT_STANDALONE_NARROW_MONTHS
,
1402 /** The CLDR-style stand-alone "wide" weekday names */
1403 UDAT_STANDALONE_WEEKDAYS
,
1405 * The CLDR-style stand-alone "abbreviated" (not "short") weekday names.
1406 * For the CLDR-style stand-alone "short" weekday names, use UDAT_STANDALONE_SHORTER_WEEKDAYS.
1408 UDAT_STANDALONE_SHORT_WEEKDAYS
,
1409 /** The CLDR-style stand-alone "narrow" weekday names */
1410 UDAT_STANDALONE_NARROW_WEEKDAYS
,
1411 /** The quarters, for example 1st Quarter */
1413 /** The short quarter names, for example Q1 */
1414 UDAT_SHORT_QUARTERS
,
1415 /** Standalone context versions of quarters */
1416 UDAT_STANDALONE_QUARTERS
,
1417 UDAT_STANDALONE_SHORT_QUARTERS
,
1419 * The CLDR-style short weekday names, e.g. "Su", Mo", etc.
1420 * These are named "SHORTER" to contrast with the constants using _SHORT_
1421 * above, which actually get the CLDR-style *abbreviated* versions of the
1422 * corresponding names.
1425 UDAT_SHORTER_WEEKDAYS
,
1427 * Standalone version of UDAT_SHORTER_WEEKDAYS.
1430 UDAT_STANDALONE_SHORTER_WEEKDAYS
,
1432 * Cyclic year names (only supported for some calendars, and only for FORMAT usage;
1433 * udat_setSymbols not supported for UDAT_CYCLIC_YEARS_WIDE)
1436 UDAT_CYCLIC_YEARS_WIDE
,
1438 * Cyclic year names (only supported for some calendars, and only for FORMAT usage)
1441 UDAT_CYCLIC_YEARS_ABBREVIATED
,
1443 * Cyclic year names (only supported for some calendars, and only for FORMAT usage;
1444 * udat_setSymbols not supported for UDAT_CYCLIC_YEARS_NARROW)
1447 UDAT_CYCLIC_YEARS_NARROW
,
1449 * Calendar zodiac names (only supported for some calendars, and only for FORMAT usage;
1450 * udat_setSymbols not supported for UDAT_ZODIAC_NAMES_WIDE)
1453 UDAT_ZODIAC_NAMES_WIDE
,
1455 * Calendar zodiac names (only supported for some calendars, and only for FORMAT usage)
1458 UDAT_ZODIAC_NAMES_ABBREVIATED
,
1460 * Calendar zodiac names (only supported for some calendars, and only for FORMAT usage;
1461 * udat_setSymbols not supported for UDAT_ZODIAC_NAMES_NARROW)
1464 UDAT_ZODIAC_NAMES_NARROW
1465 #ifndef U_HIDE_INTERNAL_API
1469 * only for udat_getSymbols.
1470 * no directly corresponding UCAL_ field.
1473 UADAT_CYCLIC_ZODIAC_NAMES
= 128
1474 #endif /* U_HIDE_INTERNAL_API */
1475 } UDateFormatSymbolType
;
1477 struct UDateFormatSymbols
;
1478 /** Date format symbols.
1479 * For usage in C programs.
1482 typedef struct UDateFormatSymbols UDateFormatSymbols
;
1485 * Get the symbols associated with an UDateFormat.
1486 * The symbols are what a UDateFormat uses to represent locale-specific data,
1487 * for example month or day names.
1488 * @param fmt The formatter to query.
1489 * @param type The type of symbols to get. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS,
1490 * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS
1491 * @param symbolIndex The desired symbol of type type.
1492 * @param result A pointer to a buffer to receive the pattern.
1493 * @param resultLength The maximum size of result.
1494 * @param status A pointer to an UErrorCode to receive any errors
1495 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
1496 * @see udat_countSymbols
1497 * @see udat_setSymbols
1500 U_CAPI
int32_t U_EXPORT2
1501 udat_getSymbols(const UDateFormat
*fmt
,
1502 UDateFormatSymbolType type
,
1503 int32_t symbolIndex
,
1505 int32_t resultLength
,
1506 UErrorCode
*status
);
1509 * Count the number of particular symbols for an UDateFormat.
1510 * This function is most useful as for detemining the loop termination condition
1511 * for calls to {@link #udat_getSymbols }.
1512 * @param fmt The formatter to query.
1513 * @param type The type of symbols to count. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS,
1514 * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS
1515 * @return The number of symbols of type type.
1516 * @see udat_getSymbols
1517 * @see udat_setSymbols
1520 U_CAPI
int32_t U_EXPORT2
1521 udat_countSymbols( const UDateFormat
*fmt
,
1522 UDateFormatSymbolType type
);
1525 * Set the symbols associated with an UDateFormat.
1526 * The symbols are what a UDateFormat uses to represent locale-specific data,
1527 * for example month or day names.
1528 * @param format The formatter to set
1529 * @param type The type of symbols to set. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS,
1530 * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS
1531 * @param symbolIndex The index of the symbol to set of type type.
1532 * @param value The new value
1533 * @param valueLength The length of value, or -1 if null-terminated
1534 * @param status A pointer to an UErrorCode to receive any errors
1535 * @see udat_getSymbols
1536 * @see udat_countSymbols
1539 U_CAPI
void U_EXPORT2
1540 udat_setSymbols( UDateFormat
*format
,
1541 UDateFormatSymbolType type
,
1542 int32_t symbolIndex
,
1544 int32_t valueLength
,
1545 UErrorCode
*status
);
1548 * Get the locale for this date format object.
1549 * You can choose between valid and actual locale.
1550 * @param fmt The formatter to get the locale from
1551 * @param type type of the locale we're looking for (valid or actual)
1552 * @param status error code for the operation
1553 * @return the locale name
1556 U_CAPI
const char* U_EXPORT2
1557 udat_getLocaleByType(const UDateFormat
*fmt
,
1558 ULocDataLocaleType type
,
1559 UErrorCode
* status
);
1562 * Set a particular UDisplayContext value in the formatter, such as
1563 * UDISPCTX_CAPITALIZATION_FOR_STANDALONE.
1564 * @param fmt The formatter for which to set a UDisplayContext value.
1565 * @param value The UDisplayContext value to set.
1566 * @param status A pointer to an UErrorCode to receive any errors
1569 U_CAPI
void U_EXPORT2
1570 udat_setContext(UDateFormat
* fmt
, UDisplayContext value
, UErrorCode
* status
);
1573 * Get the formatter's UDisplayContext value for the specified UDisplayContextType,
1574 * such as UDISPCTX_TYPE_CAPITALIZATION.
1575 * @param fmt The formatter to query.
1576 * @param type The UDisplayContextType whose value to return
1577 * @param status A pointer to an UErrorCode to receive any errors
1578 * @return The UDisplayContextValue for the specified type.
1581 U_CAPI UDisplayContext U_EXPORT2
1582 udat_getContext(const UDateFormat
* fmt
, UDisplayContextType type
, UErrorCode
* status
);
1584 #ifndef U_HIDE_INTERNAL_API
1586 * Extract the date pattern from a UDateFormat set for relative date formatting.
1587 * The pattern will follow the pattern syntax rules.
1588 * @param fmt The formatter to query.
1589 * @param result A pointer to a buffer to receive the pattern.
1590 * @param resultLength The maximum size of result.
1591 * @param status A pointer to a UErrorCode to receive any errors
1592 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
1593 * @see udat_applyPatternRelative
1594 * @internal ICU 4.2 technology preview
1596 U_INTERNAL
int32_t U_EXPORT2
1597 udat_toPatternRelativeDate(const UDateFormat
*fmt
,
1599 int32_t resultLength
,
1600 UErrorCode
*status
);
1603 * Extract the time pattern from a UDateFormat set for relative date formatting.
1604 * The pattern will follow the pattern syntax rules.
1605 * @param fmt The formatter to query.
1606 * @param result A pointer to a buffer to receive the pattern.
1607 * @param resultLength The maximum size of result.
1608 * @param status A pointer to a UErrorCode to receive any errors
1609 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
1610 * @see udat_applyPatternRelative
1611 * @internal ICU 4.2 technology preview
1613 U_INTERNAL
int32_t U_EXPORT2
1614 udat_toPatternRelativeTime(const UDateFormat
*fmt
,
1616 int32_t resultLength
,
1617 UErrorCode
*status
);
1620 * Set the date & time patterns used by a UDateFormat set for relative date formatting.
1621 * The patterns should follow the pattern syntax rules.
1622 * @param format The formatter to set.
1623 * @param datePattern The new date pattern
1624 * @param datePatternLength The length of datePattern, or -1 if null-terminated.
1625 * @param timePattern The new time pattern
1626 * @param timePatternLength The length of timePattern, or -1 if null-terminated.
1627 * @param status A pointer to a UErrorCode to receive any errors
1628 * @see udat_toPatternRelativeDate, udat_toPatternRelativeTime
1629 * @internal ICU 4.2 technology preview
1631 U_INTERNAL
void U_EXPORT2
1632 udat_applyPatternRelative(UDateFormat
*format
,
1633 const UChar
*datePattern
,
1634 int32_t datePatternLength
,
1635 const UChar
*timePattern
,
1636 int32_t timePatternLength
,
1637 UErrorCode
*status
);
1643 typedef UDateFormat
* (U_EXPORT2
*UDateFormatOpener
) (UDateFormatStyle timeStyle
,
1644 UDateFormatStyle dateStyle
,
1648 const UChar
*pattern
,
1649 int32_t patternLength
,
1650 UErrorCode
*status
);
1653 * Register a provider factory
1656 U_INTERNAL
void U_EXPORT2
1657 udat_registerOpener(UDateFormatOpener opener
, UErrorCode
*status
);
1660 * Un-Register a provider factory
1663 U_INTERNAL UDateFormatOpener U_EXPORT2
1664 udat_unregisterOpener(UDateFormatOpener opener
, UErrorCode
*status
);
1665 #endif /* U_HIDE_INTERNAL_API */
1668 #endif /* #if !UCONFIG_NO_FORMATTING */