2 *******************************************************************************
3 * Copyright (C) 1996-2013, 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"
21 * \brief C API: DateFormat
23 * <h2> Date Format C API</h2>
25 * Date Format C API consists of functions that convert dates and
26 * times from their internal representations to textual form and back again in a
27 * language-independent manner. Converting from the internal representation (milliseconds
28 * since midnight, January 1, 1970) to text is known as "formatting," and converting
29 * from text to millis is known as "parsing." We currently define only one concrete
30 * structure UDateFormat, which can handle pretty much all normal
31 * date formatting and parsing actions.
33 * Date Format helps you to format and parse dates for any locale. Your code can
34 * be completely independent of the locale conventions for months, days of the
35 * week, or even the calendar format: lunar vs. solar.
37 * To format a date for the current Locale with default time and date style,
38 * use one of the static factory methods:
41 * UErrorCode status = U_ZERO_ERROR;
43 * int32_t myStrlen = 0;
44 * UDateFormat* dfmt = udat_open(UDAT_DEFAULT, UDAT_DEFAULT, NULL, NULL, -1, NULL, -1, &status);
45 * myStrlen = udat_format(dfmt, myDate, NULL, myStrlen, NULL, &status);
46 * if (status==U_BUFFER_OVERFLOW_ERROR){
47 * status=U_ZERO_ERROR;
48 * myString=(UChar*)malloc(sizeof(UChar) * (myStrlen+1) );
49 * udat_format(dfmt, myDate, myString, myStrlen+1, NULL, &status);
53 * If you are formatting multiple numbers, it is more efficient to get the
54 * format and use it multiple times so that the system doesn't have to fetch the
55 * information about the local language and country conventions multiple times.
58 * UErrorCode status = U_ZERO_ERROR;
59 * int32_t i, myStrlen = 0;
62 * UDate myDateArr[] = { 0.0, 100000000.0, 2000000000.0 }; // test values
63 * UDateFormat* df = udat_open(UDAT_DEFAULT, UDAT_DEFAULT, NULL, NULL, -1, NULL, 0, &status);
64 * for (i = 0; i < 3; i++) {
65 * myStrlen = udat_format(df, myDateArr[i], NULL, myStrlen, NULL, &status);
66 * if(status == U_BUFFER_OVERFLOW_ERROR){
67 * status = U_ZERO_ERROR;
68 * myString = (UChar*)malloc(sizeof(UChar) * (myStrlen+1) );
69 * udat_format(df, myDateArr[i], myString, myStrlen+1, NULL, &status);
70 * printf("%s\n", u_austrcpy(buffer, myString) );
76 * To get specific fields of a date, you can use UFieldPosition to
77 * get specific fields.
80 * UErrorCode status = U_ZERO_ERROR;
83 * int32_t myStrlen = 0;
86 * pos.field = 1; // Same as the DateFormat::EField enum
87 * UDateFormat* dfmt = udat_open(UDAT_DEFAULT, UDAT_DEFAULT, NULL, -1, NULL, 0, &status);
88 * myStrlen = udat_format(dfmt, myDate, NULL, myStrlen, &pos, &status);
89 * if (status==U_BUFFER_OVERFLOW_ERROR){
90 * status=U_ZERO_ERROR;
91 * myString=(UChar*)malloc(sizeof(UChar) * (myStrlen+1) );
92 * udat_format(dfmt, myDate, myString, myStrlen+1, &pos, &status);
94 * printf("date format: %s\n", u_austrcpy(buffer, myString));
95 * buffer[pos.endIndex] = 0; // NULL terminate the string.
96 * printf("UFieldPosition position equals %s\n", &buffer[pos.beginIndex]);
99 * To format a date for a different Locale, specify it in the call to
103 * UDateFormat* df = udat_open(UDAT_SHORT, UDAT_SHORT, "fr_FR", NULL, -1, NULL, 0, &status);
106 * You can use a DateFormat API udat_parse() to parse.
109 * UErrorCode status = U_ZERO_ERROR;
110 * int32_t parsepos=0;
111 * UDate myDate = udat_parse(df, myString, u_strlen(myString), &parsepos, &status);
114 * You can pass in different options for the arguments for date and time style
115 * to control the length of the result; from SHORT to MEDIUM to LONG to FULL.
116 * The exact result depends on the locale, but generally:
117 * see UDateFormatStyle for more details
119 * <li> UDAT_SHORT is completely numeric, such as 12/13/52 or 3:30pm
120 * <li> UDAT_MEDIUM is longer, such as Jan 12, 1952
121 * <li> UDAT_LONG is longer, such as January 12, 1952 or 3:30:32pm
122 * <li> UDAT_FULL is pretty completely specified, such as
123 * Tuesday, April 12, 1952 AD or 3:30:42pm PST.
125 * You can also set the time zone on the format if you wish.
127 * You can also use forms of the parse and format methods with Parse Position and
128 * UFieldPosition to allow you to
130 * <li> Progressively parse through pieces of a string.
131 * <li> Align any particular field, or find out where it is for selection
136 /** A date formatter.
137 * For usage in C programs.
140 typedef void* UDateFormat
;
142 /** The possible date/time format styles
145 typedef enum UDateFormatStyle
{
155 UDAT_DEFAULT
= UDAT_MEDIUM
,
157 /** Bitfield for relative date */
158 UDAT_RELATIVE
= (1 << 7),
160 UDAT_FULL_RELATIVE
= UDAT_FULL
| UDAT_RELATIVE
,
162 UDAT_LONG_RELATIVE
= UDAT_LONG
| UDAT_RELATIVE
,
164 UDAT_MEDIUM_RELATIVE
= UDAT_MEDIUM
| UDAT_RELATIVE
,
166 UDAT_SHORT_RELATIVE
= UDAT_SHORT
| UDAT_RELATIVE
,
172 #ifndef U_HIDE_DRAFT_API
174 * Use the pattern given in the parameter to udat_open
180 /** @internal alias to UDAT_PATTERN */
181 UDAT_IGNORE
= UDAT_PATTERN
182 #endif /* U_HIDE_DRAFT_API */
185 // Skeletons for dates.
188 * Constant for date skeleton with year.
191 #define UDAT_YEAR "y"
192 #ifndef U_HIDE_DRAFT_API
194 * Constant for date skeleton with quarter.
197 #define UDAT_QUARTER "QQQQ"
199 * Constant for date skeleton with abbreviated quarter.
202 #define UDAT_ABBR_QUARTER "QQQ"
203 #endif /* U_HIDE_DRAFT_API */
205 * Constant for date skeleton with year and quarter.
208 #define UDAT_YEAR_QUARTER "yQQQQ"
210 * Constant for date skeleton with year and abbreviated quarter.
213 #define UDAT_YEAR_ABBR_QUARTER "yQQQ"
215 * Constant for date skeleton with month.
218 #define UDAT_MONTH "MMMM"
220 * Constant for date skeleton with abbreviated month.
223 #define UDAT_ABBR_MONTH "MMM"
225 * Constant for date skeleton with numeric month.
228 #define UDAT_NUM_MONTH "M"
230 * Constant for date skeleton with year and month.
233 #define UDAT_YEAR_MONTH "yMMMM"
235 * Constant for date skeleton with year and abbreviated month.
238 #define UDAT_YEAR_ABBR_MONTH "yMMM"
240 * Constant for date skeleton with year and numeric month.
243 #define UDAT_YEAR_NUM_MONTH "yM"
245 * Constant for date skeleton with day.
250 * Constant for date skeleton with year, month, and day.
251 * Used in combinations date + time, date + time + zone, or time + zone.
254 #define UDAT_YEAR_MONTH_DAY "yMMMMd"
256 * Constant for date skeleton with year, abbreviated month, and day.
257 * Used in combinations date + time, date + time + zone, or time + zone.
260 #define UDAT_YEAR_ABBR_MONTH_DAY "yMMMd"
262 * Constant for date skeleton with year, numeric month, and day.
263 * Used in combinations date + time, date + time + zone, or time + zone.
266 #define UDAT_YEAR_NUM_MONTH_DAY "yMd"
267 #ifndef U_HIDE_DRAFT_API
269 * Constant for date skeleton with weekday.
272 #define UDAT_WEEKDAY "EEEE"
274 * Constant for date skeleton with abbreviated weekday.
277 #define UDAT_ABBR_WEEKDAY "E"
278 #endif /* U_HIDE_DRAFT_API */
280 * Constant for date skeleton with year, month, weekday, and day.
281 * Used in combinations date + time, date + time + zone, or time + zone.
284 #define UDAT_YEAR_MONTH_WEEKDAY_DAY "yMMMMEEEEd"
286 * Constant for date skeleton with year, abbreviated month, weekday, and day.
287 * Used in combinations date + time, date + time + zone, or time + zone.
290 #define UDAT_YEAR_ABBR_MONTH_WEEKDAY_DAY "yMMMEd"
292 * Constant for date skeleton with year, numeric month, weekday, and day.
293 * Used in combinations date + time, date + time + zone, or time + zone.
296 #define UDAT_YEAR_NUM_MONTH_WEEKDAY_DAY "yMEd"
298 * Constant for date skeleton with long month and day.
299 * Used in combinations date + time, date + time + zone, or time + zone.
302 #define UDAT_MONTH_DAY "MMMMd"
304 * Constant for date skeleton with abbreviated month and day.
305 * Used in combinations date + time, date + time + zone, or time + zone.
308 #define UDAT_ABBR_MONTH_DAY "MMMd"
310 * Constant for date skeleton with numeric month and day.
311 * Used in combinations date + time, date + time + zone, or time + zone.
314 #define UDAT_NUM_MONTH_DAY "Md"
316 * Constant for date skeleton with month, weekday, and day.
317 * Used in combinations date + time, date + time + zone, or time + zone.
320 #define UDAT_MONTH_WEEKDAY_DAY "MMMMEEEEd"
322 * Constant for date skeleton with abbreviated month, weekday, and day.
323 * Used in combinations date + time, date + time + zone, or time + zone.
326 #define UDAT_ABBR_MONTH_WEEKDAY_DAY "MMMEd"
328 * Constant for date skeleton with numeric month, weekday, and day.
329 * Used in combinations date + time, date + time + zone, or time + zone.
332 #define UDAT_NUM_MONTH_WEEKDAY_DAY "MEd"
334 // Skeletons for times.
337 * Constant for date skeleton with hour, with the locale's preferred hour format (12 or 24).
340 #define UDAT_HOUR "j"
341 #ifndef U_HIDE_DRAFT_API
343 * Constant for date skeleton with hour in 24-hour presentation.
346 #define UDAT_HOUR24 "H"
348 * Constant for date skeleton with minute.
351 #define UDAT_MINUTE "m"
352 #endif /* U_HIDE_DRAFT_API */
354 * Constant for date skeleton with hour and minute, with the locale's preferred hour format (12 or 24).
355 * Used in combinations date + time, date + time + zone, or time + zone.
358 #define UDAT_HOUR_MINUTE "jm"
360 * Constant for date skeleton with hour and minute in 24-hour presentation.
361 * Used in combinations date + time, date + time + zone, or time + zone.
364 #define UDAT_HOUR24_MINUTE "Hm"
365 #ifndef U_HIDE_DRAFT_API
367 * Constant for date skeleton with second.
370 #define UDAT_SECOND "s"
371 #endif /* U_HIDE_DRAFT_API */
373 * Constant for date skeleton with hour, minute, and second,
374 * with the locale's preferred hour format (12 or 24).
375 * Used in combinations date + time, date + time + zone, or time + zone.
378 #define UDAT_HOUR_MINUTE_SECOND "jms"
380 * Constant for date skeleton with hour, minute, and second in
381 * 24-hour presentation.
382 * Used in combinations date + time, date + time + zone, or time + zone.
385 #define UDAT_HOUR24_MINUTE_SECOND "Hms"
387 * Constant for date skeleton with minute and second.
388 * Used in combinations date + time, date + time + zone, or time + zone.
391 #define UDAT_MINUTE_SECOND "ms"
393 // Skeletons for time zones.
395 #ifndef U_HIDE_DRAFT_API
397 * Constant for <i>generic location format</i>, such as Los Angeles Time;
398 * used in combinations date + time + zone, or time + zone.
399 * @see <a href="http://unicode.org/reports/tr35/#Date_Format_Patterns">LDML Date Format Patterns</a>
400 * @see <a href="http://unicode.org/reports/tr35/#Time_Zone_Fallback">LDML Time Zone Fallback</a>
403 #define UDAT_LOCATION_TZ "VVVV"
405 * Constant for <i>generic non-location format</i>, such as Pacific Time;
406 * used in combinations date + time + zone, or time + zone.
407 * @see <a href="http://unicode.org/reports/tr35/#Date_Format_Patterns">LDML Date Format Patterns</a>
408 * @see <a href="http://unicode.org/reports/tr35/#Time_Zone_Fallback">LDML Time Zone Fallback</a>
411 #define UDAT_GENERIC_TZ "vvvv"
413 * Constant for <i>generic non-location format</i>, abbreviated if possible, such as PT;
414 * used in combinations date + time + zone, or time + zone.
415 * @see <a href="http://unicode.org/reports/tr35/#Date_Format_Patterns">LDML Date Format Patterns</a>
416 * @see <a href="http://unicode.org/reports/tr35/#Time_Zone_Fallback">LDML Time Zone Fallback</a>
419 #define UDAT_ABBR_GENERIC_TZ "v"
421 * Constant for <i>specific non-location format</i>, such as Pacific Daylight Time;
422 * used in combinations date + time + zone, or time + zone.
423 * @see <a href="http://unicode.org/reports/tr35/#Date_Format_Patterns">LDML Date Format Patterns</a>
424 * @see <a href="http://unicode.org/reports/tr35/#Time_Zone_Fallback">LDML Time Zone Fallback</a>
427 #define UDAT_SPECIFIC_TZ "zzzz"
429 * Constant for <i>specific non-location format</i>, abbreviated if possible, such as PDT;
430 * used in combinations date + time + zone, or time + zone.
431 * @see <a href="http://unicode.org/reports/tr35/#Date_Format_Patterns">LDML Date Format Patterns</a>
432 * @see <a href="http://unicode.org/reports/tr35/#Time_Zone_Fallback">LDML Time Zone Fallback</a>
435 #define UDAT_ABBR_SPECIFIC_TZ "z"
437 * Constant for <i>localized GMT/UTC format</i>, such as GMT+8:00 or HPG-8:00;
438 * used in combinations date + time + zone, or time + zone.
439 * @see <a href="http://unicode.org/reports/tr35/#Date_Format_Patterns">LDML Date Format Patterns</a>
440 * @see <a href="http://unicode.org/reports/tr35/#Time_Zone_Fallback">LDML Time Zone Fallback</a>
443 #define UDAT_ABBR_UTC_TZ "ZZZZ"
444 #endif /* U_HIDE_DRAFT_API */
446 // deprecated skeleton constants
448 #ifndef U_HIDE_DEPRECATED_API
450 * Constant for date skeleton with standalone month.
451 * @deprecated ICU 50 Use UDAT_MONTH instead.
453 #define UDAT_STANDALONE_MONTH "LLLL"
455 * Constant for date skeleton with standalone abbreviated month.
456 * @deprecated ICU 50 Use UDAT_ABBR_MONTH instead.
458 #define UDAT_ABBR_STANDALONE_MONTH "LLL"
461 * Constant for date skeleton with hour, minute, and generic timezone.
462 * @deprecated ICU 50 Use instead UDAT_HOUR_MINUTE UDAT_ABBR_GENERIC_TZ or some other timezone presentation.
464 #define UDAT_HOUR_MINUTE_GENERIC_TZ "jmv"
466 * Constant for date skeleton with hour, minute, and timezone.
467 * @deprecated ICU 50 Use instead UDAT_HOUR_MINUTE UDAT_ABBR_SPECIFIC_TZ or some other timezone presentation.
469 #define UDAT_HOUR_MINUTE_TZ "jmz"
471 * Constant for date skeleton with hour and generic timezone.
472 * @deprecated ICU 50 Use instead UDAT_HOUR UDAT_ABBR_GENERIC_TZ or some other timezone presentation.
474 #define UDAT_HOUR_GENERIC_TZ "jv"
476 * Constant for date skeleton with hour and timezone.
477 * @deprecated ICU 50 Use instead UDAT_HOUR UDAT_ABBR_SPECIFIC_TZ or some other timezone presentation.
479 #define UDAT_HOUR_TZ "jz"
480 #endif /* U_HIDE_DEPRECATED_API */
483 * FieldPosition and UFieldPosition selectors for format fields
484 * defined by DateFormat and UDateFormat.
487 typedef enum UDateFormatField
{
489 * FieldPosition and UFieldPosition selector for 'G' field alignment,
490 * corresponding to the UCAL_ERA field.
496 * FieldPosition and UFieldPosition selector for 'y' field alignment,
497 * corresponding to the UCAL_YEAR field.
503 * FieldPosition and UFieldPosition selector for 'M' field alignment,
504 * corresponding to the UCAL_MONTH field.
507 UDAT_MONTH_FIELD
= 2,
510 * FieldPosition and UFieldPosition selector for 'd' field alignment,
511 * corresponding to the UCAL_DATE field.
517 * FieldPosition and UFieldPosition selector for 'k' field alignment,
518 * corresponding to the UCAL_HOUR_OF_DAY field.
519 * UDAT_HOUR_OF_DAY1_FIELD is used for the one-based 24-hour clock.
520 * For example, 23:59 + 01:00 results in 24:59.
523 UDAT_HOUR_OF_DAY1_FIELD
= 4,
526 * FieldPosition and UFieldPosition selector for 'H' field alignment,
527 * corresponding to the UCAL_HOUR_OF_DAY field.
528 * UDAT_HOUR_OF_DAY0_FIELD is used for the zero-based 24-hour clock.
529 * For example, 23:59 + 01:00 results in 00:59.
532 UDAT_HOUR_OF_DAY0_FIELD
= 5,
535 * FieldPosition and UFieldPosition selector for 'm' field alignment,
536 * corresponding to the UCAL_MINUTE field.
539 UDAT_MINUTE_FIELD
= 6,
542 * FieldPosition and UFieldPosition selector for 's' field alignment,
543 * corresponding to the UCAL_SECOND field.
546 UDAT_SECOND_FIELD
= 7,
549 * FieldPosition and UFieldPosition selector for 'S' field alignment,
550 * corresponding to the UCAL_MILLISECOND field.
552 * Note: Time formats that use 'S' can display a maximum of three
553 * significant digits for fractional seconds, corresponding to millisecond
554 * resolution and a fractional seconds sub-pattern of SSS. If the
555 * sub-pattern is S or SS, the fractional seconds value will be truncated
556 * (not rounded) to the number of display places specified. If the
557 * fractional seconds sub-pattern is longer than SSS, the additional
558 * display places will be filled with zeros.
561 UDAT_FRACTIONAL_SECOND_FIELD
= 8,
564 * FieldPosition and UFieldPosition selector for 'E' field alignment,
565 * corresponding to the UCAL_DAY_OF_WEEK field.
568 UDAT_DAY_OF_WEEK_FIELD
= 9,
571 * FieldPosition and UFieldPosition selector for 'D' field alignment,
572 * corresponding to the UCAL_DAY_OF_YEAR field.
575 UDAT_DAY_OF_YEAR_FIELD
= 10,
578 * FieldPosition and UFieldPosition selector for 'F' field alignment,
579 * corresponding to the UCAL_DAY_OF_WEEK_IN_MONTH field.
582 UDAT_DAY_OF_WEEK_IN_MONTH_FIELD
= 11,
585 * FieldPosition and UFieldPosition selector for 'w' field alignment,
586 * corresponding to the UCAL_WEEK_OF_YEAR field.
589 UDAT_WEEK_OF_YEAR_FIELD
= 12,
592 * FieldPosition and UFieldPosition selector for 'W' field alignment,
593 * corresponding to the UCAL_WEEK_OF_MONTH field.
596 UDAT_WEEK_OF_MONTH_FIELD
= 13,
599 * FieldPosition and UFieldPosition selector for 'a' field alignment,
600 * corresponding to the UCAL_AM_PM field.
603 UDAT_AM_PM_FIELD
= 14,
606 * FieldPosition and UFieldPosition selector for 'h' field alignment,
607 * corresponding to the UCAL_HOUR field.
608 * UDAT_HOUR1_FIELD is used for the one-based 12-hour clock.
609 * For example, 11:30 PM + 1 hour results in 12:30 AM.
612 UDAT_HOUR1_FIELD
= 15,
615 * FieldPosition and UFieldPosition selector for 'K' field alignment,
616 * corresponding to the UCAL_HOUR field.
617 * UDAT_HOUR0_FIELD is used for the zero-based 12-hour clock.
618 * For example, 11:30 PM + 1 hour results in 00:30 AM.
621 UDAT_HOUR0_FIELD
= 16,
624 * FieldPosition and UFieldPosition selector for 'z' field alignment,
625 * corresponding to the UCAL_ZONE_OFFSET and
626 * UCAL_DST_OFFSET fields.
629 UDAT_TIMEZONE_FIELD
= 17,
632 * FieldPosition and UFieldPosition selector for 'Y' field alignment,
633 * corresponding to the UCAL_YEAR_WOY field.
636 UDAT_YEAR_WOY_FIELD
= 18,
639 * FieldPosition and UFieldPosition selector for 'e' field alignment,
640 * corresponding to the UCAL_DOW_LOCAL field.
643 UDAT_DOW_LOCAL_FIELD
= 19,
646 * FieldPosition and UFieldPosition selector for 'u' field alignment,
647 * corresponding to the UCAL_EXTENDED_YEAR field.
650 UDAT_EXTENDED_YEAR_FIELD
= 20,
653 * FieldPosition and UFieldPosition selector for 'g' field alignment,
654 * corresponding to the UCAL_JULIAN_DAY field.
657 UDAT_JULIAN_DAY_FIELD
= 21,
660 * FieldPosition and UFieldPosition selector for 'A' field alignment,
661 * corresponding to the UCAL_MILLISECONDS_IN_DAY field.
664 UDAT_MILLISECONDS_IN_DAY_FIELD
= 22,
667 * FieldPosition and UFieldPosition selector for 'Z' field alignment,
668 * corresponding to the UCAL_ZONE_OFFSET and
669 * UCAL_DST_OFFSET fields.
672 UDAT_TIMEZONE_RFC_FIELD
= 23,
675 * FieldPosition and UFieldPosition selector for 'v' field alignment,
676 * corresponding to the UCAL_ZONE_OFFSET field.
679 UDAT_TIMEZONE_GENERIC_FIELD
= 24,
681 * FieldPosition selector for 'c' field alignment,
682 * corresponding to the {@link #UCAL_DOW_LOCAL} field.
683 * This displays the stand alone day name, if available.
686 UDAT_STANDALONE_DAY_FIELD
= 25,
689 * FieldPosition selector for 'L' field alignment,
690 * corresponding to the {@link #UCAL_MONTH} field.
691 * This displays the stand alone month name, if available.
694 UDAT_STANDALONE_MONTH_FIELD
= 26,
697 * FieldPosition selector for "Q" field alignment,
698 * corresponding to quarters. This is implemented
699 * using the {@link #UCAL_MONTH} field. This
700 * displays the quarter.
703 UDAT_QUARTER_FIELD
= 27,
706 * FieldPosition selector for the "q" field alignment,
707 * corresponding to stand-alone quarters. This is
708 * implemented using the {@link #UCAL_MONTH} field.
709 * This displays the stand-alone quarter.
712 UDAT_STANDALONE_QUARTER_FIELD
= 28,
715 * FieldPosition and UFieldPosition selector for 'V' field alignment,
716 * corresponding to the UCAL_ZONE_OFFSET field.
719 UDAT_TIMEZONE_SPECIAL_FIELD
= 29,
722 * FieldPosition selector for "U" field alignment,
723 * corresponding to cyclic year names. This is implemented
724 * using the {@link #UCAL_YEAR} field. This displays
725 * the cyclic year name, if available.
728 UDAT_YEAR_NAME_FIELD
= 30,
730 #ifndef U_HIDE_DRAFT_API
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_OFFSETfields.
750 * This displays the ISO 8601 local time offset format.
753 UDAT_TIMEZONE_ISO_LOCAL_FIELD
= 33,
754 #endif /* U_HIDE_DRAFT_API */
757 * Number of FieldPosition and UFieldPosition selectors for
758 * DateFormat and UDateFormat.
759 * Valid selectors range from 0 to UDAT_FIELD_COUNT-1.
760 * This value is subject to change if new fields are defined
764 UDAT_FIELD_COUNT
= 34
770 * Maps from a UDateFormatField to the corresponding UCalendarDateFields.
771 * Note: since the mapping is many-to-one, there is no inverse mapping.
772 * @param field the UDateFormatField.
773 * @return the UCalendarDateField. This will be UCAL_FIELD_COUNT in case
774 * of error (e.g., the input field is UDAT_FIELD_COUNT).
777 U_STABLE UCalendarDateFields U_EXPORT2
778 udat_toCalendarDateField(UDateFormatField field
);
782 * Open a new UDateFormat for formatting and parsing dates and times.
783 * A UDateFormat may be used to format dates in calls to {@link #udat_format },
784 * and to parse dates in calls to {@link #udat_parse }.
785 * @param timeStyle The style used to format times; one of UDAT_FULL, UDAT_LONG,
786 * UDAT_MEDIUM, UDAT_SHORT, UDAT_DEFAULT, or UDAT_NONE (relative time styles
787 * are not currently supported).
788 * When the pattern parameter is used, pass in UDAT_PATTERN for both timeStyle and dateStyle.
789 * @param dateStyle The style used to format dates; one of UDAT_FULL, UDAT_LONG,
790 * UDAT_MEDIUM, UDAT_SHORT, UDAT_DEFAULT, UDAT_FULL_RELATIVE, UDAT_LONG_RELATIVE,
791 * UDAT_MEDIUM_RELATIVE, UDAT_SHORT_RELATIVE, or UDAT_NONE.
792 * When the pattern parameter is used, pass in UDAT_PATTERN for both timeStyle and dateStyle.
793 * As currently implemented,
794 * relative date formatting only affects a limited range of calendar days before or
795 * after the current date, based on the CLDR <field type="day">/<relative> data: For
796 * example, in English, "Yesterday", "Today", and "Tomorrow". Outside of this range,
797 * dates are formatted using the corresponding non-relative style.
798 * @param locale The locale specifying the formatting conventions
799 * @param tzID A timezone ID specifying the timezone to use. If 0, use
800 * the default timezone.
801 * @param tzIDLength The length of tzID, or -1 if null-terminated.
802 * @param pattern A pattern specifying the format to use.
803 * @param patternLength The number of characters in the pattern, or -1 if null-terminated.
804 * @param status A pointer to an UErrorCode to receive any errors
805 * @return A pointer to a UDateFormat to use for formatting dates and times, or 0 if
809 U_STABLE UDateFormat
* U_EXPORT2
810 udat_open(UDateFormatStyle timeStyle
,
811 UDateFormatStyle dateStyle
,
815 const UChar
*pattern
,
816 int32_t patternLength
,
821 * Close a UDateFormat.
822 * Once closed, a UDateFormat may no longer be used.
823 * @param format The formatter to close.
826 U_STABLE
void U_EXPORT2
827 udat_close(UDateFormat
* format
);
829 #if U_SHOW_CPLUSPLUS_API
834 * \class LocalUDateFormatPointer
835 * "Smart pointer" class, closes a UDateFormat via udat_close().
836 * For most methods see the LocalPointerBase base class.
838 * @see LocalPointerBase
842 U_DEFINE_LOCAL_OPEN_POINTER(LocalUDateFormatPointer
, UDateFormat
, udat_close
);
849 * Open a copy of a UDateFormat.
850 * This function performs a deep copy.
851 * @param fmt The format to copy
852 * @param status A pointer to an UErrorCode to receive any errors.
853 * @return A pointer to a UDateFormat identical to fmt.
856 U_STABLE UDateFormat
* U_EXPORT2
857 udat_clone(const UDateFormat
*fmt
,
861 * Format a date using an UDateFormat.
862 * The date will be formatted using the conventions specified in {@link #udat_open }
863 * @param format The formatter to use
864 * @param dateToFormat The date to format
865 * @param result A pointer to a buffer to receive the formatted number.
866 * @param resultLength The maximum size of result.
867 * @param position A pointer to a UFieldPosition. On input, position->field
868 * is read. On output, position->beginIndex and position->endIndex indicate
869 * the beginning and ending indices of field number position->field, if such
870 * a field exists. This parameter may be NULL, in which case no field
871 * position data is returned.
872 * @param status A pointer to an UErrorCode to receive any errors
873 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
875 * @see UFieldPosition
878 U_STABLE
int32_t U_EXPORT2
879 udat_format( const UDateFormat
* format
,
882 int32_t resultLength
,
883 UFieldPosition
* position
,
887 * Parse a string into an date/time using a UDateFormat.
888 * The date will be parsed using the conventions specified in {@link #udat_open }.
890 * Note that the normal date formats associated with some calendars - such
891 * as the Chinese lunar calendar - do not specify enough fields to enable
892 * dates to be parsed unambiguously. In the case of the Chinese lunar
893 * calendar, while the year within the current 60-year cycle is specified,
894 * the number of such cycles since the start date of the calendar (in the
895 * UCAL_ERA field of the UCalendar object) is not normally part of the format,
896 * and parsing may assume the wrong era. For cases such as this it is
897 * recommended that clients parse using udat_parseCalendar with the UCalendar
898 * passed in set to the current date, or to a date within the era/cycle that
899 * should be assumed if absent in the format.
901 * @param format The formatter to use.
902 * @param text The text to parse.
903 * @param textLength The length of text, or -1 if null-terminated.
904 * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which
905 * to begin parsing. If not 0, on output the offset at which parsing ended.
906 * @param status A pointer to an UErrorCode to receive any errors
907 * @return The value of the parsed date/time
911 U_STABLE UDate U_EXPORT2
912 udat_parse(const UDateFormat
* format
,
919 * Parse a string into an date/time using a UDateFormat.
920 * The date will be parsed using the conventions specified in {@link #udat_open }.
921 * @param format The formatter to use.
922 * @param calendar A calendar set on input to the date and time to be used for
923 * missing values in the date/time string being parsed, and set
924 * on output to the parsed date/time. When the calendar type is
925 * different from the internal calendar held by the UDateFormat
926 * instance, the internal calendar will be cloned to a work
927 * calendar set to the same milliseconds and time zone as this
928 * calendar parameter, field values will be parsed based on the
929 * work calendar, then the result (milliseconds and time zone)
930 * will be set in this calendar.
931 * @param text The text to parse.
932 * @param textLength The length of text, or -1 if null-terminated.
933 * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which
934 * to begin parsing. If not 0, on output the offset at which parsing ended.
935 * @param status A pointer to an UErrorCode to receive any errors
939 U_STABLE
void U_EXPORT2
940 udat_parseCalendar(const UDateFormat
* format
,
948 * Determine if an UDateFormat will perform lenient parsing.
949 * With lenient parsing, the parser may use heuristics to interpret inputs that do not
950 * precisely match the pattern. With strict parsing, inputs must match the pattern.
951 * @param fmt The formatter to query
952 * @return TRUE if fmt is set to perform lenient parsing, FALSE otherwise.
953 * @see udat_setLenient
956 U_STABLE UBool U_EXPORT2
957 udat_isLenient(const UDateFormat
* fmt
);
960 * Specify whether an UDateFormat will perform lenient parsing.
961 * With lenient parsing, the parser may use heuristics to interpret inputs that do not
962 * precisely match the pattern. With strict parsing, inputs must match the pattern.
963 * @param fmt The formatter to set
964 * @param isLenient TRUE if fmt should perform lenient parsing, FALSE otherwise.
968 U_STABLE
void U_EXPORT2
969 udat_setLenient( UDateFormat
* fmt
,
973 * Get the UCalendar associated with an UDateFormat.
974 * A UDateFormat uses a UCalendar to convert a raw value to, for example,
975 * the day of the week.
976 * @param fmt The formatter to query.
977 * @return A pointer to the UCalendar used by fmt.
978 * @see udat_setCalendar
981 U_STABLE
const UCalendar
* U_EXPORT2
982 udat_getCalendar(const UDateFormat
* fmt
);
985 * Set the UCalendar associated with an UDateFormat.
986 * A UDateFormat uses a UCalendar to convert a raw value to, for example,
987 * the day of the week.
988 * @param fmt The formatter to set.
989 * @param calendarToSet A pointer to an UCalendar to be used by fmt.
990 * @see udat_setCalendar
993 U_STABLE
void U_EXPORT2
994 udat_setCalendar( UDateFormat
* fmt
,
995 const UCalendar
* calendarToSet
);
998 * Get the UNumberFormat associated with an UDateFormat.
999 * A UDateFormat uses a UNumberFormat to format numbers within a date,
1000 * for example the day number.
1001 * @param fmt The formatter to query.
1002 * @return A pointer to the UNumberFormat used by fmt to format numbers.
1003 * @see udat_setNumberFormat
1006 U_STABLE
const UNumberFormat
* U_EXPORT2
1007 udat_getNumberFormat(const UDateFormat
* fmt
);
1010 * Set the UNumberFormat associated with an UDateFormat.
1011 * A UDateFormat uses a UNumberFormat to format numbers within a date,
1012 * for example the day number.
1013 * @param fmt The formatter to set.
1014 * @param numberFormatToSet A pointer to the UNumberFormat to be used by fmt to format numbers.
1015 * @see udat_getNumberFormat
1018 U_STABLE
void U_EXPORT2
1019 udat_setNumberFormat( UDateFormat
* fmt
,
1020 const UNumberFormat
* numberFormatToSet
);
1023 * Get a locale for which date/time formatting patterns are available.
1024 * A UDateFormat in a locale returned by this function will perform the correct
1025 * formatting and parsing for the locale.
1026 * @param localeIndex The index of the desired locale.
1027 * @return A locale for which date/time formatting patterns are available, or 0 if none.
1028 * @see udat_countAvailable
1031 U_STABLE
const char* U_EXPORT2
1032 udat_getAvailable(int32_t localeIndex
);
1035 * Determine how many locales have date/time formatting patterns available.
1036 * This function is most useful as determining the loop ending condition for
1037 * calls to {@link #udat_getAvailable }.
1038 * @return The number of locales for which date/time formatting patterns are available.
1039 * @see udat_getAvailable
1042 U_STABLE
int32_t U_EXPORT2
1043 udat_countAvailable(void);
1046 * Get the year relative to which all 2-digit years are interpreted.
1047 * For example, if the 2-digit start year is 2100, the year 99 will be
1048 * interpreted as 2199.
1049 * @param fmt The formatter to query.
1050 * @param status A pointer to an UErrorCode to receive any errors
1051 * @return The year relative to which all 2-digit years are interpreted.
1052 * @see udat_Set2DigitYearStart
1055 U_STABLE UDate U_EXPORT2
1056 udat_get2DigitYearStart( const UDateFormat
*fmt
,
1057 UErrorCode
*status
);
1060 * Set the year relative to which all 2-digit years will be interpreted.
1061 * For example, if the 2-digit start year is 2100, the year 99 will be
1062 * interpreted as 2199.
1063 * @param fmt The formatter to set.
1064 * @param d The year relative to which all 2-digit years will be interpreted.
1065 * @param status A pointer to an UErrorCode to receive any errors
1066 * @see udat_Set2DigitYearStart
1069 U_STABLE
void U_EXPORT2
1070 udat_set2DigitYearStart( UDateFormat
*fmt
,
1072 UErrorCode
*status
);
1075 * Extract the pattern from a UDateFormat.
1076 * The pattern will follow the pattern syntax rules.
1077 * @param fmt The formatter to query.
1078 * @param localized TRUE if the pattern should be localized, FALSE otherwise.
1079 * @param result A pointer to a buffer to receive the pattern.
1080 * @param resultLength The maximum size of result.
1081 * @param status A pointer to an UErrorCode to receive any errors
1082 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
1083 * @see udat_applyPattern
1086 U_STABLE
int32_t U_EXPORT2
1087 udat_toPattern( const UDateFormat
*fmt
,
1090 int32_t resultLength
,
1091 UErrorCode
*status
);
1094 * Set the pattern used by an UDateFormat.
1095 * The pattern should follow the pattern syntax rules.
1096 * @param format The formatter to set.
1097 * @param localized TRUE if the pattern is localized, FALSE otherwise.
1098 * @param pattern The new pattern
1099 * @param patternLength The length of pattern, or -1 if null-terminated.
1100 * @see udat_toPattern
1103 U_STABLE
void U_EXPORT2
1104 udat_applyPattern( UDateFormat
*format
,
1106 const UChar
*pattern
,
1107 int32_t patternLength
);
1110 * The possible types of date format symbols
1113 typedef enum UDateFormatSymbolType
{
1114 /** The era names, for example AD */
1116 /** The month names, for example February */
1118 /** The short month names, for example Feb. */
1120 /** The CLDR-style format "wide" weekday names, for example Monday */
1123 * The CLDR-style format "abbreviated" (not "short") weekday names, for example "Mon."
1124 * For the CLDR-style format "short" weekday names, use UDAT_SHORTER_WEEKDAYS.
1126 UDAT_SHORT_WEEKDAYS
,
1127 /** The AM/PM names, for example AM */
1129 /** The localized characters */
1130 UDAT_LOCALIZED_CHARS
,
1131 /** The long era names, for example Anno Domini */
1133 /** The narrow month names, for example F */
1135 /** The CLDR-style format "narrow" weekday names, for example "M" */
1136 UDAT_NARROW_WEEKDAYS
,
1137 /** Standalone context versions of months */
1138 UDAT_STANDALONE_MONTHS
,
1139 UDAT_STANDALONE_SHORT_MONTHS
,
1140 UDAT_STANDALONE_NARROW_MONTHS
,
1141 /** The CLDR-style stand-alone "wide" weekday names */
1142 UDAT_STANDALONE_WEEKDAYS
,
1144 * The CLDR-style stand-alone "abbreviated" (not "short") weekday names.
1145 * For the CLDR-style stand-alone "short" weekday names, use UDAT_STANDALONE_SHORTER_WEEKDAYS.
1147 UDAT_STANDALONE_SHORT_WEEKDAYS
,
1148 /** The CLDR-style stand-alone "narrow" weekday names */
1149 UDAT_STANDALONE_NARROW_WEEKDAYS
,
1150 /** The quarters, for example 1st Quarter */
1152 /** The short quarter names, for example Q1 */
1153 UDAT_SHORT_QUARTERS
,
1154 /** Standalone context versions of quarters */
1155 UDAT_STANDALONE_QUARTERS
,
1156 UDAT_STANDALONE_SHORT_QUARTERS
,
1157 #ifndef U_HIDE_DRAFT_API
1159 * The CLDR-style short weekday names, e.g. "Su", Mo", etc.
1160 * These are named "SHORTER" to contrast with the constants using _SHORT_
1161 * above, which actually get the CLDR-style *abbreviated* versions of the
1162 * corresponding names.
1165 UDAT_SHORTER_WEEKDAYS
,
1167 * Standalone version of UDAT_SHORTER_WEEKDAYS.
1170 UDAT_STANDALONE_SHORTER_WEEKDAYS
1171 #endif /* U_HIDE_DRAFT_API */
1172 } UDateFormatSymbolType
;
1174 struct UDateFormatSymbols
;
1175 /** Date format symbols.
1176 * For usage in C programs.
1179 typedef struct UDateFormatSymbols UDateFormatSymbols
;
1182 * Get the symbols associated with an UDateFormat.
1183 * The symbols are what a UDateFormat uses to represent locale-specific data,
1184 * for example month or day names.
1185 * @param fmt The formatter to query.
1186 * @param type The type of symbols to get. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS,
1187 * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS
1188 * @param symbolIndex The desired symbol of type type.
1189 * @param result A pointer to a buffer to receive the pattern.
1190 * @param resultLength The maximum size of result.
1191 * @param status A pointer to an UErrorCode to receive any errors
1192 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
1193 * @see udat_countSymbols
1194 * @see udat_setSymbols
1197 U_STABLE
int32_t U_EXPORT2
1198 udat_getSymbols(const UDateFormat
*fmt
,
1199 UDateFormatSymbolType type
,
1200 int32_t symbolIndex
,
1202 int32_t resultLength
,
1203 UErrorCode
*status
);
1206 * Count the number of particular symbols for an UDateFormat.
1207 * This function is most useful as for detemining the loop termination condition
1208 * for calls to {@link #udat_getSymbols }.
1209 * @param fmt The formatter to query.
1210 * @param type The type of symbols to count. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS,
1211 * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS
1212 * @return The number of symbols of type type.
1213 * @see udat_getSymbols
1214 * @see udat_setSymbols
1217 U_STABLE
int32_t U_EXPORT2
1218 udat_countSymbols( const UDateFormat
*fmt
,
1219 UDateFormatSymbolType type
);
1222 * Set the symbols associated with an UDateFormat.
1223 * The symbols are what a UDateFormat uses to represent locale-specific data,
1224 * for example month or day names.
1225 * @param format The formatter to set
1226 * @param type The type of symbols to set. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS,
1227 * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS
1228 * @param symbolIndex The index of the symbol to set of type type.
1229 * @param value The new value
1230 * @param valueLength The length of value, or -1 if null-terminated
1231 * @param status A pointer to an UErrorCode to receive any errors
1232 * @see udat_getSymbols
1233 * @see udat_countSymbols
1236 U_STABLE
void U_EXPORT2
1237 udat_setSymbols( UDateFormat
*format
,
1238 UDateFormatSymbolType type
,
1239 int32_t symbolIndex
,
1241 int32_t valueLength
,
1242 UErrorCode
*status
);
1245 * Get the locale for this date format object.
1246 * You can choose between valid and actual locale.
1247 * @param fmt The formatter to get the locale from
1248 * @param type type of the locale we're looking for (valid or actual)
1249 * @param status error code for the operation
1250 * @return the locale name
1253 U_STABLE
const char* U_EXPORT2
1254 udat_getLocaleByType(const UDateFormat
*fmt
,
1255 ULocDataLocaleType type
,
1256 UErrorCode
* status
);
1258 #ifndef U_HIDE_DRAFT_API
1260 * Set a particular UDisplayContext value in the formatter, such as
1261 * UDISPCTX_CAPITALIZATION_FOR_STANDALONE.
1262 * @param fmt The formatter for which to set a UDisplayContext value.
1263 * @param value The UDisplayContext value to set.
1264 * @param status A pointer to an UErrorCode to receive any errors
1267 U_DRAFT
void U_EXPORT2
1268 udat_setContext(UDateFormat
* fmt
, UDisplayContext value
, UErrorCode
* status
);
1271 * Get the formatter's UDisplayContext value for the specified UDisplayContextType,
1272 * such as UDISPCTX_TYPE_CAPITALIZATION.
1273 * @param fmt The formatter to query.
1274 * @param type The UDisplayContextType whose value to return
1275 * @param status A pointer to an UErrorCode to receive any errors
1276 * @return The UDisplayContextValue for the specified type.
1279 U_DRAFT UDisplayContext U_EXPORT2
1280 udat_getContext(UDateFormat
* fmt
, UDisplayContextType type
, UErrorCode
* status
);
1282 #endif /* U_HIDE_DRAFT_API */
1284 #ifndef U_HIDE_INTERNAL_API
1286 * Extract the date pattern from a UDateFormat set for relative date formatting.
1287 * The pattern will follow the pattern syntax rules.
1288 * @param fmt The formatter to query.
1289 * @param result A pointer to a buffer to receive the pattern.
1290 * @param resultLength The maximum size of result.
1291 * @param status A pointer to a UErrorCode to receive any errors
1292 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
1293 * @see udat_applyPatternRelative
1294 * @internal ICU 4.2 technology preview
1296 U_INTERNAL
int32_t U_EXPORT2
1297 udat_toPatternRelativeDate(const UDateFormat
*fmt
,
1299 int32_t resultLength
,
1300 UErrorCode
*status
);
1303 * Extract the time pattern from a UDateFormat set for relative date formatting.
1304 * The pattern will follow the pattern syntax rules.
1305 * @param fmt The formatter to query.
1306 * @param result A pointer to a buffer to receive the pattern.
1307 * @param resultLength The maximum size of result.
1308 * @param status A pointer to a UErrorCode to receive any errors
1309 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
1310 * @see udat_applyPatternRelative
1311 * @internal ICU 4.2 technology preview
1313 U_INTERNAL
int32_t U_EXPORT2
1314 udat_toPatternRelativeTime(const UDateFormat
*fmt
,
1316 int32_t resultLength
,
1317 UErrorCode
*status
);
1320 * Set the date & time patterns used by a UDateFormat set for relative date formatting.
1321 * The patterns should follow the pattern syntax rules.
1322 * @param format The formatter to set.
1323 * @param datePattern The new date pattern
1324 * @param datePatternLength The length of datePattern, or -1 if null-terminated.
1325 * @param timePattern The new time pattern
1326 * @param timePatternLength The length of timePattern, or -1 if null-terminated.
1327 * @param status A pointer to a UErrorCode to receive any errors
1328 * @see udat_toPatternRelativeDate, udat_toPatternRelativeTime
1329 * @internal ICU 4.2 technology preview
1331 U_INTERNAL
void U_EXPORT2
1332 udat_applyPatternRelative(UDateFormat
*format
,
1333 const UChar
*datePattern
,
1334 int32_t datePatternLength
,
1335 const UChar
*timePattern
,
1336 int32_t timePatternLength
,
1337 UErrorCode
*status
);
1343 typedef UDateFormat
* (U_EXPORT2
*UDateFormatOpener
) (UDateFormatStyle timeStyle
,
1344 UDateFormatStyle dateStyle
,
1348 const UChar
*pattern
,
1349 int32_t patternLength
,
1350 UErrorCode
*status
);
1353 * Register a provider factory
1356 U_INTERNAL
void U_EXPORT2
1357 udat_registerOpener(UDateFormatOpener opener
, UErrorCode
*status
);
1360 * Un-Register a provider factory
1363 U_INTERNAL UDateFormatOpener U_EXPORT2
1364 udat_unregisterOpener(UDateFormatOpener opener
, UErrorCode
*status
);
1365 #endif /* U_HIDE_INTERNAL_API */
1368 #endif /* #if !UCONFIG_NO_FORMATTING */