2 *******************************************************************************
3 * Copyright (C) 1996-2012, 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"
20 * \brief C API: DateFormat
22 * <h2> Date Format C API</h2>
24 * Date Format C API consists of functions that convert dates and
25 * times from their internal representations to textual form and back again in a
26 * language-independent manner. Converting from the internal representation (milliseconds
27 * since midnight, January 1, 1970) to text is known as "formatting," and converting
28 * from text to millis is known as "parsing." We currently define only one concrete
29 * structure UDateFormat, which can handle pretty much all normal
30 * date formatting and parsing actions.
32 * Date Format helps you to format and parse dates for any locale. Your code can
33 * be completely independent of the locale conventions for months, days of the
34 * week, or even the calendar format: lunar vs. solar.
36 * To format a date for the current Locale with default time and date style,
37 * use one of the static factory methods:
40 * UErrorCode status = U_ZERO_ERROR;
42 * int32_t myStrlen = 0;
43 * UDateFormat* dfmt = udat_open(UDAT_DEFAULT, UDAT_DEFAULT, NULL, NULL, -1, NULL, -1, &status);
44 * myStrlen = udat_format(dfmt, myDate, NULL, myStrlen, NULL, &status);
45 * if (status==U_BUFFER_OVERFLOW_ERROR){
46 * status=U_ZERO_ERROR;
47 * myString=(UChar*)malloc(sizeof(UChar) * (myStrlen+1) );
48 * udat_format(dfmt, myDate, myString, myStrlen+1, NULL, &status);
52 * If you are formatting multiple numbers, it is more efficient to get the
53 * format and use it multiple times so that the system doesn't have to fetch the
54 * information about the local language and country conventions multiple times.
57 * UErrorCode status = U_ZERO_ERROR;
58 * int32_t i, myStrlen = 0;
61 * UDate myDateArr[] = { 0.0, 100000000.0, 2000000000.0 }; // test values
62 * UDateFormat* df = udat_open(UDAT_DEFAULT, UDAT_DEFAULT, NULL, NULL, -1, NULL, 0, &status);
63 * for (i = 0; i < 3; i++) {
64 * myStrlen = udat_format(df, myDateArr[i], NULL, myStrlen, NULL, &status);
65 * if(status == U_BUFFER_OVERFLOW_ERROR){
66 * status = U_ZERO_ERROR;
67 * myString = (UChar*)malloc(sizeof(UChar) * (myStrlen+1) );
68 * udat_format(df, myDateArr[i], myString, myStrlen+1, NULL, &status);
69 * printf("%s\n", u_austrcpy(buffer, myString) );
75 * To get specific fields of a date, you can use UFieldPosition to
76 * get specific fields.
79 * UErrorCode status = U_ZERO_ERROR;
82 * int32_t myStrlen = 0;
85 * pos.field = 1; // Same as the DateFormat::EField enum
86 * UDateFormat* dfmt = udat_open(UDAT_DEFAULT, UDAT_DEFAULT, NULL, -1, NULL, 0, &status);
87 * myStrlen = udat_format(dfmt, myDate, NULL, myStrlen, &pos, &status);
88 * if (status==U_BUFFER_OVERFLOW_ERROR){
89 * status=U_ZERO_ERROR;
90 * myString=(UChar*)malloc(sizeof(UChar) * (myStrlen+1) );
91 * udat_format(dfmt, myDate, myString, myStrlen+1, &pos, &status);
93 * printf("date format: %s\n", u_austrcpy(buffer, myString));
94 * buffer[pos.endIndex] = 0; // NULL terminate the string.
95 * printf("UFieldPosition position equals %s\n", &buffer[pos.beginIndex]);
98 * To format a date for a different Locale, specify it in the call to
102 * UDateFormat* df = udat_open(UDAT_SHORT, UDAT_SHORT, "fr_FR", NULL, -1, NULL, 0, &status);
105 * You can use a DateFormat API udat_parse() to parse.
108 * UErrorCode status = U_ZERO_ERROR;
109 * int32_t parsepos=0;
110 * UDate myDate = udat_parse(df, myString, u_strlen(myString), &parsepos, &status);
113 * You can pass in different options for the arguments for date and time style
114 * to control the length of the result; from SHORT to MEDIUM to LONG to FULL.
115 * The exact result depends on the locale, but generally:
116 * see UDateFormatStyle for more details
118 * <li> UDAT_SHORT is completely numeric, such as 12/13/52 or 3:30pm
119 * <li> UDAT_MEDIUM is longer, such as Jan 12, 1952
120 * <li> UDAT_LONG is longer, such as January 12, 1952 or 3:30:32pm
121 * <li> UDAT_FULL is pretty completely specified, such as
122 * Tuesday, April 12, 1952 AD or 3:30:42pm PST.
124 * You can also set the time zone on the format if you wish.
126 * You can also use forms of the parse and format methods with Parse Position and
127 * UFieldPosition to allow you to
129 * <li> Progressively parse through pieces of a string.
130 * <li> Align any particular field, or find out where it is for selection
135 /** A date formatter.
136 * For usage in C programs.
139 typedef void* UDateFormat
;
141 /** The possible date/time format styles
144 typedef enum UDateFormatStyle
{
154 UDAT_DEFAULT
= UDAT_MEDIUM
,
156 /** Bitfield for relative date */
157 UDAT_RELATIVE
= (1 << 7),
159 UDAT_FULL_RELATIVE
= UDAT_FULL
| UDAT_RELATIVE
,
161 UDAT_LONG_RELATIVE
= UDAT_LONG
| UDAT_RELATIVE
,
163 UDAT_MEDIUM_RELATIVE
= UDAT_MEDIUM
| UDAT_RELATIVE
,
165 UDAT_SHORT_RELATIVE
= UDAT_SHORT
| UDAT_RELATIVE
,
170 /** for internal API use only */
175 /* Cannot use #ifndef U_HIDE_DRAFT_API for UDateFormatContextType and UDateFormatContextValue
176 * since a SimpleDateFormat virtual method & data member depends on them */
177 /** Date format context types
180 typedef enum UDateFormatContextType
{
182 * Type (key) for specifying the capitalization context for which a date
183 * is to be formatted (possible values are in UDateFormatContextValue).
186 UDAT_CAPITALIZATION
= 1
187 } UDateFormatContextType
;
189 /** Values for date format context types
192 typedef enum UDateFormatContextValue
{
193 /** Values for any UDateFormatContextType (key) */
195 * Value for any UDateFormatContextType (such as UDAT_CAPITALIZATION) if the
196 * relevant context to be used in formatting a date is unknown (this is the
197 * default value for any UDateFormatContextType when no value has been
198 * explicitly specified for that UDateFormatContextType).
201 UDAT_CONTEXT_UNKNOWN
= 0,
202 #if !UCONFIG_NO_BREAK_ITERATION
203 /** Values for type (key) UDAT_CAPITALIZATION */
205 * UDAT_CAPITALIZATION value if a date (or date symbol) is to be formatted
206 * with capitalization appropriate for the middle of a sentence.
209 UDAT_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE
= 1,
211 * UDAT_CAPITALIZATION value if a date (or date symbol) is to be formatted
212 * with capitalization appropriate for the beginning of a sentence.
215 UDAT_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE
= 2,
217 * UDAT_CAPITALIZATION value if a date (or date symbol) is to be formatted
218 * with capitalization appropriate for a user-interface list or menu item.
221 UDAT_CAPITALIZATION_FOR_UI_LIST_OR_MENU
= 3,
223 * UDAT_CAPITALIZATION value if a date (or date symbol) is to be formatted
224 * with capitalization appropriate for stand-alone usage such as an
225 * isolated name on a calendar page.
228 UDAT_CAPITALIZATION_FOR_STANDALONE
= 4
230 } UDateFormatContextValue
;
234 * Below are a set of pre-defined skeletons.
240 * only keeps the field pattern letter and ignores all other parts
241 * in a pattern, such as space, punctuations, and string literals.
244 * hides the order of fields.
247 * might hide a field's pattern letter length.
249 * For those non-digit calendar fields, the pattern letter length is
250 * important, such as MMM, MMMM, and MMMMM; EEE and EEEE,
251 * and the field's pattern letter length is honored.
253 * For the digit calendar fields, such as M or MM, d or dd, yy or yyyy,
254 * the field pattern length is ignored and the best match, which is defined
255 * in date time patterns, will be returned without honor the field pattern
256 * letter length in skeleton.
263 #define UDAT_MINUTE_SECOND "ms"
264 #define UDAT_HOUR24_MINUTE "Hm"
265 #define UDAT_HOUR24_MINUTE_SECOND "Hms"
266 #define UDAT_HOUR_MINUTE_SECOND "hms"
267 #define UDAT_STANDALONE_MONTH "LLLL"
268 #define UDAT_ABBR_STANDALONE_MONTH "LLL"
269 #define UDAT_YEAR_QUARTER "yQQQ"
270 #define UDAT_YEAR_ABBR_QUARTER "yQ"
276 * Below are a set of pre-defined skeletons that
277 * have pre-defined interval patterns in resource files.
278 * Users are encouraged to use them in date interval format factory methods.
282 #define UDAT_HOUR_MINUTE "hm"
283 #define UDAT_YEAR "y"
285 #define UDAT_NUM_MONTH_WEEKDAY_DAY "MEd"
286 #define UDAT_YEAR_NUM_MONTH "yM"
287 #define UDAT_NUM_MONTH_DAY "Md"
288 #define UDAT_YEAR_NUM_MONTH_WEEKDAY_DAY "yMEd"
289 #define UDAT_ABBR_MONTH_WEEKDAY_DAY "MMMEd"
290 #define UDAT_YEAR_MONTH "yMMMM"
291 #define UDAT_YEAR_ABBR_MONTH "yMMM"
292 #define UDAT_MONTH_DAY "MMMMd"
293 #define UDAT_ABBR_MONTH_DAY "MMMd"
294 #define UDAT_MONTH_WEEKDAY_DAY "MMMMEEEEd"
295 #define UDAT_YEAR_ABBR_MONTH_WEEKDAY_DAY "yMMMEd"
296 #define UDAT_YEAR_MONTH_WEEKDAY_DAY "yMMMMEEEEd"
297 #define UDAT_YEAR_MONTH_DAY "yMMMMd"
298 #define UDAT_YEAR_ABBR_MONTH_DAY "yMMMd"
299 #define UDAT_YEAR_NUM_MONTH_DAY "yMd"
300 #define UDAT_NUM_MONTH "M"
301 #define UDAT_ABBR_MONTH "MMM"
302 #define UDAT_MONTH "MMMM"
303 #define UDAT_HOUR_MINUTE_GENERIC_TZ "hmv"
304 #define UDAT_HOUR_MINUTE_TZ "hmz"
305 #define UDAT_HOUR "h"
306 #define UDAT_HOUR_GENERIC_TZ "hv"
307 #define UDAT_HOUR_TZ "hz"
313 * FieldPosition and UFieldPosition selectors for format fields
314 * defined by DateFormat and UDateFormat.
317 typedef enum UDateFormatField
{
319 * FieldPosition and UFieldPosition selector for 'G' field alignment,
320 * corresponding to the UCAL_ERA field.
326 * FieldPosition and UFieldPosition selector for 'y' field alignment,
327 * corresponding to the UCAL_YEAR field.
333 * FieldPosition and UFieldPosition selector for 'M' field alignment,
334 * corresponding to the UCAL_MONTH field.
337 UDAT_MONTH_FIELD
= 2,
340 * FieldPosition and UFieldPosition selector for 'd' field alignment,
341 * corresponding to the UCAL_DATE field.
347 * FieldPosition and UFieldPosition selector for 'k' field alignment,
348 * corresponding to the UCAL_HOUR_OF_DAY field.
349 * UDAT_HOUR_OF_DAY1_FIELD is used for the one-based 24-hour clock.
350 * For example, 23:59 + 01:00 results in 24:59.
353 UDAT_HOUR_OF_DAY1_FIELD
= 4,
356 * FieldPosition and UFieldPosition selector for 'H' field alignment,
357 * corresponding to the UCAL_HOUR_OF_DAY field.
358 * UDAT_HOUR_OF_DAY0_FIELD is used for the zero-based 24-hour clock.
359 * For example, 23:59 + 01:00 results in 00:59.
362 UDAT_HOUR_OF_DAY0_FIELD
= 5,
365 * FieldPosition and UFieldPosition selector for 'm' field alignment,
366 * corresponding to the UCAL_MINUTE field.
369 UDAT_MINUTE_FIELD
= 6,
372 * FieldPosition and UFieldPosition selector for 's' field alignment,
373 * corresponding to the UCAL_SECOND field.
376 UDAT_SECOND_FIELD
= 7,
379 * FieldPosition and UFieldPosition selector for 'S' field alignment,
380 * corresponding to the UCAL_MILLISECOND field.
383 UDAT_FRACTIONAL_SECOND_FIELD
= 8,
386 * FieldPosition and UFieldPosition selector for 'E' field alignment,
387 * corresponding to the UCAL_DAY_OF_WEEK field.
390 UDAT_DAY_OF_WEEK_FIELD
= 9,
393 * FieldPosition and UFieldPosition selector for 'D' field alignment,
394 * corresponding to the UCAL_DAY_OF_YEAR field.
397 UDAT_DAY_OF_YEAR_FIELD
= 10,
400 * FieldPosition and UFieldPosition selector for 'F' field alignment,
401 * corresponding to the UCAL_DAY_OF_WEEK_IN_MONTH field.
404 UDAT_DAY_OF_WEEK_IN_MONTH_FIELD
= 11,
407 * FieldPosition and UFieldPosition selector for 'w' field alignment,
408 * corresponding to the UCAL_WEEK_OF_YEAR field.
411 UDAT_WEEK_OF_YEAR_FIELD
= 12,
414 * FieldPosition and UFieldPosition selector for 'W' field alignment,
415 * corresponding to the UCAL_WEEK_OF_MONTH field.
418 UDAT_WEEK_OF_MONTH_FIELD
= 13,
421 * FieldPosition and UFieldPosition selector for 'a' field alignment,
422 * corresponding to the UCAL_AM_PM field.
425 UDAT_AM_PM_FIELD
= 14,
428 * FieldPosition and UFieldPosition selector for 'h' field alignment,
429 * corresponding to the UCAL_HOUR field.
430 * UDAT_HOUR1_FIELD is used for the one-based 12-hour clock.
431 * For example, 11:30 PM + 1 hour results in 12:30 AM.
434 UDAT_HOUR1_FIELD
= 15,
437 * FieldPosition and UFieldPosition selector for 'K' field alignment,
438 * corresponding to the UCAL_HOUR field.
439 * UDAT_HOUR0_FIELD is used for the zero-based 12-hour clock.
440 * For example, 11:30 PM + 1 hour results in 00:30 AM.
443 UDAT_HOUR0_FIELD
= 16,
446 * FieldPosition and UFieldPosition selector for 'z' field alignment,
447 * corresponding to the UCAL_ZONE_OFFSET and
448 * UCAL_DST_OFFSET fields.
451 UDAT_TIMEZONE_FIELD
= 17,
454 * FieldPosition and UFieldPosition selector for 'Y' field alignment,
455 * corresponding to the UCAL_YEAR_WOY field.
458 UDAT_YEAR_WOY_FIELD
= 18,
461 * FieldPosition and UFieldPosition selector for 'e' field alignment,
462 * corresponding to the UCAL_DOW_LOCAL field.
465 UDAT_DOW_LOCAL_FIELD
= 19,
468 * FieldPosition and UFieldPosition selector for 'u' field alignment,
469 * corresponding to the UCAL_EXTENDED_YEAR field.
472 UDAT_EXTENDED_YEAR_FIELD
= 20,
475 * FieldPosition and UFieldPosition selector for 'g' field alignment,
476 * corresponding to the UCAL_JULIAN_DAY field.
479 UDAT_JULIAN_DAY_FIELD
= 21,
482 * FieldPosition and UFieldPosition selector for 'A' field alignment,
483 * corresponding to the UCAL_MILLISECONDS_IN_DAY field.
486 UDAT_MILLISECONDS_IN_DAY_FIELD
= 22,
489 * FieldPosition and UFieldPosition selector for 'Z' field alignment,
490 * corresponding to the UCAL_ZONE_OFFSET and
491 * UCAL_DST_OFFSET fields.
494 UDAT_TIMEZONE_RFC_FIELD
= 23,
497 * FieldPosition and UFieldPosition selector for 'v' field alignment,
498 * corresponding to the UCAL_ZONE_OFFSET field.
501 UDAT_TIMEZONE_GENERIC_FIELD
= 24,
503 * FieldPosition selector for 'c' field alignment,
504 * corresponding to the {@link #UCAL_DOW_LOCAL} field.
505 * This displays the stand alone day name, if available.
508 UDAT_STANDALONE_DAY_FIELD
= 25,
511 * FieldPosition selector for 'L' field alignment,
512 * corresponding to the {@link #UCAL_MONTH} field.
513 * This displays the stand alone month name, if available.
516 UDAT_STANDALONE_MONTH_FIELD
= 26,
519 * FieldPosition selector for "Q" field alignment,
520 * corresponding to quarters. This is implemented
521 * using the {@link #UCAL_MONTH} field. This
522 * displays the quarter.
525 UDAT_QUARTER_FIELD
= 27,
528 * FieldPosition selector for the "q" field alignment,
529 * corresponding to stand-alone quarters. This is
530 * implemented using the {@link #UCAL_MONTH} field.
531 * This displays the stand-alone quarter.
534 UDAT_STANDALONE_QUARTER_FIELD
= 28,
537 * FieldPosition and UFieldPosition selector for 'V' field alignment,
538 * corresponding to the UCAL_ZONE_OFFSET field.
541 UDAT_TIMEZONE_SPECIAL_FIELD
= 29,
544 * FieldPosition selector for "U" field alignment,
545 * corresponding to cyclic year names. This is implemented
546 * using the {@link #UCAL_YEAR} field. This displays
547 * the cyclic year name, if available.
550 UDAT_YEAR_NAME_FIELD
= 30,
553 * Number of FieldPosition and UFieldPosition selectors for
554 * DateFormat and UDateFormat.
555 * Valid selectors range from 0 to UDAT_FIELD_COUNT-1.
556 * This value is subject to change if new fields are defined
560 UDAT_FIELD_COUNT
= 31
566 * Maps from a UDateFormatField to the corresponding UCalendarDateFields.
567 * Note: since the mapping is many-to-one, there is no inverse mapping.
568 * @param field the UDateFormatField.
569 * @return the UCalendarDateField. This will be UCAL_FIELD_COUNT in case
570 * of error (e.g., the input field is UDAT_FIELD_COUNT).
573 U_STABLE UCalendarDateFields U_EXPORT2
574 udat_toCalendarDateField(UDateFormatField field
);
578 * Open a new UDateFormat for formatting and parsing dates and times.
579 * A UDateFormat may be used to format dates in calls to {@link #udat_format },
580 * and to parse dates in calls to {@link #udat_parse }.
581 * @param timeStyle The style used to format times; one of UDAT_FULL, UDAT_LONG,
582 * UDAT_MEDIUM, UDAT_SHORT, UDAT_DEFAULT, or UDAT_NONE (relative time styles
583 * are not currently supported).
584 * @param dateStyle The style used to format dates; one of UDAT_FULL, UDAT_LONG,
585 * UDAT_MEDIUM, UDAT_SHORT, UDAT_DEFAULT, UDAT_FULL_RELATIVE, UDAT_LONG_RELATIVE,
586 * UDAT_MEDIUM_RELATIVE, UDAT_SHORT_RELATIVE, or UDAT_NONE. As currently implemented,
587 * relative date formatting only affects a limited range of calendar days before or
588 * after the current date, based on the CLDR <field type="day">/<relative> data: For
589 * example, in English, "Yesterday", "Today", and "Tomorrow". Outside of this range,
590 * dates are formatted using the corresponding non-relative style.
591 * @param locale The locale specifying the formatting conventions
592 * @param tzID A timezone ID specifying the timezone to use. If 0, use
593 * the default timezone.
594 * @param tzIDLength The length of tzID, or -1 if null-terminated.
595 * @param pattern A pattern specifying the format to use.
596 * @param patternLength The number of characters in the pattern, or -1 if null-terminated.
597 * @param status A pointer to an UErrorCode to receive any errors
598 * @return A pointer to a UDateFormat to use for formatting dates and times, or 0 if
602 U_STABLE UDateFormat
* U_EXPORT2
603 udat_open(UDateFormatStyle timeStyle
,
604 UDateFormatStyle dateStyle
,
608 const UChar
*pattern
,
609 int32_t patternLength
,
614 * Close a UDateFormat.
615 * Once closed, a UDateFormat may no longer be used.
616 * @param format The formatter to close.
619 U_STABLE
void U_EXPORT2
620 udat_close(UDateFormat
* format
);
622 #if U_SHOW_CPLUSPLUS_API
627 * \class LocalUDateFormatPointer
628 * "Smart pointer" class, closes a UDateFormat via udat_close().
629 * For most methods see the LocalPointerBase base class.
631 * @see LocalPointerBase
635 U_DEFINE_LOCAL_OPEN_POINTER(LocalUDateFormatPointer
, UDateFormat
, udat_close
);
642 * Open a copy of a UDateFormat.
643 * This function performs a deep copy.
644 * @param fmt The format to copy
645 * @param status A pointer to an UErrorCode to receive any errors.
646 * @return A pointer to a UDateFormat identical to fmt.
649 U_STABLE UDateFormat
* U_EXPORT2
650 udat_clone(const UDateFormat
*fmt
,
654 * Format a date using an UDateFormat.
655 * The date will be formatted using the conventions specified in {@link #udat_open }
656 * @param format The formatter to use
657 * @param dateToFormat The date to format
658 * @param result A pointer to a buffer to receive the formatted number.
659 * @param resultLength The maximum size of result.
660 * @param position A pointer to a UFieldPosition. On input, position->field
661 * is read. On output, position->beginIndex and position->endIndex indicate
662 * the beginning and ending indices of field number position->field, if such
663 * a field exists. This parameter may be NULL, in which case no field
664 * position data is returned.
665 * @param status A pointer to an UErrorCode to receive any errors
666 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
668 * @see UFieldPosition
671 U_STABLE
int32_t U_EXPORT2
672 udat_format( const UDateFormat
* format
,
675 int32_t resultLength
,
676 UFieldPosition
* position
,
680 * Parse a string into an date/time using a UDateFormat.
681 * The date will be parsed using the conventions specified in {@link #udat_open }.
683 * Note that the normal date formats associated with some calendars - such
684 * as the Chinese lunar calendar - do not specify enough fields to enable
685 * dates to be parsed unambiguously. In the case of the Chinese lunar
686 * calendar, while the year within the current 60-year cycle is specified,
687 * the number of such cycles since the start date of the calendar (in the
688 * UCAL_ERA field of the UCalendar object) is not normally part of the format,
689 * and parsing may assume the wrong era. For cases such as this it is
690 * recommended that clients parse using udat_parseCalendar with the UCalendar
691 * passed in set to the current date, or to a date within the era/cycle that
692 * should be assumed if absent in the format.
694 * @param format The formatter to use.
695 * @param text The text to parse.
696 * @param textLength The length of text, or -1 if null-terminated.
697 * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which
698 * to begin parsing. If not 0, on output the offset at which parsing ended.
699 * @param status A pointer to an UErrorCode to receive any errors
700 * @return The value of the parsed date/time
704 U_STABLE UDate U_EXPORT2
705 udat_parse(const UDateFormat
* format
,
712 * Parse a string into an date/time using a UDateFormat.
713 * The date will be parsed using the conventions specified in {@link #udat_open }.
714 * @param format The formatter to use.
715 * @param calendar A calendar set on input to the date and time to be used for
716 * missing values in the date/time string being parsed, and set
717 * on output to the parsed date/time. When the calendar type is
718 * different from the internal calendar held by the UDateFormat
719 * instance, the internal calendar will be cloned to a work
720 * calendar set to the same milliseconds and time zone as this
721 * calendar parameter, field values will be parsed based on the
722 * work calendar, then the result (milliseconds and time zone)
723 * will be set in this calendar.
724 * @param text The text to parse.
725 * @param textLength The length of text, or -1 if null-terminated.
726 * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which
727 * to begin parsing. If not 0, on output the offset at which parsing ended.
728 * @param status A pointer to an UErrorCode to receive any errors
732 U_STABLE
void U_EXPORT2
733 udat_parseCalendar(const UDateFormat
* format
,
741 * Determine if an UDateFormat will perform lenient parsing.
742 * With lenient parsing, the parser may use heuristics to interpret inputs that do not
743 * precisely match the pattern. With strict parsing, inputs must match the pattern.
744 * @param fmt The formatter to query
745 * @return TRUE if fmt is set to perform lenient parsing, FALSE otherwise.
746 * @see udat_setLenient
749 U_STABLE UBool U_EXPORT2
750 udat_isLenient(const UDateFormat
* fmt
);
753 * Specify whether an UDateFormat will perform lenient parsing.
754 * With lenient parsing, the parser may use heuristics to interpret inputs that do not
755 * precisely match the pattern. With strict parsing, inputs must match the pattern.
756 * @param fmt The formatter to set
757 * @param isLenient TRUE if fmt should perform lenient parsing, FALSE otherwise.
761 U_STABLE
void U_EXPORT2
762 udat_setLenient( UDateFormat
* fmt
,
766 * Get the UCalendar associated with an UDateFormat.
767 * A UDateFormat uses a UCalendar to convert a raw value to, for example,
768 * the day of the week.
769 * @param fmt The formatter to query.
770 * @return A pointer to the UCalendar used by fmt.
771 * @see udat_setCalendar
774 U_STABLE
const UCalendar
* U_EXPORT2
775 udat_getCalendar(const UDateFormat
* fmt
);
778 * Set the UCalendar associated with an UDateFormat.
779 * A UDateFormat uses a UCalendar to convert a raw value to, for example,
780 * the day of the week.
781 * @param fmt The formatter to set.
782 * @param calendarToSet A pointer to an UCalendar to be used by fmt.
783 * @see udat_setCalendar
786 U_STABLE
void U_EXPORT2
787 udat_setCalendar( UDateFormat
* fmt
,
788 const UCalendar
* calendarToSet
);
791 * Get the UNumberFormat associated with an UDateFormat.
792 * A UDateFormat uses a UNumberFormat to format numbers within a date,
793 * for example the day number.
794 * @param fmt The formatter to query.
795 * @return A pointer to the UNumberFormat used by fmt to format numbers.
796 * @see udat_setNumberFormat
799 U_STABLE
const UNumberFormat
* U_EXPORT2
800 udat_getNumberFormat(const UDateFormat
* fmt
);
803 * Set the UNumberFormat associated with an UDateFormat.
804 * A UDateFormat uses a UNumberFormat to format numbers within a date,
805 * for example the day number.
806 * @param fmt The formatter to set.
807 * @param numberFormatToSet A pointer to the UNumberFormat to be used by fmt to format numbers.
808 * @see udat_getNumberFormat
811 U_STABLE
void U_EXPORT2
812 udat_setNumberFormat( UDateFormat
* fmt
,
813 const UNumberFormat
* numberFormatToSet
);
816 * Get a locale for which date/time formatting patterns are available.
817 * A UDateFormat in a locale returned by this function will perform the correct
818 * formatting and parsing for the locale.
819 * @param localeIndex The index of the desired locale.
820 * @return A locale for which date/time formatting patterns are available, or 0 if none.
821 * @see udat_countAvailable
824 U_STABLE
const char* U_EXPORT2
825 udat_getAvailable(int32_t localeIndex
);
828 * Determine how many locales have date/time formatting patterns available.
829 * This function is most useful as determining the loop ending condition for
830 * calls to {@link #udat_getAvailable }.
831 * @return The number of locales for which date/time formatting patterns are available.
832 * @see udat_getAvailable
835 U_STABLE
int32_t U_EXPORT2
836 udat_countAvailable(void);
839 * Get the year relative to which all 2-digit years are interpreted.
840 * For example, if the 2-digit start year is 2100, the year 99 will be
841 * interpreted as 2199.
842 * @param fmt The formatter to query.
843 * @param status A pointer to an UErrorCode to receive any errors
844 * @return The year relative to which all 2-digit years are interpreted.
845 * @see udat_Set2DigitYearStart
848 U_STABLE UDate U_EXPORT2
849 udat_get2DigitYearStart( const UDateFormat
*fmt
,
853 * Set the year relative to which all 2-digit years will be interpreted.
854 * For example, if the 2-digit start year is 2100, the year 99 will be
855 * interpreted as 2199.
856 * @param fmt The formatter to set.
857 * @param d The year relative to which all 2-digit years will be interpreted.
858 * @param status A pointer to an UErrorCode to receive any errors
859 * @see udat_Set2DigitYearStart
862 U_STABLE
void U_EXPORT2
863 udat_set2DigitYearStart( UDateFormat
*fmt
,
868 * Extract the pattern from a UDateFormat.
869 * The pattern will follow the pattern syntax rules.
870 * @param fmt The formatter to query.
871 * @param localized TRUE if the pattern should be localized, FALSE otherwise.
872 * @param result A pointer to a buffer to receive the pattern.
873 * @param resultLength The maximum size of result.
874 * @param status A pointer to an UErrorCode to receive any errors
875 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
876 * @see udat_applyPattern
879 U_STABLE
int32_t U_EXPORT2
880 udat_toPattern( const UDateFormat
*fmt
,
883 int32_t resultLength
,
887 * Set the pattern used by an UDateFormat.
888 * The pattern should follow the pattern syntax rules.
889 * @param format The formatter to set.
890 * @param localized TRUE if the pattern is localized, FALSE otherwise.
891 * @param pattern The new pattern
892 * @param patternLength The length of pattern, or -1 if null-terminated.
893 * @see udat_toPattern
896 U_STABLE
void U_EXPORT2
897 udat_applyPattern( UDateFormat
*format
,
899 const UChar
*pattern
,
900 int32_t patternLength
);
903 * The possible types of date format symbols
906 typedef enum UDateFormatSymbolType
{
907 /** The era names, for example AD */
909 /** The month names, for example February */
911 /** The short month names, for example Feb. */
913 /** The weekday names, for example Monday */
915 /** The short weekday names, for example Mon. */
917 /** The AM/PM names, for example AM */
919 /** The localized characters */
920 UDAT_LOCALIZED_CHARS
,
921 /** The long era names, for example Anno Domini */
923 /** The narrow month names, for example F */
925 /** The narrow weekday names, for example N */
926 UDAT_NARROW_WEEKDAYS
,
927 /** Standalone context versions of months */
928 UDAT_STANDALONE_MONTHS
,
929 UDAT_STANDALONE_SHORT_MONTHS
,
930 UDAT_STANDALONE_NARROW_MONTHS
,
931 /** Standalone context versions of weekdays */
932 UDAT_STANDALONE_WEEKDAYS
,
933 UDAT_STANDALONE_SHORT_WEEKDAYS
,
934 UDAT_STANDALONE_NARROW_WEEKDAYS
,
935 /** The quarters, for example 1st Quarter */
937 /** The short quarter names, for example Q1 */
939 /** Standalone context versions of quarters */
940 UDAT_STANDALONE_QUARTERS
,
941 UDAT_STANDALONE_SHORT_QUARTERS
943 } UDateFormatSymbolType
;
945 struct UDateFormatSymbols
;
946 /** Date format symbols.
947 * For usage in C programs.
950 typedef struct UDateFormatSymbols UDateFormatSymbols
;
953 * Get the symbols associated with an UDateFormat.
954 * The symbols are what a UDateFormat uses to represent locale-specific data,
955 * for example month or day names.
956 * @param fmt The formatter to query.
957 * @param type The type of symbols to get. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS,
958 * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS
959 * @param symbolIndex The desired symbol of type type.
960 * @param result A pointer to a buffer to receive the pattern.
961 * @param resultLength The maximum size of result.
962 * @param status A pointer to an UErrorCode to receive any errors
963 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
964 * @see udat_countSymbols
965 * @see udat_setSymbols
968 U_STABLE
int32_t U_EXPORT2
969 udat_getSymbols(const UDateFormat
*fmt
,
970 UDateFormatSymbolType type
,
973 int32_t resultLength
,
977 * Count the number of particular symbols for an UDateFormat.
978 * This function is most useful as for detemining the loop termination condition
979 * for calls to {@link #udat_getSymbols }.
980 * @param fmt The formatter to query.
981 * @param type The type of symbols to count. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS,
982 * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS
983 * @return The number of symbols of type type.
984 * @see udat_getSymbols
985 * @see udat_setSymbols
988 U_STABLE
int32_t U_EXPORT2
989 udat_countSymbols( const UDateFormat
*fmt
,
990 UDateFormatSymbolType type
);
993 * Set the symbols associated with an UDateFormat.
994 * The symbols are what a UDateFormat uses to represent locale-specific data,
995 * for example month or day names.
996 * @param format The formatter to set
997 * @param type The type of symbols to set. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS,
998 * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS
999 * @param symbolIndex The index of the symbol to set of type type.
1000 * @param value The new value
1001 * @param valueLength The length of value, or -1 if null-terminated
1002 * @param status A pointer to an UErrorCode to receive any errors
1003 * @see udat_getSymbols
1004 * @see udat_countSymbols
1007 U_STABLE
void U_EXPORT2
1008 udat_setSymbols( UDateFormat
*format
,
1009 UDateFormatSymbolType type
,
1010 int32_t symbolIndex
,
1012 int32_t valueLength
,
1013 UErrorCode
*status
);
1016 * Get the locale for this date format object.
1017 * You can choose between valid and actual locale.
1018 * @param fmt The formatter to get the locale from
1019 * @param type type of the locale we're looking for (valid or actual)
1020 * @param status error code for the operation
1021 * @return the locale name
1024 U_STABLE
const char* U_EXPORT2
1025 udat_getLocaleByType(const UDateFormat
*fmt
,
1026 ULocDataLocaleType type
,
1027 UErrorCode
* status
);
1029 #ifndef U_HIDE_DRAFT_API
1031 * Set the formatter's default value for a particular context type,
1032 * such as UDAT_CAPITALIZATION.
1033 * @param fmt The formatter for which to set a context type's default value.
1034 * @param type The context type for which the default value should be set.
1035 * @param value The default value to set for the specified context type.
1036 * @param status A pointer to an UErrorCode to receive any errors
1039 U_DRAFT
void U_EXPORT2
1040 udat_setDefaultContext(UDateFormat
* fmt
,
1041 UDateFormatContextType type
, UDateFormatContextValue value
,
1042 UErrorCode
* status
);
1045 * Get the formatter's default value for a particular context type,
1046 * such as UDAT_CAPITALIZATION.
1047 * @param fmt The formatter from which to get a context type's default value.
1048 * @param type The context type for which the default value should be obtained.
1049 * @param status A pointer to an UErrorCode to receive any errors
1050 * @return The current default value for the specified context type.
1053 U_DRAFT
int32_t U_EXPORT2
1054 udat_getDefaultContext(UDateFormat
* fmt
,
1055 UDateFormatContextType type
,
1056 UErrorCode
* status
);
1057 #endif /* U_HIDE_DRAFT_API */
1059 #ifndef U_HIDE_INTERNAL_API
1061 * Extract the date pattern from a UDateFormat set for relative date formatting.
1062 * The pattern will follow the pattern syntax rules.
1063 * @param fmt The formatter to query.
1064 * @param result A pointer to a buffer to receive the pattern.
1065 * @param resultLength The maximum size of result.
1066 * @param status A pointer to a UErrorCode to receive any errors
1067 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
1068 * @see udat_applyPatternRelative
1069 * @internal ICU 4.2 technology preview
1071 U_INTERNAL
int32_t U_EXPORT2
1072 udat_toPatternRelativeDate(const UDateFormat
*fmt
,
1074 int32_t resultLength
,
1075 UErrorCode
*status
);
1078 * Extract the time pattern from a UDateFormat set for relative date formatting.
1079 * The pattern will follow the pattern syntax rules.
1080 * @param fmt The formatter to query.
1081 * @param result A pointer to a buffer to receive the pattern.
1082 * @param resultLength The maximum size of result.
1083 * @param status A pointer to a UErrorCode to receive any errors
1084 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
1085 * @see udat_applyPatternRelative
1086 * @internal ICU 4.2 technology preview
1088 U_INTERNAL
int32_t U_EXPORT2
1089 udat_toPatternRelativeTime(const UDateFormat
*fmt
,
1091 int32_t resultLength
,
1092 UErrorCode
*status
);
1095 * Set the date & time patterns used by a UDateFormat set for relative date formatting.
1096 * The patterns should follow the pattern syntax rules.
1097 * @param format The formatter to set.
1098 * @param datePattern The new date pattern
1099 * @param datePatternLength The length of datePattern, or -1 if null-terminated.
1100 * @param timePattern The new time pattern
1101 * @param timePatternLength The length of timePattern, or -1 if null-terminated.
1102 * @param status A pointer to a UErrorCode to receive any errors
1103 * @see udat_toPatternRelativeDate, udat_toPatternRelativeTime
1104 * @internal ICU 4.2 technology preview
1106 U_INTERNAL
void U_EXPORT2
1107 udat_applyPatternRelative(UDateFormat
*format
,
1108 const UChar
*datePattern
,
1109 int32_t datePatternLength
,
1110 const UChar
*timePattern
,
1111 int32_t timePatternLength
,
1112 UErrorCode
*status
);
1113 #endif /* U_HIDE_INTERNAL_API */
1119 typedef UDateFormat
* (U_EXPORT2
*UDateFormatOpener
) (UDateFormatStyle timeStyle
,
1120 UDateFormatStyle dateStyle
,
1124 const UChar
*pattern
,
1125 int32_t patternLength
,
1126 UErrorCode
*status
);
1129 * Register a provider factory
1132 U_INTERNAL
void U_EXPORT2
1133 udat_registerOpener(UDateFormatOpener opener
, UErrorCode
*status
);
1136 * Un-Register a provider factory
1139 U_INTERNAL UDateFormatOpener U_EXPORT2
1140 udat_unregisterOpener(UDateFormatOpener opener
, UErrorCode
*status
);
1143 #endif /* #if !UCONFIG_NO_FORMATTING */