2 *******************************************************************************
3 * Copyright (C) 1996-2015, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 *******************************************************************************
11 #include "unicode/utypes.h"
13 #if !UCONFIG_NO_FORMATTING
15 #include "unicode/localpointer.h"
16 #include "unicode/ucal.h"
17 #include "unicode/unum.h"
18 #include "unicode/udisplaycontext.h"
19 #include "unicode/ufieldpositer.h"
22 * \brief C API: DateFormat
24 * <h2> Date Format C API</h2>
26 * Date Format C API consists of functions that convert dates and
27 * times from their internal representations to textual form and back again in a
28 * language-independent manner. Converting from the internal representation (milliseconds
29 * since midnight, January 1, 1970) to text is known as "formatting," and converting
30 * from text to millis is known as "parsing." We currently define only one concrete
31 * structure UDateFormat, which can handle pretty much all normal
32 * date formatting and parsing actions.
34 * Date Format helps you to format and parse dates for any locale. Your code can
35 * be completely independent of the locale conventions for months, days of the
36 * week, or even the calendar format: lunar vs. solar.
38 * To format a date for the current Locale with default time and date style,
39 * use one of the static factory methods:
42 * UErrorCode status = U_ZERO_ERROR;
44 * int32_t myStrlen = 0;
45 * UDateFormat* dfmt = udat_open(UDAT_DEFAULT, UDAT_DEFAULT, NULL, NULL, -1, NULL, -1, &status);
46 * myStrlen = udat_format(dfmt, myDate, NULL, myStrlen, NULL, &status);
47 * if (status==U_BUFFER_OVERFLOW_ERROR){
48 * status=U_ZERO_ERROR;
49 * myString=(UChar*)malloc(sizeof(UChar) * (myStrlen+1) );
50 * udat_format(dfmt, myDate, myString, myStrlen+1, NULL, &status);
54 * If you are formatting multiple numbers, it is more efficient to get the
55 * format and use it multiple times so that the system doesn't have to fetch the
56 * information about the local language and country conventions multiple times.
59 * UErrorCode status = U_ZERO_ERROR;
60 * int32_t i, myStrlen = 0;
63 * UDate myDateArr[] = { 0.0, 100000000.0, 2000000000.0 }; // test values
64 * UDateFormat* df = udat_open(UDAT_DEFAULT, UDAT_DEFAULT, NULL, NULL, -1, NULL, 0, &status);
65 * for (i = 0; i < 3; i++) {
66 * myStrlen = udat_format(df, myDateArr[i], NULL, myStrlen, NULL, &status);
67 * if(status == U_BUFFER_OVERFLOW_ERROR){
68 * status = U_ZERO_ERROR;
69 * myString = (UChar*)malloc(sizeof(UChar) * (myStrlen+1) );
70 * udat_format(df, myDateArr[i], myString, myStrlen+1, NULL, &status);
71 * printf("%s\n", u_austrcpy(buffer, myString) );
77 * To get specific fields of a date, you can use UFieldPosition to
78 * get specific fields.
81 * UErrorCode status = U_ZERO_ERROR;
84 * int32_t myStrlen = 0;
87 * pos.field = 1; // Same as the DateFormat::EField enum
88 * UDateFormat* dfmt = udat_open(UDAT_DEFAULT, UDAT_DEFAULT, NULL, -1, NULL, 0, &status);
89 * myStrlen = udat_format(dfmt, myDate, NULL, myStrlen, &pos, &status);
90 * if (status==U_BUFFER_OVERFLOW_ERROR){
91 * status=U_ZERO_ERROR;
92 * myString=(UChar*)malloc(sizeof(UChar) * (myStrlen+1) );
93 * udat_format(dfmt, myDate, myString, myStrlen+1, &pos, &status);
95 * printf("date format: %s\n", u_austrcpy(buffer, myString));
96 * buffer[pos.endIndex] = 0; // NULL terminate the string.
97 * printf("UFieldPosition position equals %s\n", &buffer[pos.beginIndex]);
100 * To format a date for a different Locale, specify it in the call to
104 * UDateFormat* df = udat_open(UDAT_SHORT, UDAT_SHORT, "fr_FR", NULL, -1, NULL, 0, &status);
107 * You can use a DateFormat API udat_parse() to parse.
110 * UErrorCode status = U_ZERO_ERROR;
111 * int32_t parsepos=0;
112 * UDate myDate = udat_parse(df, myString, u_strlen(myString), &parsepos, &status);
115 * You can pass in different options for the arguments for date and time style
116 * to control the length of the result; from SHORT to MEDIUM to LONG to FULL.
117 * The exact result depends on the locale, but generally:
118 * see UDateFormatStyle for more details
120 * <li> UDAT_SHORT is completely numeric, such as 12/13/52 or 3:30pm
121 * <li> UDAT_MEDIUM is longer, such as Jan 12, 1952
122 * <li> UDAT_LONG is longer, such as January 12, 1952 or 3:30:32pm
123 * <li> UDAT_FULL is pretty completely specified, such as
124 * Tuesday, April 12, 1952 AD or 3:30:42pm PST.
126 * You can also set the time zone on the format if you wish.
128 * You can also use forms of the parse and format methods with Parse Position and
129 * UFieldPosition to allow you to
131 * <li> Progressively parse through pieces of a string.
132 * <li> Align any particular field, or find out where it is for selection
135 * <p><strong>Date and Time Patterns:</strong></p>
137 * <p>Date and time formats are specified by <em>date and time pattern</em> strings.
138 * Within date and time pattern strings, all unquoted ASCII letters [A-Za-z] are reserved
139 * as pattern letters representing calendar fields. <code>UDateFormat</code> supports
140 * the date and time formatting algorithm and pattern letters defined by
141 * <a href="http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table">UTS#35
142 * Unicode Locale Data Markup Language (LDML)</a> and further documented for ICU in the
143 * <a href="https://sites.google.com/site/icuprojectuserguide/formatparse/datetime?pli=1#TOC-Date-Field-Symbol-Table">ICU
144 * User Guide</a>.</p>
147 /** A date formatter.
148 * For usage in C programs.
151 typedef void* UDateFormat
;
153 /** The possible date/time format styles
156 typedef enum UDateFormatStyle
{
166 UDAT_DEFAULT
= UDAT_MEDIUM
,
168 /** Bitfield for relative date */
169 UDAT_RELATIVE
= (1 << 7),
171 UDAT_FULL_RELATIVE
= UDAT_FULL
| UDAT_RELATIVE
,
173 UDAT_LONG_RELATIVE
= UDAT_LONG
| UDAT_RELATIVE
,
175 UDAT_MEDIUM_RELATIVE
= UDAT_MEDIUM
| UDAT_RELATIVE
,
177 UDAT_SHORT_RELATIVE
= UDAT_SHORT
| UDAT_RELATIVE
,
184 * Use the pattern given in the parameter to udat_open
190 #ifndef U_HIDE_INTERNAL_API
191 /** @internal alias to UDAT_PATTERN */
192 UDAT_IGNORE
= UDAT_PATTERN
193 #endif /* U_HIDE_INTERNAL_API */
196 /* Skeletons for dates. */
199 * Constant for date skeleton with year.
202 #define UDAT_YEAR "y"
204 * Constant for date skeleton with quarter.
207 #define UDAT_QUARTER "QQQQ"
209 * Constant for date skeleton with abbreviated quarter.
212 #define UDAT_ABBR_QUARTER "QQQ"
214 * Constant for date skeleton with year and quarter.
217 #define UDAT_YEAR_QUARTER "yQQQQ"
219 * Constant for date skeleton with year and abbreviated quarter.
222 #define UDAT_YEAR_ABBR_QUARTER "yQQQ"
224 * Constant for date skeleton with month.
227 #define UDAT_MONTH "MMMM"
229 * Constant for date skeleton with abbreviated month.
232 #define UDAT_ABBR_MONTH "MMM"
234 * Constant for date skeleton with numeric month.
237 #define UDAT_NUM_MONTH "M"
239 * Constant for date skeleton with year and month.
242 #define UDAT_YEAR_MONTH "yMMMM"
244 * Constant for date skeleton with year and abbreviated month.
247 #define UDAT_YEAR_ABBR_MONTH "yMMM"
249 * Constant for date skeleton with year and numeric month.
252 #define UDAT_YEAR_NUM_MONTH "yM"
254 * Constant for date skeleton with day.
259 * Constant for date skeleton with year, month, and day.
260 * Used in combinations date + time, date + time + zone, or time + zone.
263 #define UDAT_YEAR_MONTH_DAY "yMMMMd"
265 * Constant for date skeleton with year, abbreviated month, and day.
266 * Used in combinations date + time, date + time + zone, or time + zone.
269 #define UDAT_YEAR_ABBR_MONTH_DAY "yMMMd"
271 * Constant for date skeleton with year, numeric month, and day.
272 * Used in combinations date + time, date + time + zone, or time + zone.
275 #define UDAT_YEAR_NUM_MONTH_DAY "yMd"
277 * Constant for date skeleton with weekday.
280 #define UDAT_WEEKDAY "EEEE"
282 * Constant for date skeleton with abbreviated weekday.
285 #define UDAT_ABBR_WEEKDAY "E"
287 * Constant for date skeleton with year, month, weekday, and day.
288 * Used in combinations date + time, date + time + zone, or time + zone.
291 #define UDAT_YEAR_MONTH_WEEKDAY_DAY "yMMMMEEEEd"
293 * Constant for date skeleton with year, abbreviated month, weekday, and day.
294 * Used in combinations date + time, date + time + zone, or time + zone.
297 #define UDAT_YEAR_ABBR_MONTH_WEEKDAY_DAY "yMMMEd"
299 * Constant for date skeleton with year, numeric month, weekday, and day.
300 * Used in combinations date + time, date + time + zone, or time + zone.
303 #define UDAT_YEAR_NUM_MONTH_WEEKDAY_DAY "yMEd"
305 * Constant for date skeleton with long month and day.
306 * Used in combinations date + time, date + time + zone, or time + zone.
309 #define UDAT_MONTH_DAY "MMMMd"
311 * Constant for date skeleton with abbreviated month and day.
312 * Used in combinations date + time, date + time + zone, or time + zone.
315 #define UDAT_ABBR_MONTH_DAY "MMMd"
317 * Constant for date skeleton with numeric month and day.
318 * Used in combinations date + time, date + time + zone, or time + zone.
321 #define UDAT_NUM_MONTH_DAY "Md"
323 * Constant for date skeleton with month, weekday, and day.
324 * Used in combinations date + time, date + time + zone, or time + zone.
327 #define UDAT_MONTH_WEEKDAY_DAY "MMMMEEEEd"
329 * Constant for date skeleton with abbreviated month, weekday, and day.
330 * Used in combinations date + time, date + time + zone, or time + zone.
333 #define UDAT_ABBR_MONTH_WEEKDAY_DAY "MMMEd"
335 * Constant for date skeleton with numeric month, weekday, and day.
336 * Used in combinations date + time, date + time + zone, or time + zone.
339 #define UDAT_NUM_MONTH_WEEKDAY_DAY "MEd"
341 /* Skeletons for times. */
344 * Constant for date skeleton with hour, with the locale's preferred hour format (12 or 24).
347 #define UDAT_HOUR "j"
349 * Constant for date skeleton with hour in 24-hour presentation.
352 #define UDAT_HOUR24 "H"
354 * Constant for date skeleton with minute.
357 #define UDAT_MINUTE "m"
359 * Constant for date skeleton with hour and minute, with the locale's preferred hour format (12 or 24).
360 * Used in combinations date + time, date + time + zone, or time + zone.
363 #define UDAT_HOUR_MINUTE "jm"
365 * Constant for date skeleton with hour and minute in 24-hour presentation.
366 * Used in combinations date + time, date + time + zone, or time + zone.
369 #define UDAT_HOUR24_MINUTE "Hm"
371 * Constant for date skeleton with second.
374 #define UDAT_SECOND "s"
376 * Constant for date skeleton with hour, minute, and second,
377 * with the locale's preferred hour format (12 or 24).
378 * Used in combinations date + time, date + time + zone, or time + zone.
381 #define UDAT_HOUR_MINUTE_SECOND "jms"
383 * Constant for date skeleton with hour, minute, and second in
384 * 24-hour presentation.
385 * Used in combinations date + time, date + time + zone, or time + zone.
388 #define UDAT_HOUR24_MINUTE_SECOND "Hms"
390 * Constant for date skeleton with minute and second.
391 * Used in combinations date + time, date + time + zone, or time + zone.
394 #define UDAT_MINUTE_SECOND "ms"
396 /* Skeletons for time zones. */
399 * Constant for <i>generic location format</i>, such as Los Angeles Time;
400 * used in combinations date + time + zone, or time + zone.
401 * @see <a href="http://unicode.org/reports/tr35/#Date_Format_Patterns">LDML Date Format Patterns</a>
402 * @see <a href="http://unicode.org/reports/tr35/#Time_Zone_Fallback">LDML Time Zone Fallback</a>
405 #define UDAT_LOCATION_TZ "VVVV"
407 * Constant for <i>generic non-location format</i>, such as Pacific Time;
408 * used in combinations date + time + zone, or time + zone.
409 * @see <a href="http://unicode.org/reports/tr35/#Date_Format_Patterns">LDML Date Format Patterns</a>
410 * @see <a href="http://unicode.org/reports/tr35/#Time_Zone_Fallback">LDML Time Zone Fallback</a>
413 #define UDAT_GENERIC_TZ "vvvv"
415 * Constant for <i>generic non-location format</i>, abbreviated if possible, such as PT;
416 * used in combinations date + time + zone, or time + zone.
417 * @see <a href="http://unicode.org/reports/tr35/#Date_Format_Patterns">LDML Date Format Patterns</a>
418 * @see <a href="http://unicode.org/reports/tr35/#Time_Zone_Fallback">LDML Time Zone Fallback</a>
421 #define UDAT_ABBR_GENERIC_TZ "v"
423 * Constant for <i>specific non-location format</i>, such as Pacific Daylight Time;
424 * used in combinations date + time + zone, or time + zone.
425 * @see <a href="http://unicode.org/reports/tr35/#Date_Format_Patterns">LDML Date Format Patterns</a>
426 * @see <a href="http://unicode.org/reports/tr35/#Time_Zone_Fallback">LDML Time Zone Fallback</a>
429 #define UDAT_SPECIFIC_TZ "zzzz"
431 * Constant for <i>specific non-location format</i>, abbreviated if possible, such as PDT;
432 * used in combinations date + time + zone, or time + zone.
433 * @see <a href="http://unicode.org/reports/tr35/#Date_Format_Patterns">LDML Date Format Patterns</a>
434 * @see <a href="http://unicode.org/reports/tr35/#Time_Zone_Fallback">LDML Time Zone Fallback</a>
437 #define UDAT_ABBR_SPECIFIC_TZ "z"
439 * Constant for <i>localized GMT/UTC format</i>, such as GMT+8:00 or HPG-8:00;
440 * used in combinations date + time + zone, or time + zone.
441 * @see <a href="http://unicode.org/reports/tr35/#Date_Format_Patterns">LDML Date Format Patterns</a>
442 * @see <a href="http://unicode.org/reports/tr35/#Time_Zone_Fallback">LDML Time Zone Fallback</a>
445 #define UDAT_ABBR_UTC_TZ "ZZZZ"
447 /* deprecated skeleton constants */
449 #ifndef U_HIDE_DEPRECATED_API
451 * Constant for date skeleton with standalone month.
452 * @deprecated ICU 50 Use UDAT_MONTH instead.
454 #define UDAT_STANDALONE_MONTH "LLLL"
456 * Constant for date skeleton with standalone abbreviated month.
457 * @deprecated ICU 50 Use UDAT_ABBR_MONTH instead.
459 #define UDAT_ABBR_STANDALONE_MONTH "LLL"
462 * Constant for date skeleton with hour, minute, and generic timezone.
463 * @deprecated ICU 50 Use instead UDAT_HOUR_MINUTE UDAT_ABBR_GENERIC_TZ or some other timezone presentation.
465 #define UDAT_HOUR_MINUTE_GENERIC_TZ "jmv"
467 * Constant for date skeleton with hour, minute, and timezone.
468 * @deprecated ICU 50 Use instead UDAT_HOUR_MINUTE UDAT_ABBR_SPECIFIC_TZ or some other timezone presentation.
470 #define UDAT_HOUR_MINUTE_TZ "jmz"
472 * Constant for date skeleton with hour and generic timezone.
473 * @deprecated ICU 50 Use instead UDAT_HOUR UDAT_ABBR_GENERIC_TZ or some other timezone presentation.
475 #define UDAT_HOUR_GENERIC_TZ "jv"
477 * Constant for date skeleton with hour and timezone.
478 * @deprecated ICU 50 Use instead UDAT_HOUR UDAT_ABBR_SPECIFIC_TZ or some other timezone presentation.
480 #define UDAT_HOUR_TZ "jz"
481 #endif /* U_HIDE_DEPRECATED_API */
484 * FieldPosition and UFieldPosition selectors for format fields
485 * defined by DateFormat and UDateFormat.
488 typedef enum UDateFormatField
{
490 * FieldPosition and UFieldPosition selector for 'G' field alignment,
491 * corresponding to the UCAL_ERA field.
497 * FieldPosition and UFieldPosition selector for 'y' field alignment,
498 * corresponding to the UCAL_YEAR field.
504 * FieldPosition and UFieldPosition selector for 'M' field alignment,
505 * corresponding to the UCAL_MONTH field.
508 UDAT_MONTH_FIELD
= 2,
511 * FieldPosition and UFieldPosition selector for 'd' field alignment,
512 * corresponding to the UCAL_DATE field.
518 * FieldPosition and UFieldPosition selector for 'k' field alignment,
519 * corresponding to the UCAL_HOUR_OF_DAY field.
520 * UDAT_HOUR_OF_DAY1_FIELD is used for the one-based 24-hour clock.
521 * For example, 23:59 + 01:00 results in 24:59.
524 UDAT_HOUR_OF_DAY1_FIELD
= 4,
527 * FieldPosition and UFieldPosition selector for 'H' field alignment,
528 * corresponding to the UCAL_HOUR_OF_DAY field.
529 * UDAT_HOUR_OF_DAY0_FIELD is used for the zero-based 24-hour clock.
530 * For example, 23:59 + 01:00 results in 00:59.
533 UDAT_HOUR_OF_DAY0_FIELD
= 5,
536 * FieldPosition and UFieldPosition selector for 'm' field alignment,
537 * corresponding to the UCAL_MINUTE field.
540 UDAT_MINUTE_FIELD
= 6,
543 * FieldPosition and UFieldPosition selector for 's' field alignment,
544 * corresponding to the UCAL_SECOND field.
547 UDAT_SECOND_FIELD
= 7,
550 * FieldPosition and UFieldPosition selector for 'S' field alignment,
551 * corresponding to the UCAL_MILLISECOND field.
553 * Note: Time formats that use 'S' can display a maximum of three
554 * significant digits for fractional seconds, corresponding to millisecond
555 * resolution and a fractional seconds sub-pattern of SSS. If the
556 * sub-pattern is S or SS, the fractional seconds value will be truncated
557 * (not rounded) to the number of display places specified. If the
558 * fractional seconds sub-pattern is longer than SSS, the additional
559 * display places will be filled with zeros.
562 UDAT_FRACTIONAL_SECOND_FIELD
= 8,
565 * FieldPosition and UFieldPosition selector for 'E' field alignment,
566 * corresponding to the UCAL_DAY_OF_WEEK field.
569 UDAT_DAY_OF_WEEK_FIELD
= 9,
572 * FieldPosition and UFieldPosition selector for 'D' field alignment,
573 * corresponding to the UCAL_DAY_OF_YEAR field.
576 UDAT_DAY_OF_YEAR_FIELD
= 10,
579 * FieldPosition and UFieldPosition selector for 'F' field alignment,
580 * corresponding to the UCAL_DAY_OF_WEEK_IN_MONTH field.
583 UDAT_DAY_OF_WEEK_IN_MONTH_FIELD
= 11,
586 * FieldPosition and UFieldPosition selector for 'w' field alignment,
587 * corresponding to the UCAL_WEEK_OF_YEAR field.
590 UDAT_WEEK_OF_YEAR_FIELD
= 12,
593 * FieldPosition and UFieldPosition selector for 'W' field alignment,
594 * corresponding to the UCAL_WEEK_OF_MONTH field.
597 UDAT_WEEK_OF_MONTH_FIELD
= 13,
600 * FieldPosition and UFieldPosition selector for 'a' field alignment,
601 * corresponding to the UCAL_AM_PM field.
604 UDAT_AM_PM_FIELD
= 14,
607 * FieldPosition and UFieldPosition selector for 'h' field alignment,
608 * corresponding to the UCAL_HOUR field.
609 * UDAT_HOUR1_FIELD is used for the one-based 12-hour clock.
610 * For example, 11:30 PM + 1 hour results in 12:30 AM.
613 UDAT_HOUR1_FIELD
= 15,
616 * FieldPosition and UFieldPosition selector for 'K' field alignment,
617 * corresponding to the UCAL_HOUR field.
618 * UDAT_HOUR0_FIELD is used for the zero-based 12-hour clock.
619 * For example, 11:30 PM + 1 hour results in 00:30 AM.
622 UDAT_HOUR0_FIELD
= 16,
625 * FieldPosition and UFieldPosition selector for 'z' field alignment,
626 * corresponding to the UCAL_ZONE_OFFSET and
627 * UCAL_DST_OFFSET fields.
630 UDAT_TIMEZONE_FIELD
= 17,
633 * FieldPosition and UFieldPosition selector for 'Y' field alignment,
634 * corresponding to the UCAL_YEAR_WOY field.
637 UDAT_YEAR_WOY_FIELD
= 18,
640 * FieldPosition and UFieldPosition selector for 'e' field alignment,
641 * corresponding to the UCAL_DOW_LOCAL field.
644 UDAT_DOW_LOCAL_FIELD
= 19,
647 * FieldPosition and UFieldPosition selector for 'u' field alignment,
648 * corresponding to the UCAL_EXTENDED_YEAR field.
651 UDAT_EXTENDED_YEAR_FIELD
= 20,
654 * FieldPosition and UFieldPosition selector for 'g' field alignment,
655 * corresponding to the UCAL_JULIAN_DAY field.
658 UDAT_JULIAN_DAY_FIELD
= 21,
661 * FieldPosition and UFieldPosition selector for 'A' field alignment,
662 * corresponding to the UCAL_MILLISECONDS_IN_DAY field.
665 UDAT_MILLISECONDS_IN_DAY_FIELD
= 22,
668 * FieldPosition and UFieldPosition selector for 'Z' field alignment,
669 * corresponding to the UCAL_ZONE_OFFSET and
670 * UCAL_DST_OFFSET fields.
673 UDAT_TIMEZONE_RFC_FIELD
= 23,
676 * FieldPosition and UFieldPosition selector for 'v' field alignment,
677 * corresponding to the UCAL_ZONE_OFFSET field.
680 UDAT_TIMEZONE_GENERIC_FIELD
= 24,
682 * FieldPosition selector for 'c' field alignment,
683 * corresponding to the {@link #UCAL_DOW_LOCAL} field.
684 * This displays the stand alone day name, if available.
687 UDAT_STANDALONE_DAY_FIELD
= 25,
690 * FieldPosition selector for 'L' field alignment,
691 * corresponding to the {@link #UCAL_MONTH} field.
692 * This displays the stand alone month name, if available.
695 UDAT_STANDALONE_MONTH_FIELD
= 26,
698 * FieldPosition selector for "Q" field alignment,
699 * corresponding to quarters. This is implemented
700 * using the {@link #UCAL_MONTH} field. This
701 * displays the quarter.
704 UDAT_QUARTER_FIELD
= 27,
707 * FieldPosition selector for the "q" field alignment,
708 * corresponding to stand-alone quarters. This is
709 * implemented using the {@link #UCAL_MONTH} field.
710 * This displays the stand-alone quarter.
713 UDAT_STANDALONE_QUARTER_FIELD
= 28,
716 * FieldPosition and UFieldPosition selector for 'V' field alignment,
717 * corresponding to the UCAL_ZONE_OFFSET field.
720 UDAT_TIMEZONE_SPECIAL_FIELD
= 29,
723 * FieldPosition selector for "U" field alignment,
724 * corresponding to cyclic year names. This is implemented
725 * using the {@link #UCAL_YEAR} field. This displays
726 * the cyclic year name, if available.
729 UDAT_YEAR_NAME_FIELD
= 30,
732 * FieldPosition selector for 'O' field alignment,
733 * corresponding to the UCAL_ZONE_OFFSET and UCAL_DST_OFFSETfields.
734 * This displays the localized GMT format.
737 UDAT_TIMEZONE_LOCALIZED_GMT_OFFSET_FIELD
= 31,
740 * FieldPosition selector for 'X' field alignment,
741 * corresponding to the UCAL_ZONE_OFFSET and UCAL_DST_OFFSETfields.
742 * This displays the ISO 8601 local time offset format or UTC indicator ("Z").
745 UDAT_TIMEZONE_ISO_FIELD
= 32,
748 * FieldPosition selector for 'x' field alignment,
749 * corresponding to the UCAL_ZONE_OFFSET and UCAL_DST_OFFSET fields.
750 * This displays the ISO 8601 local time offset format.
753 UDAT_TIMEZONE_ISO_LOCAL_FIELD
= 33,
755 #ifndef U_HIDE_INTERNAL_API
757 * FieldPosition and UFieldPosition selector for 'r' field alignment,
758 * no directly corresponding UCAL_ field.
761 UDAT_RELATED_YEAR_FIELD
= 34,
762 #endif /* U_HIDE_INTERNAL_API */
764 #ifndef U_HIDE_DRAFT_API
766 * FieldPosition and UFieldPosition selector for ':' time separator,
767 * no corresponding UCAL_ field.
770 UDAT_TIME_SEPARATOR_FIELD
= 35,
771 #endif /* U_HIDE_DRAFT_API */
774 * Number of FieldPosition and UFieldPosition selectors for
775 * DateFormat and UDateFormat.
776 * Valid selectors range from 0 to UDAT_FIELD_COUNT-1.
777 * This value is subject to change if new fields are defined
781 UDAT_FIELD_COUNT
= 36
787 * Maps from a UDateFormatField to the corresponding UCalendarDateFields.
788 * Note: since the mapping is many-to-one, there is no inverse mapping.
789 * @param field the UDateFormatField.
790 * @return the UCalendarDateField. This will be UCAL_FIELD_COUNT in case
791 * of error (e.g., the input field is UDAT_FIELD_COUNT).
794 U_STABLE UCalendarDateFields U_EXPORT2
795 udat_toCalendarDateField(UDateFormatField field
);
799 * Open a new UDateFormat for formatting and parsing dates and times.
800 * A UDateFormat may be used to format dates in calls to {@link #udat_format },
801 * and to parse dates in calls to {@link #udat_parse }.
802 * @param timeStyle The style used to format times; one of UDAT_FULL, UDAT_LONG,
803 * UDAT_MEDIUM, UDAT_SHORT, UDAT_DEFAULT, or UDAT_NONE (relative time styles
804 * are not currently supported).
805 * When the pattern parameter is used, pass in UDAT_PATTERN for both timeStyle and dateStyle.
806 * @param dateStyle The style used to format dates; one of UDAT_FULL, UDAT_LONG,
807 * UDAT_MEDIUM, UDAT_SHORT, UDAT_DEFAULT, UDAT_FULL_RELATIVE, UDAT_LONG_RELATIVE,
808 * UDAT_MEDIUM_RELATIVE, UDAT_SHORT_RELATIVE, or UDAT_NONE.
809 * When the pattern parameter is used, pass in UDAT_PATTERN for both timeStyle and dateStyle.
810 * As currently implemented,
811 * relative date formatting only affects a limited range of calendar days before or
812 * after the current date, based on the CLDR <field type="day">/<relative> data: For
813 * example, in English, "Yesterday", "Today", and "Tomorrow". Outside of this range,
814 * dates are formatted using the corresponding non-relative style.
815 * @param locale The locale specifying the formatting conventions
816 * @param tzID A timezone ID specifying the timezone to use. If 0, use
817 * the default timezone.
818 * @param tzIDLength The length of tzID, or -1 if null-terminated.
819 * @param pattern A pattern specifying the format to use.
820 * @param patternLength The number of characters in the pattern, or -1 if null-terminated.
821 * @param status A pointer to an UErrorCode to receive any errors
822 * @return A pointer to a UDateFormat to use for formatting dates and times, or 0 if
826 U_STABLE UDateFormat
* U_EXPORT2
827 udat_open(UDateFormatStyle timeStyle
,
828 UDateFormatStyle dateStyle
,
832 const UChar
*pattern
,
833 int32_t patternLength
,
838 * Close a UDateFormat.
839 * Once closed, a UDateFormat may no longer be used.
840 * @param format The formatter to close.
843 U_STABLE
void U_EXPORT2
844 udat_close(UDateFormat
* format
);
848 * DateFormat boolean attributes
852 typedef enum UDateFormatBooleanAttribute
{
854 * indicates whether whitespace is allowed. Includes trailing dot tolerance.
857 UDAT_PARSE_ALLOW_WHITESPACE
= 0,
859 * indicates tolerance of numeric data when String data may be assumed. eg: UDAT_YEAR_NAME_FIELD,
860 * UDAT_STANDALONE_MONTH_FIELD, UDAT_DAY_OF_WEEK_FIELD
863 UDAT_PARSE_ALLOW_NUMERIC
= 1,
864 #ifndef U_HIDE_DRAFT_API
866 * indicates tolerance of a partial literal match
869 UDAT_PARSE_PARTIAL_MATCH
= 2,
871 * indicates tolerance of pattern mismatch between input data and specified format pattern.
872 * e.g. accepting "September" for a month pattern of MMM ("Sep")
875 UDAT_PARSE_MULTIPLE_PATTERNS_FOR_MATCH
= 3,
876 #endif /* U_HIDE_DRAFT_API */
878 * count boolean date format constants
881 UDAT_BOOLEAN_ATTRIBUTE_COUNT
= 4
882 } UDateFormatBooleanAttribute
;
885 * Get a boolean attribute associated with a UDateFormat.
886 * An example would be a true value for a key of UDAT_PARSE_ALLOW_WHITESPACE indicating allowing whitespace leniency.
887 * If the formatter does not understand the attribute, -1 is returned.
888 * @param fmt The formatter to query.
889 * @param attr The attribute to query; e.g. UDAT_PARSE_ALLOW_WHITESPACE.
890 * @param status A pointer to an UErrorCode to receive any errors
891 * @return The value of attr.
894 U_STABLE UBool U_EXPORT2
895 udat_getBooleanAttribute(const UDateFormat
* fmt
, UDateFormatBooleanAttribute attr
, UErrorCode
* status
);
898 * Set a boolean attribute associated with a UDateFormat.
899 * An example of a boolean attribute is parse leniency control. If the formatter does not understand
900 * the attribute, the call is ignored.
901 * @param fmt The formatter to set.
902 * @param attr The attribute to set; one of UDAT_PARSE_ALLOW_WHITESPACE or UDAT_PARSE_ALLOW_NUMERIC
903 * @param newValue The new value of attr.
904 * @param status A pointer to an UErrorCode to receive any errors
907 U_STABLE
void U_EXPORT2
908 udat_setBooleanAttribute(UDateFormat
*fmt
, UDateFormatBooleanAttribute attr
, UBool newValue
, UErrorCode
* status
);
912 #if U_SHOW_CPLUSPLUS_API
917 * \class LocalUDateFormatPointer
918 * "Smart pointer" class, closes a UDateFormat via udat_close().
919 * For most methods see the LocalPointerBase base class.
921 * @see LocalPointerBase
925 U_DEFINE_LOCAL_OPEN_POINTER(LocalUDateFormatPointer
, UDateFormat
, udat_close
);
932 * Open a copy of a UDateFormat.
933 * This function performs a deep copy.
934 * @param fmt The format to copy
935 * @param status A pointer to an UErrorCode to receive any errors.
936 * @return A pointer to a UDateFormat identical to fmt.
939 U_STABLE UDateFormat
* U_EXPORT2
940 udat_clone(const UDateFormat
*fmt
,
944 * Format a date using a UDateFormat.
945 * The date will be formatted using the conventions specified in {@link #udat_open }
946 * @param format The formatter to use
947 * @param dateToFormat The date to format
948 * @param result A pointer to a buffer to receive the formatted number.
949 * @param resultLength The maximum size of result.
950 * @param position A pointer to a UFieldPosition. On input, position->field
951 * is read. On output, position->beginIndex and position->endIndex indicate
952 * the beginning and ending indices of field number position->field, if such
953 * a field exists. This parameter may be NULL, in which case no field
954 * position data is returned.
955 * @param status A pointer to an UErrorCode to receive any errors
956 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
958 * @see UFieldPosition
961 U_STABLE
int32_t U_EXPORT2
962 udat_format( const UDateFormat
* format
,
965 int32_t resultLength
,
966 UFieldPosition
* position
,
969 #ifndef U_HIDE_DRAFT_API
971 * Format a date using an UDateFormat.
972 * The date will be formatted using the conventions specified in {@link #udat_open }
973 * @param format The formatter to use
974 * @param calendar The calendar to format. The calendar instance might be
975 * mutated if fields are not yet fully calculated, though
976 * the function won't change the logical date and time held
978 * @param result A pointer to a buffer to receive the formatted number.
979 * @param capacity The maximum size of result.
980 * @param position A pointer to a UFieldPosition. On input, position->field
981 * is read. On output, position->beginIndex and position->endIndex indicate
982 * the beginning and ending indices of field number position->field, if such
983 * a field exists. This parameter may be NULL, in which case no field
984 * position data is returned.
985 * @param status A pointer to an UErrorCode to receive any errors
986 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
988 * @see udat_parseCalendar
989 * @see UFieldPosition
992 U_DRAFT
int32_t U_EXPORT2
993 udat_formatCalendar( const UDateFormat
* format
,
997 UFieldPosition
* position
,
1001 * Format a date using a UDateFormat.
1002 * The date will be formatted using the conventions specified in {@link #udat_open}
1004 * The formatter to use
1005 * @param dateToFormat
1006 * The date to format
1008 * A pointer to a buffer to receive the formatted number.
1009 * @param resultLength
1010 * The maximum size of result.
1012 * A pointer to a UFieldPositionIterator created by {@link #ufieldpositer_open}
1013 * (may be NULL if field position information is not needed). Any
1014 * iteration information already present in the UFieldPositionIterator
1015 * will be deleted, and the iterator will be reset to apply to the
1016 * fields in the formatted string created by this function call; the
1017 * field values provided by {@link #ufieldpositer_next} will be from the
1018 * UDateFormatField enum.
1020 * A pointer to a UErrorCode to receive any errors
1022 * The total buffer size needed; if greater than resultLength, the output was truncated.
1024 * @see UFieldPositionIterator
1027 U_DRAFT
int32_t U_EXPORT2
1028 udat_formatForFields( const UDateFormat
* format
,
1031 int32_t resultLength
,
1032 UFieldPositionIterator
* fpositer
,
1033 UErrorCode
* status
);
1036 * Format a date using a UDateFormat.
1037 * The date will be formatted using the conventions specified in {@link #udat_open }
1039 * The formatter to use
1041 * The calendar to format. The calendar instance might be mutated if fields
1042 * are not yet fully calculated, though the function won't change the logical
1043 * date and time held by the instance.
1045 * A pointer to a buffer to receive the formatted number.
1047 * The maximum size of result.
1049 * A pointer to a UFieldPositionIterator created by {@link #ufieldpositer_open}
1050 * (may be NULL if field position information is not needed). Any
1051 * iteration information already present in the UFieldPositionIterator
1052 * will be deleted, and the iterator will be reset to apply to the
1053 * fields in the formatted string created by this function call; the
1054 * field values provided by {@link #ufieldpositer_next} will be from the
1055 * UDateFormatField enum.
1057 * A pointer to a UErrorCode to receive any errors
1059 * The total buffer size needed; if greater than resultLength, the output was truncated.
1061 * @see udat_parseCalendar
1062 * @see UFieldPositionIterator
1065 U_DRAFT
int32_t U_EXPORT2
1066 udat_formatCalendarForFields( const UDateFormat
* format
,
1067 UCalendar
* calendar
,
1070 UFieldPositionIterator
* fpositer
,
1071 UErrorCode
* status
);
1073 #endif /* U_HIDE_DRAFT_API */
1076 * Parse a string into an date/time using a UDateFormat.
1077 * The date will be parsed using the conventions specified in {@link #udat_open }.
1079 * Note that the normal date formats associated with some calendars - such
1080 * as the Chinese lunar calendar - do not specify enough fields to enable
1081 * dates to be parsed unambiguously. In the case of the Chinese lunar
1082 * calendar, while the year within the current 60-year cycle is specified,
1083 * the number of such cycles since the start date of the calendar (in the
1084 * UCAL_ERA field of the UCalendar object) is not normally part of the format,
1085 * and parsing may assume the wrong era. For cases such as this it is
1086 * recommended that clients parse using udat_parseCalendar with the UCalendar
1087 * passed in set to the current date, or to a date within the era/cycle that
1088 * should be assumed if absent in the format.
1090 * @param format The formatter to use.
1091 * @param text The text to parse.
1092 * @param textLength The length of text, or -1 if null-terminated.
1093 * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which
1094 * to begin parsing. If not 0, on output the offset at which parsing ended.
1095 * @param status A pointer to an UErrorCode to receive any errors
1096 * @return The value of the parsed date/time
1100 U_STABLE UDate U_EXPORT2
1101 udat_parse(const UDateFormat
* format
,
1105 UErrorCode
*status
);
1108 * Parse a string into an date/time using a UDateFormat.
1109 * The date will be parsed using the conventions specified in {@link #udat_open }.
1110 * @param format The formatter to use.
1111 * @param calendar A calendar set on input to the date and time to be used for
1112 * missing values in the date/time string being parsed, and set
1113 * on output to the parsed date/time. When the calendar type is
1114 * different from the internal calendar held by the UDateFormat
1115 * instance, the internal calendar will be cloned to a work
1116 * calendar set to the same milliseconds and time zone as this
1117 * calendar parameter, field values will be parsed based on the
1118 * work calendar, then the result (milliseconds and time zone)
1119 * will be set in this calendar.
1120 * @param text The text to parse.
1121 * @param textLength The length of text, or -1 if null-terminated.
1122 * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which
1123 * to begin parsing. If not 0, on output the offset at which parsing ended.
1124 * @param status A pointer to an UErrorCode to receive any errors
1128 U_STABLE
void U_EXPORT2
1129 udat_parseCalendar(const UDateFormat
* format
,
1130 UCalendar
* calendar
,
1134 UErrorCode
*status
);
1137 * Determine if an UDateFormat will perform lenient parsing.
1138 * With lenient parsing, the parser may use heuristics to interpret inputs that do not
1139 * precisely match the pattern. With strict parsing, inputs must match the pattern.
1140 * @param fmt The formatter to query
1141 * @return TRUE if fmt is set to perform lenient parsing, FALSE otherwise.
1142 * @see udat_setLenient
1145 U_STABLE UBool U_EXPORT2
1146 udat_isLenient(const UDateFormat
* fmt
);
1149 * Specify whether an UDateFormat will perform lenient parsing.
1150 * With lenient parsing, the parser may use heuristics to interpret inputs that do not
1151 * precisely match the pattern. With strict parsing, inputs must match the pattern.
1152 * @param fmt The formatter to set
1153 * @param isLenient TRUE if fmt should perform lenient parsing, FALSE otherwise.
1154 * @see dat_isLenient
1157 U_STABLE
void U_EXPORT2
1158 udat_setLenient( UDateFormat
* fmt
,
1162 * Get the UCalendar associated with an UDateFormat.
1163 * A UDateFormat uses a UCalendar to convert a raw value to, for example,
1164 * the day of the week.
1165 * @param fmt The formatter to query.
1166 * @return A pointer to the UCalendar used by fmt.
1167 * @see udat_setCalendar
1170 U_STABLE
const UCalendar
* U_EXPORT2
1171 udat_getCalendar(const UDateFormat
* fmt
);
1174 * Set the UCalendar associated with an UDateFormat.
1175 * A UDateFormat uses a UCalendar to convert a raw value to, for example,
1176 * the day of the week.
1177 * @param fmt The formatter to set.
1178 * @param calendarToSet A pointer to an UCalendar to be used by fmt.
1179 * @see udat_setCalendar
1182 U_STABLE
void U_EXPORT2
1183 udat_setCalendar( UDateFormat
* fmt
,
1184 const UCalendar
* calendarToSet
);
1187 * Get the UNumberFormat associated with an UDateFormat.
1188 * A UDateFormat uses a UNumberFormat to format numbers within a date,
1189 * for example the day number.
1190 * @param fmt The formatter to query.
1191 * @return A pointer to the UNumberFormat used by fmt to format numbers.
1192 * @see udat_setNumberFormat
1195 U_STABLE
const UNumberFormat
* U_EXPORT2
1196 udat_getNumberFormat(const UDateFormat
* fmt
);
1198 #ifndef U_HIDE_DRAFT_API
1200 * Get the UNumberFormat for specific field associated with an UDateFormat.
1201 * For example: 'y' for year and 'M' for month
1202 * @param fmt The formatter to query.
1203 * @param field the field to query
1204 * @return A pointer to the UNumberFormat used by fmt to format field numbers.
1205 * @see udat_setNumberFormatForField
1208 U_DRAFT
const UNumberFormat
* U_EXPORT2
1209 udat_getNumberFormatForField(const UDateFormat
* fmt
, UChar field
);
1212 * Set the UNumberFormat for specific field associated with an UDateFormat.
1213 * It can be a single field like: "y"(year) or "M"(month)
1214 * It can be several field combined together: "yM"(year and month)
1216 * 1 symbol field is enough for multiple symbol field (so "y" will override "yy", "yyy")
1217 * If the field is not numeric, then override has no effect (like "MMM" will use abbreviation, not numerical field)
1219 * @param fields the fields to set
1220 * @param fmt The formatter to set.
1221 * @param numberFormatToSet A pointer to the UNumberFormat to be used by fmt to format numbers.
1222 * @param status error code passed around (memory allocation or invalid fields)
1223 * @see udat_getNumberFormatForField
1226 U_DRAFT
void U_EXPORT2
1227 udat_adoptNumberFormatForFields( UDateFormat
* fmt
,
1228 const UChar
* fields
,
1229 UNumberFormat
* numberFormatToSet
,
1230 UErrorCode
* status
);
1231 #endif /* U_HIDE_DRAFT_API */
1234 * Set the UNumberFormat associated with an UDateFormat.
1235 * A UDateFormat uses a UNumberFormat to format numbers within a date,
1236 * for example the day number.
1237 * This method also clears per field NumberFormat instances previously
1238 * set by {@see udat_setNumberFormatForField}
1239 * @param fmt The formatter to set.
1240 * @param numberFormatToSet A pointer to the UNumberFormat to be used by fmt to format numbers.
1241 * @see udat_getNumberFormat
1242 * @see udat_setNumberFormatForField
1245 U_STABLE
void U_EXPORT2
1246 udat_setNumberFormat( UDateFormat
* fmt
,
1247 const UNumberFormat
* numberFormatToSet
);
1249 #ifndef U_HIDE_DRAFT_API
1251 * Adopt the UNumberFormat associated with an UDateFormat.
1252 * A UDateFormat uses a UNumberFormat to format numbers within a date,
1253 * for example the day number.
1254 * @param fmt The formatter to set.
1255 * @param numberFormatToAdopt A pointer to the UNumberFormat to be used by fmt to format numbers.
1256 * @see udat_getNumberFormat
1259 U_DRAFT
void U_EXPORT2
1260 udat_adoptNumberFormat( UDateFormat
* fmt
,
1261 UNumberFormat
* numberFormatToAdopt
);
1262 #endif /* U_HIDE_DRAFT_API */
1265 * Get a locale for which date/time formatting patterns are available.
1266 * A UDateFormat in a locale returned by this function will perform the correct
1267 * formatting and parsing for the locale.
1268 * @param localeIndex The index of the desired locale.
1269 * @return A locale for which date/time formatting patterns are available, or 0 if none.
1270 * @see udat_countAvailable
1273 U_STABLE
const char* U_EXPORT2
1274 udat_getAvailable(int32_t localeIndex
);
1277 * Determine how many locales have date/time formatting patterns available.
1278 * This function is most useful as determining the loop ending condition for
1279 * calls to {@link #udat_getAvailable }.
1280 * @return The number of locales for which date/time formatting patterns are available.
1281 * @see udat_getAvailable
1284 U_STABLE
int32_t U_EXPORT2
1285 udat_countAvailable(void);
1288 * Get the year relative to which all 2-digit years are interpreted.
1289 * For example, if the 2-digit start year is 2100, the year 99 will be
1290 * interpreted as 2199.
1291 * @param fmt The formatter to query.
1292 * @param status A pointer to an UErrorCode to receive any errors
1293 * @return The year relative to which all 2-digit years are interpreted.
1294 * @see udat_Set2DigitYearStart
1297 U_STABLE UDate U_EXPORT2
1298 udat_get2DigitYearStart( const UDateFormat
*fmt
,
1299 UErrorCode
*status
);
1302 * Set the year relative to which all 2-digit years will be interpreted.
1303 * For example, if the 2-digit start year is 2100, the year 99 will be
1304 * interpreted as 2199.
1305 * @param fmt The formatter to set.
1306 * @param d The year relative to which all 2-digit years will be interpreted.
1307 * @param status A pointer to an UErrorCode to receive any errors
1308 * @see udat_Set2DigitYearStart
1311 U_STABLE
void U_EXPORT2
1312 udat_set2DigitYearStart( UDateFormat
*fmt
,
1314 UErrorCode
*status
);
1317 * Extract the pattern from a UDateFormat.
1318 * The pattern will follow the pattern syntax rules.
1319 * @param fmt The formatter to query.
1320 * @param localized TRUE if the pattern should be localized, FALSE otherwise.
1321 * @param result A pointer to a buffer to receive the pattern.
1322 * @param resultLength The maximum size of result.
1323 * @param status A pointer to an UErrorCode to receive any errors
1324 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
1325 * @see udat_applyPattern
1328 U_STABLE
int32_t U_EXPORT2
1329 udat_toPattern( const UDateFormat
*fmt
,
1332 int32_t resultLength
,
1333 UErrorCode
*status
);
1336 * Set the pattern used by an UDateFormat.
1337 * The pattern should follow the pattern syntax rules.
1338 * @param format The formatter to set.
1339 * @param localized TRUE if the pattern is localized, FALSE otherwise.
1340 * @param pattern The new pattern
1341 * @param patternLength The length of pattern, or -1 if null-terminated.
1342 * @see udat_toPattern
1345 U_STABLE
void U_EXPORT2
1346 udat_applyPattern( UDateFormat
*format
,
1348 const UChar
*pattern
,
1349 int32_t patternLength
);
1352 * The possible types of date format symbols
1355 typedef enum UDateFormatSymbolType
{
1356 /** The era names, for example AD */
1358 /** The month names, for example February */
1360 /** The short month names, for example Feb. */
1362 /** The CLDR-style format "wide" weekday names, for example Monday */
1365 * The CLDR-style format "abbreviated" (not "short") weekday names, for example "Mon."
1366 * For the CLDR-style format "short" weekday names, use UDAT_SHORTER_WEEKDAYS.
1368 UDAT_SHORT_WEEKDAYS
,
1369 /** The AM/PM names, for example AM */
1371 /** The localized characters */
1372 UDAT_LOCALIZED_CHARS
,
1373 /** The long era names, for example Anno Domini */
1375 /** The narrow month names, for example F */
1377 /** The CLDR-style format "narrow" weekday names, for example "M" */
1378 UDAT_NARROW_WEEKDAYS
,
1379 /** Standalone context versions of months */
1380 UDAT_STANDALONE_MONTHS
,
1381 UDAT_STANDALONE_SHORT_MONTHS
,
1382 UDAT_STANDALONE_NARROW_MONTHS
,
1383 /** The CLDR-style stand-alone "wide" weekday names */
1384 UDAT_STANDALONE_WEEKDAYS
,
1386 * The CLDR-style stand-alone "abbreviated" (not "short") weekday names.
1387 * For the CLDR-style stand-alone "short" weekday names, use UDAT_STANDALONE_SHORTER_WEEKDAYS.
1389 UDAT_STANDALONE_SHORT_WEEKDAYS
,
1390 /** The CLDR-style stand-alone "narrow" weekday names */
1391 UDAT_STANDALONE_NARROW_WEEKDAYS
,
1392 /** The quarters, for example 1st Quarter */
1394 /** The short quarter names, for example Q1 */
1395 UDAT_SHORT_QUARTERS
,
1396 /** Standalone context versions of quarters */
1397 UDAT_STANDALONE_QUARTERS
,
1398 UDAT_STANDALONE_SHORT_QUARTERS
,
1400 * The CLDR-style short weekday names, e.g. "Su", Mo", etc.
1401 * These are named "SHORTER" to contrast with the constants using _SHORT_
1402 * above, which actually get the CLDR-style *abbreviated* versions of the
1403 * corresponding names.
1406 UDAT_SHORTER_WEEKDAYS
,
1408 * Standalone version of UDAT_SHORTER_WEEKDAYS.
1411 UDAT_STANDALONE_SHORTER_WEEKDAYS
1412 #ifndef U_HIDE_DRAFT_API
1415 * Cyclic year names (only supported for some calendars, and only for FORMAT usage;
1416 * udat_setSymbols not supported for UDAT_CYCLIC_YEARS_WIDE)
1419 UDAT_CYCLIC_YEARS_WIDE
,
1421 * Cyclic year names (only supported for some calendars, and only for FORMAT usage)
1424 UDAT_CYCLIC_YEARS_ABBREVIATED
,
1426 * Cyclic year names (only supported for some calendars, and only for FORMAT usage;
1427 * udat_setSymbols not supported for UDAT_CYCLIC_YEARS_NARROW)
1430 UDAT_CYCLIC_YEARS_NARROW
,
1432 * Calendar zodiac names (only supported for some calendars, and only for FORMAT usage;
1433 * udat_setSymbols not supported for UDAT_ZODIAC_NAMES_WIDE)
1436 UDAT_ZODIAC_NAMES_WIDE
,
1438 * Calendar zodiac names (only supported for some calendars, and only for FORMAT usage)
1441 UDAT_ZODIAC_NAMES_ABBREVIATED
,
1443 * Calendar zodiac names (only supported for some calendars, and only for FORMAT usage;
1444 * udat_setSymbols not supported for UDAT_ZODIAC_NAMES_NARROW)
1447 UDAT_ZODIAC_NAMES_NARROW
1448 #endif /* U_HIDE_DRAFT_API */
1449 } UDateFormatSymbolType
;
1451 struct UDateFormatSymbols
;
1452 /** Date format symbols.
1453 * For usage in C programs.
1456 typedef struct UDateFormatSymbols UDateFormatSymbols
;
1459 * Get the symbols associated with an UDateFormat.
1460 * The symbols are what a UDateFormat uses to represent locale-specific data,
1461 * for example month or day names.
1462 * @param fmt The formatter to query.
1463 * @param type The type of symbols to get. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS,
1464 * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS
1465 * @param symbolIndex The desired symbol of type type.
1466 * @param result A pointer to a buffer to receive the pattern.
1467 * @param resultLength The maximum size of result.
1468 * @param status A pointer to an UErrorCode to receive any errors
1469 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
1470 * @see udat_countSymbols
1471 * @see udat_setSymbols
1474 U_STABLE
int32_t U_EXPORT2
1475 udat_getSymbols(const UDateFormat
*fmt
,
1476 UDateFormatSymbolType type
,
1477 int32_t symbolIndex
,
1479 int32_t resultLength
,
1480 UErrorCode
*status
);
1483 * Count the number of particular symbols for an UDateFormat.
1484 * This function is most useful as for detemining the loop termination condition
1485 * for calls to {@link #udat_getSymbols }.
1486 * @param fmt The formatter to query.
1487 * @param type The type of symbols to count. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS,
1488 * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS
1489 * @return The number of symbols of type type.
1490 * @see udat_getSymbols
1491 * @see udat_setSymbols
1494 U_STABLE
int32_t U_EXPORT2
1495 udat_countSymbols( const UDateFormat
*fmt
,
1496 UDateFormatSymbolType type
);
1499 * Set the symbols associated with an UDateFormat.
1500 * The symbols are what a UDateFormat uses to represent locale-specific data,
1501 * for example month or day names.
1502 * @param format The formatter to set
1503 * @param type The type of symbols to set. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS,
1504 * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS
1505 * @param symbolIndex The index of the symbol to set of type type.
1506 * @param value The new value
1507 * @param valueLength The length of value, or -1 if null-terminated
1508 * @param status A pointer to an UErrorCode to receive any errors
1509 * @see udat_getSymbols
1510 * @see udat_countSymbols
1513 U_STABLE
void U_EXPORT2
1514 udat_setSymbols( UDateFormat
*format
,
1515 UDateFormatSymbolType type
,
1516 int32_t symbolIndex
,
1518 int32_t valueLength
,
1519 UErrorCode
*status
);
1522 * Get the locale for this date format object.
1523 * You can choose between valid and actual locale.
1524 * @param fmt The formatter to get the locale from
1525 * @param type type of the locale we're looking for (valid or actual)
1526 * @param status error code for the operation
1527 * @return the locale name
1530 U_STABLE
const char* U_EXPORT2
1531 udat_getLocaleByType(const UDateFormat
*fmt
,
1532 ULocDataLocaleType type
,
1533 UErrorCode
* status
);
1536 * Set a particular UDisplayContext value in the formatter, such as
1537 * UDISPCTX_CAPITALIZATION_FOR_STANDALONE.
1538 * @param fmt The formatter for which to set a UDisplayContext value.
1539 * @param value The UDisplayContext value to set.
1540 * @param status A pointer to an UErrorCode to receive any errors
1543 U_DRAFT
void U_EXPORT2
1544 udat_setContext(UDateFormat
* fmt
, UDisplayContext value
, UErrorCode
* status
);
1547 * Get the formatter's UDisplayContext value for the specified UDisplayContextType,
1548 * such as UDISPCTX_TYPE_CAPITALIZATION.
1549 * @param fmt The formatter to query.
1550 * @param type The UDisplayContextType whose value to return
1551 * @param status A pointer to an UErrorCode to receive any errors
1552 * @return The UDisplayContextValue for the specified type.
1555 U_STABLE UDisplayContext U_EXPORT2
1556 udat_getContext(const UDateFormat
* fmt
, UDisplayContextType type
, UErrorCode
* status
);
1558 #ifndef U_HIDE_INTERNAL_API
1560 * Extract the date pattern from a UDateFormat set for relative date formatting.
1561 * The pattern will follow the pattern syntax rules.
1562 * @param fmt The formatter to query.
1563 * @param result A pointer to a buffer to receive the pattern.
1564 * @param resultLength The maximum size of result.
1565 * @param status A pointer to a UErrorCode to receive any errors
1566 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
1567 * @see udat_applyPatternRelative
1568 * @internal ICU 4.2 technology preview
1570 U_INTERNAL
int32_t U_EXPORT2
1571 udat_toPatternRelativeDate(const UDateFormat
*fmt
,
1573 int32_t resultLength
,
1574 UErrorCode
*status
);
1577 * Extract the time pattern from a UDateFormat set for relative date formatting.
1578 * The pattern will follow the pattern syntax rules.
1579 * @param fmt The formatter to query.
1580 * @param result A pointer to a buffer to receive the pattern.
1581 * @param resultLength The maximum size of result.
1582 * @param status A pointer to a UErrorCode to receive any errors
1583 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
1584 * @see udat_applyPatternRelative
1585 * @internal ICU 4.2 technology preview
1587 U_INTERNAL
int32_t U_EXPORT2
1588 udat_toPatternRelativeTime(const UDateFormat
*fmt
,
1590 int32_t resultLength
,
1591 UErrorCode
*status
);
1594 * Set the date & time patterns used by a UDateFormat set for relative date formatting.
1595 * The patterns should follow the pattern syntax rules.
1596 * @param format The formatter to set.
1597 * @param datePattern The new date pattern
1598 * @param datePatternLength The length of datePattern, or -1 if null-terminated.
1599 * @param timePattern The new time pattern
1600 * @param timePatternLength The length of timePattern, or -1 if null-terminated.
1601 * @param status A pointer to a UErrorCode to receive any errors
1602 * @see udat_toPatternRelativeDate, udat_toPatternRelativeTime
1603 * @internal ICU 4.2 technology preview
1605 U_INTERNAL
void U_EXPORT2
1606 udat_applyPatternRelative(UDateFormat
*format
,
1607 const UChar
*datePattern
,
1608 int32_t datePatternLength
,
1609 const UChar
*timePattern
,
1610 int32_t timePatternLength
,
1611 UErrorCode
*status
);
1617 typedef UDateFormat
* (U_EXPORT2
*UDateFormatOpener
) (UDateFormatStyle timeStyle
,
1618 UDateFormatStyle dateStyle
,
1622 const UChar
*pattern
,
1623 int32_t patternLength
,
1624 UErrorCode
*status
);
1627 * Register a provider factory
1630 U_INTERNAL
void U_EXPORT2
1631 udat_registerOpener(UDateFormatOpener opener
, UErrorCode
*status
);
1634 * Un-Register a provider factory
1637 U_INTERNAL UDateFormatOpener U_EXPORT2
1638 udat_unregisterOpener(UDateFormatOpener opener
, UErrorCode
*status
);
1639 #endif /* U_HIDE_INTERNAL_API */
1642 #endif /* #if !UCONFIG_NO_FORMATTING */