2 *******************************************************************************
3 * Copyright (C) 1996-2010, 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 */
178 * Below are a set of pre-defined skeletons.
184 * only keeps the field pattern letter and ignores all other parts
185 * in a pattern, such as space, punctuations, and string literals.
188 * hides the order of fields.
191 * might hide a field's pattern letter length.
193 * For those non-digit calendar fields, the pattern letter length is
194 * important, such as MMM, MMMM, and MMMMM; EEE and EEEE,
195 * and the field's pattern letter length is honored.
197 * For the digit calendar fields, such as M or MM, d or dd, yy or yyyy,
198 * the field pattern length is ignored and the best match, which is defined
199 * in date time patterns, will be returned without honor the field pattern
200 * letter length in skeleton.
207 #define UDAT_MINUTE_SECOND "ms"
208 #define UDAT_HOUR24_MINUTE "Hm"
209 #define UDAT_HOUR24_MINUTE_SECOND "Hms"
210 #define UDAT_HOUR_MINUTE_SECOND "hms"
211 #define UDAT_STANDALONE_MONTH "LLLL"
212 #define UDAT_ABBR_STANDALONE_MONTH "LLL"
213 #define UDAT_YEAR_QUARTER "yQQQ"
214 #define UDAT_YEAR_ABBR_QUARTER "yQ"
220 * Below are a set of pre-defined skeletons that
221 * have pre-defined interval patterns in resource files.
222 * Users are encouraged to use them in date interval format factory methods.
226 #define UDAT_HOUR_MINUTE "hm"
227 #define UDAT_YEAR "y"
229 #define UDAT_NUM_MONTH_WEEKDAY_DAY "MEd"
230 #define UDAT_YEAR_NUM_MONTH "yM"
231 #define UDAT_NUM_MONTH_DAY "Md"
232 #define UDAT_YEAR_NUM_MONTH_WEEKDAY_DAY "yMEd"
233 #define UDAT_ABBR_MONTH_WEEKDAY_DAY "MMMEd"
234 #define UDAT_YEAR_MONTH "yMMMM"
235 #define UDAT_YEAR_ABBR_MONTH "yMMM"
236 #define UDAT_MONTH_DAY "MMMMd"
237 #define UDAT_ABBR_MONTH_DAY "MMMd"
238 #define UDAT_MONTH_WEEKDAY_DAY "MMMMEEEEd"
239 #define UDAT_YEAR_ABBR_MONTH_WEEKDAY_DAY "yMMMEd"
240 #define UDAT_YEAR_MONTH_WEEKDAY_DAY "yMMMMEEEEd"
241 #define UDAT_YEAR_MONTH_DAY "yMMMMd"
242 #define UDAT_YEAR_ABBR_MONTH_DAY "yMMMd"
243 #define UDAT_YEAR_NUM_MONTH_DAY "yMd"
244 #define UDAT_NUM_MONTH "M"
245 #define UDAT_ABBR_MONTH "MMM"
246 #define UDAT_MONTH "MMMM"
247 #define UDAT_HOUR_MINUTE_GENERIC_TZ "hmv"
248 #define UDAT_HOUR_MINUTE_TZ "hmz"
249 #define UDAT_HOUR "h"
250 #define UDAT_HOUR_GENERIC_TZ "hv"
251 #define UDAT_HOUR_TZ "hz"
257 * FieldPosition and UFieldPosition selectors for format fields
258 * defined by DateFormat and UDateFormat.
261 typedef enum UDateFormatField
{
263 * FieldPosition and UFieldPosition selector for 'G' field alignment,
264 * corresponding to the UCAL_ERA field.
270 * FieldPosition and UFieldPosition selector for 'y' field alignment,
271 * corresponding to the UCAL_YEAR field.
277 * FieldPosition and UFieldPosition selector for 'M' field alignment,
278 * corresponding to the UCAL_MONTH field.
281 UDAT_MONTH_FIELD
= 2,
284 * FieldPosition and UFieldPosition selector for 'd' field alignment,
285 * corresponding to the UCAL_DATE field.
291 * FieldPosition and UFieldPosition selector for 'k' field alignment,
292 * corresponding to the UCAL_HOUR_OF_DAY field.
293 * UDAT_HOUR_OF_DAY1_FIELD is used for the one-based 24-hour clock.
294 * For example, 23:59 + 01:00 results in 24:59.
297 UDAT_HOUR_OF_DAY1_FIELD
= 4,
300 * FieldPosition and UFieldPosition selector for 'H' field alignment,
301 * corresponding to the UCAL_HOUR_OF_DAY field.
302 * UDAT_HOUR_OF_DAY0_FIELD is used for the zero-based 24-hour clock.
303 * For example, 23:59 + 01:00 results in 00:59.
306 UDAT_HOUR_OF_DAY0_FIELD
= 5,
309 * FieldPosition and UFieldPosition selector for 'm' field alignment,
310 * corresponding to the UCAL_MINUTE field.
313 UDAT_MINUTE_FIELD
= 6,
316 * FieldPosition and UFieldPosition selector for 's' field alignment,
317 * corresponding to the UCAL_SECOND field.
320 UDAT_SECOND_FIELD
= 7,
323 * FieldPosition and UFieldPosition selector for 'S' field alignment,
324 * corresponding to the UCAL_MILLISECOND field.
327 UDAT_FRACTIONAL_SECOND_FIELD
= 8,
330 * FieldPosition and UFieldPosition selector for 'E' field alignment,
331 * corresponding to the UCAL_DAY_OF_WEEK field.
334 UDAT_DAY_OF_WEEK_FIELD
= 9,
337 * FieldPosition and UFieldPosition selector for 'D' field alignment,
338 * corresponding to the UCAL_DAY_OF_YEAR field.
341 UDAT_DAY_OF_YEAR_FIELD
= 10,
344 * FieldPosition and UFieldPosition selector for 'F' field alignment,
345 * corresponding to the UCAL_DAY_OF_WEEK_IN_MONTH field.
348 UDAT_DAY_OF_WEEK_IN_MONTH_FIELD
= 11,
351 * FieldPosition and UFieldPosition selector for 'w' field alignment,
352 * corresponding to the UCAL_WEEK_OF_YEAR field.
355 UDAT_WEEK_OF_YEAR_FIELD
= 12,
358 * FieldPosition and UFieldPosition selector for 'W' field alignment,
359 * corresponding to the UCAL_WEEK_OF_MONTH field.
362 UDAT_WEEK_OF_MONTH_FIELD
= 13,
365 * FieldPosition and UFieldPosition selector for 'a' field alignment,
366 * corresponding to the UCAL_AM_PM field.
369 UDAT_AM_PM_FIELD
= 14,
372 * FieldPosition and UFieldPosition selector for 'h' field alignment,
373 * corresponding to the UCAL_HOUR field.
374 * UDAT_HOUR1_FIELD is used for the one-based 12-hour clock.
375 * For example, 11:30 PM + 1 hour results in 12:30 AM.
378 UDAT_HOUR1_FIELD
= 15,
381 * FieldPosition and UFieldPosition selector for 'K' field alignment,
382 * corresponding to the UCAL_HOUR field.
383 * UDAT_HOUR0_FIELD is used for the zero-based 12-hour clock.
384 * For example, 11:30 PM + 1 hour results in 00:30 AM.
387 UDAT_HOUR0_FIELD
= 16,
390 * FieldPosition and UFieldPosition selector for 'z' field alignment,
391 * corresponding to the UCAL_ZONE_OFFSET and
392 * UCAL_DST_OFFSET fields.
395 UDAT_TIMEZONE_FIELD
= 17,
398 * FieldPosition and UFieldPosition selector for 'Y' field alignment,
399 * corresponding to the UCAL_YEAR_WOY field.
402 UDAT_YEAR_WOY_FIELD
= 18,
405 * FieldPosition and UFieldPosition selector for 'e' field alignment,
406 * corresponding to the UCAL_DOW_LOCAL field.
409 UDAT_DOW_LOCAL_FIELD
= 19,
412 * FieldPosition and UFieldPosition selector for 'u' field alignment,
413 * corresponding to the UCAL_EXTENDED_YEAR field.
416 UDAT_EXTENDED_YEAR_FIELD
= 20,
419 * FieldPosition and UFieldPosition selector for 'g' field alignment,
420 * corresponding to the UCAL_JULIAN_DAY field.
423 UDAT_JULIAN_DAY_FIELD
= 21,
426 * FieldPosition and UFieldPosition selector for 'A' field alignment,
427 * corresponding to the UCAL_MILLISECONDS_IN_DAY field.
430 UDAT_MILLISECONDS_IN_DAY_FIELD
= 22,
433 * FieldPosition and UFieldPosition selector for 'Z' field alignment,
434 * corresponding to the UCAL_ZONE_OFFSET and
435 * UCAL_DST_OFFSET fields.
438 UDAT_TIMEZONE_RFC_FIELD
= 23,
441 * FieldPosition and UFieldPosition selector for 'v' field alignment,
442 * corresponding to the UCAL_ZONE_OFFSET field.
445 UDAT_TIMEZONE_GENERIC_FIELD
= 24,
447 * FieldPosition selector for 'c' field alignment,
448 * corresponding to the {@link #UCAL_DOW_LOCAL} field.
449 * This displays the stand alone day name, if available.
452 UDAT_STANDALONE_DAY_FIELD
= 25,
455 * FieldPosition selector for 'L' field alignment,
456 * corresponding to the {@link #UCAL_MONTH} field.
457 * This displays the stand alone month name, if available.
460 UDAT_STANDALONE_MONTH_FIELD
= 26,
463 * FieldPosition selector for "Q" field alignment,
464 * corresponding to quarters. This is implemented
465 * using the {@link #UCAL_MONTH} field. This
466 * displays the quarter.
469 UDAT_QUARTER_FIELD
= 27,
472 * FieldPosition selector for the "q" field alignment,
473 * corresponding to stand-alone quarters. This is
474 * implemented using the {@link #UCAL_MONTH} field.
475 * This displays the stand-alone quarter.
478 UDAT_STANDALONE_QUARTER_FIELD
= 28,
481 * FieldPosition and UFieldPosition selector for 'V' field alignment,
482 * corresponding to the UCAL_ZONE_OFFSET field.
485 UDAT_TIMEZONE_SPECIAL_FIELD
= 29,
488 * Number of FieldPosition and UFieldPosition selectors for
489 * DateFormat and UDateFormat.
490 * Valid selectors range from 0 to UDAT_FIELD_COUNT-1.
491 * This value is subject to change if new fields are defined
495 UDAT_FIELD_COUNT
= 30
501 * Maps from a UDateFormatField to the corresponding UCalendarDateFields.
502 * Note: since the mapping is many-to-one, there is no inverse mapping.
503 * @param field the UDateFormatField.
504 * @return the UCalendarDateField. This will be UCAL_FIELD_COUNT in case
505 * of error (e.g., the input field is UDAT_FIELD_COUNT).
508 U_STABLE UCalendarDateFields U_EXPORT2
509 udat_toCalendarDateField(UDateFormatField field
);
513 * Open a new UDateFormat for formatting and parsing dates and times.
514 * A UDateFormat may be used to format dates in calls to {@link #udat_format },
515 * and to parse dates in calls to {@link #udat_parse }.
516 * @param timeStyle The style used to format times; one of UDAT_FULL, UDAT_LONG,
517 * UDAT_MEDIUM, UDAT_SHORT, UDAT_DEFAULT, or UDAT_NONE (relative time styles
518 * are not currently supported)
519 * @param dateStyle The style used to format dates; one of UDAT_FULL, UDAT_LONG,
520 * UDAT_MEDIUM, UDAT_SHORT, UDAT_DEFAULT, UDAT_FULL_RELATIVE, UDAT_LONG_RELATIVE,
521 * UDAT_MEDIUM_RELATIVE, UDAT_SHORT_RELATIVE, or UDAT_NONE
522 * @param locale The locale specifying the formatting conventions
523 * @param tzID A timezone ID specifying the timezone to use. If 0, use
524 * the default timezone.
525 * @param tzIDLength The length of tzID, or -1 if null-terminated.
526 * @param pattern A pattern specifying the format to use.
527 * @param patternLength The number of characters in the pattern, or -1 if null-terminated.
528 * @param status A pointer to an UErrorCode to receive any errors
529 * @return A pointer to a UDateFormat to use for formatting dates and times, or 0 if
533 U_STABLE UDateFormat
* U_EXPORT2
534 udat_open(UDateFormatStyle timeStyle
,
535 UDateFormatStyle dateStyle
,
539 const UChar
*pattern
,
540 int32_t patternLength
,
545 * Close a UDateFormat.
546 * Once closed, a UDateFormat may no longer be used.
547 * @param format The formatter to close.
550 U_STABLE
void U_EXPORT2
551 udat_close(UDateFormat
* format
);
553 #if U_SHOW_CPLUSPLUS_API
558 * \class LocalUDateFormatPointer
559 * "Smart pointer" class, closes a UDateFormat via udat_close().
560 * For most methods see the LocalPointerBase base class.
562 * @see LocalPointerBase
566 U_DEFINE_LOCAL_OPEN_POINTER(LocalUDateFormatPointer
, UDateFormat
, udat_close
);
573 * Open a copy of a UDateFormat.
574 * This function performs a deep copy.
575 * @param fmt The format to copy
576 * @param status A pointer to an UErrorCode to receive any errors.
577 * @return A pointer to a UDateFormat identical to fmt.
580 U_STABLE UDateFormat
* U_EXPORT2
581 udat_clone(const UDateFormat
*fmt
,
585 * Format a date using an UDateFormat.
586 * The date will be formatted using the conventions specified in {@link #udat_open }
587 * @param format The formatter to use
588 * @param dateToFormat The date to format
589 * @param result A pointer to a buffer to receive the formatted number.
590 * @param resultLength The maximum size of result.
591 * @param position A pointer to a UFieldPosition. On input, position->field
592 * is read. On output, position->beginIndex and position->endIndex indicate
593 * the beginning and ending indices of field number position->field, if such
594 * a field exists. This parameter may be NULL, in which case no field
595 * position data is returned.
596 * @param status A pointer to an UErrorCode to receive any errors
597 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
599 * @see UFieldPosition
602 U_STABLE
int32_t U_EXPORT2
603 udat_format( const UDateFormat
* format
,
606 int32_t resultLength
,
607 UFieldPosition
* position
,
611 * Parse a string into an date/time using a UDateFormat.
612 * The date will be parsed using the conventions specified in {@link #udat_open }
613 * @param format The formatter to use.
614 * @param text The text to parse.
615 * @param textLength The length of text, or -1 if null-terminated.
616 * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which
617 * to begin parsing. If not 0, on output the offset at which parsing ended.
618 * @param status A pointer to an UErrorCode to receive any errors
619 * @return The value of the parsed date/time
623 U_STABLE UDate U_EXPORT2
624 udat_parse( const UDateFormat
* format
,
631 * Parse a string into an date/time using a UDateFormat.
632 * The date will be parsed using the conventions specified in {@link #udat_open }
633 * @param format The formatter to use.
634 * @param calendar The calendar in which to store the parsed data.
635 * @param text The text to parse.
636 * @param textLength The length of text, or -1 if null-terminated.
637 * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which
638 * to begin parsing. If not 0, on output the offset at which parsing ended.
639 * @param status A pointer to an UErrorCode to receive any errors
643 U_STABLE
void U_EXPORT2
644 udat_parseCalendar(const UDateFormat
* format
,
652 * Determine if an UDateFormat will perform lenient parsing.
653 * With lenient parsing, the parser may use heuristics to interpret inputs that do not
654 * precisely match the pattern. With strict parsing, inputs must match the pattern.
655 * @param fmt The formatter to query
656 * @return TRUE if fmt is set to perform lenient parsing, FALSE otherwise.
657 * @see udat_setLenient
660 U_STABLE UBool U_EXPORT2
661 udat_isLenient(const UDateFormat
* fmt
);
664 * Specify whether an UDateFormat will perform lenient parsing.
665 * With lenient parsing, the parser may use heuristics to interpret inputs that do not
666 * precisely match the pattern. With strict parsing, inputs must match the pattern.
667 * @param fmt The formatter to set
668 * @param isLenient TRUE if fmt should perform lenient parsing, FALSE otherwise.
672 U_STABLE
void U_EXPORT2
673 udat_setLenient( UDateFormat
* fmt
,
677 * Get the UCalendar associated with an UDateFormat.
678 * A UDateFormat uses a UCalendar to convert a raw value to, for example,
679 * the day of the week.
680 * @param fmt The formatter to query.
681 * @return A pointer to the UCalendar used by fmt.
682 * @see udat_setCalendar
685 U_STABLE
const UCalendar
* U_EXPORT2
686 udat_getCalendar(const UDateFormat
* fmt
);
689 * Set the UCalendar associated with an UDateFormat.
690 * A UDateFormat uses a UCalendar to convert a raw value to, for example,
691 * the day of the week.
692 * @param fmt The formatter to set.
693 * @param calendarToSet A pointer to an UCalendar to be used by fmt.
694 * @see udat_setCalendar
697 U_STABLE
void U_EXPORT2
698 udat_setCalendar( UDateFormat
* fmt
,
699 const UCalendar
* calendarToSet
);
702 * Get the UNumberFormat associated with an UDateFormat.
703 * A UDateFormat uses a UNumberFormat to format numbers within a date,
704 * for example the day number.
705 * @param fmt The formatter to query.
706 * @return A pointer to the UNumberFormat used by fmt to format numbers.
707 * @see udat_setNumberFormat
710 U_STABLE
const UNumberFormat
* U_EXPORT2
711 udat_getNumberFormat(const UDateFormat
* fmt
);
714 * Set the UNumberFormat associated with an UDateFormat.
715 * A UDateFormat uses a UNumberFormat to format numbers within a date,
716 * for example the day number.
717 * @param fmt The formatter to set.
718 * @param numberFormatToSet A pointer to the UNumberFormat to be used by fmt to format numbers.
719 * @see udat_getNumberFormat
722 U_STABLE
void U_EXPORT2
723 udat_setNumberFormat( UDateFormat
* fmt
,
724 const UNumberFormat
* numberFormatToSet
);
727 * Get a locale for which date/time formatting patterns are available.
728 * A UDateFormat in a locale returned by this function will perform the correct
729 * formatting and parsing for the locale.
730 * @param localeIndex The index of the desired locale.
731 * @return A locale for which date/time formatting patterns are available, or 0 if none.
732 * @see udat_countAvailable
735 U_STABLE
const char* U_EXPORT2
736 udat_getAvailable(int32_t localeIndex
);
739 * Determine how many locales have date/time formatting patterns available.
740 * This function is most useful as determining the loop ending condition for
741 * calls to {@link #udat_getAvailable }.
742 * @return The number of locales for which date/time formatting patterns are available.
743 * @see udat_getAvailable
746 U_STABLE
int32_t U_EXPORT2
747 udat_countAvailable(void);
750 * Get the year relative to which all 2-digit years are interpreted.
751 * For example, if the 2-digit start year is 2100, the year 99 will be
752 * interpreted as 2199.
753 * @param fmt The formatter to query.
754 * @param status A pointer to an UErrorCode to receive any errors
755 * @return The year relative to which all 2-digit years are interpreted.
756 * @see udat_Set2DigitYearStart
759 U_STABLE UDate U_EXPORT2
760 udat_get2DigitYearStart( const UDateFormat
*fmt
,
764 * Set the year relative to which all 2-digit years will be interpreted.
765 * For example, if the 2-digit start year is 2100, the year 99 will be
766 * interpreted as 2199.
767 * @param fmt The formatter to set.
768 * @param d The year relative to which all 2-digit years will be interpreted.
769 * @param status A pointer to an UErrorCode to receive any errors
770 * @see udat_Set2DigitYearStart
773 U_STABLE
void U_EXPORT2
774 udat_set2DigitYearStart( UDateFormat
*fmt
,
779 * Extract the pattern from a UDateFormat.
780 * The pattern will follow the pattern syntax rules.
781 * @param fmt The formatter to query.
782 * @param localized TRUE if the pattern should be localized, FALSE otherwise.
783 * @param result A pointer to a buffer to receive the pattern.
784 * @param resultLength The maximum size of result.
785 * @param status A pointer to an UErrorCode to receive any errors
786 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
787 * @see udat_applyPattern
790 U_STABLE
int32_t U_EXPORT2
791 udat_toPattern( const UDateFormat
*fmt
,
794 int32_t resultLength
,
798 * Set the pattern used by an UDateFormat.
799 * The pattern should follow the pattern syntax rules.
800 * @param format The formatter to set.
801 * @param localized TRUE if the pattern is localized, FALSE otherwise.
802 * @param pattern The new pattern
803 * @param patternLength The length of pattern, or -1 if null-terminated.
804 * @see udat_toPattern
807 U_STABLE
void U_EXPORT2
808 udat_applyPattern( UDateFormat
*format
,
810 const UChar
*pattern
,
811 int32_t patternLength
);
814 * The possible types of date format symbols
817 typedef enum UDateFormatSymbolType
{
818 /** The era names, for example AD */
820 /** The month names, for example February */
822 /** The short month names, for example Feb. */
824 /** The weekday names, for example Monday */
826 /** The short weekday names, for example Mon. */
828 /** The AM/PM names, for example AM */
830 /** The localized characters */
831 UDAT_LOCALIZED_CHARS
,
832 /** The long era names, for example Anno Domini */
834 /** The narrow month names, for example F */
836 /** The narrow weekday names, for example N */
837 UDAT_NARROW_WEEKDAYS
,
838 /** Standalone context versions of months */
839 UDAT_STANDALONE_MONTHS
,
840 UDAT_STANDALONE_SHORT_MONTHS
,
841 UDAT_STANDALONE_NARROW_MONTHS
,
842 /** Standalone context versions of weekdays */
843 UDAT_STANDALONE_WEEKDAYS
,
844 UDAT_STANDALONE_SHORT_WEEKDAYS
,
845 UDAT_STANDALONE_NARROW_WEEKDAYS
,
846 /** The quarters, for example 1st Quarter */
848 /** The short quarter names, for example Q1 */
850 /** Standalone context versions of quarters */
851 UDAT_STANDALONE_QUARTERS
,
852 UDAT_STANDALONE_SHORT_QUARTERS
854 } UDateFormatSymbolType
;
856 struct UDateFormatSymbols
;
857 /** Date format symbols.
858 * For usage in C programs.
861 typedef struct UDateFormatSymbols UDateFormatSymbols
;
864 * Get the symbols associated with an UDateFormat.
865 * The symbols are what a UDateFormat uses to represent locale-specific data,
866 * for example month or day names.
867 * @param fmt The formatter to query.
868 * @param type The type of symbols to get. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS,
869 * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS
870 * @param symbolIndex The desired symbol of type type.
871 * @param result A pointer to a buffer to receive the pattern.
872 * @param resultLength The maximum size of result.
873 * @param status A pointer to an UErrorCode to receive any errors
874 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
875 * @see udat_countSymbols
876 * @see udat_setSymbols
879 U_STABLE
int32_t U_EXPORT2
880 udat_getSymbols(const UDateFormat
*fmt
,
881 UDateFormatSymbolType type
,
884 int32_t resultLength
,
888 * Count the number of particular symbols for an UDateFormat.
889 * This function is most useful as for detemining the loop termination condition
890 * for calls to {@link #udat_getSymbols }.
891 * @param fmt The formatter to query.
892 * @param type The type of symbols to count. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS,
893 * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS
894 * @return The number of symbols of type type.
895 * @see udat_getSymbols
896 * @see udat_setSymbols
899 U_STABLE
int32_t U_EXPORT2
900 udat_countSymbols( const UDateFormat
*fmt
,
901 UDateFormatSymbolType type
);
904 * Set the symbols associated with an UDateFormat.
905 * The symbols are what a UDateFormat uses to represent locale-specific data,
906 * for example month or day names.
907 * @param format The formatter to set
908 * @param type The type of symbols to set. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS,
909 * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS
910 * @param symbolIndex The index of the symbol to set of type type.
911 * @param value The new value
912 * @param valueLength The length of value, or -1 if null-terminated
913 * @param status A pointer to an UErrorCode to receive any errors
914 * @see udat_getSymbols
915 * @see udat_countSymbols
918 U_STABLE
void U_EXPORT2
919 udat_setSymbols( UDateFormat
*format
,
920 UDateFormatSymbolType type
,
927 * Get the locale for this date format object.
928 * You can choose between valid and actual locale.
929 * @param fmt The formatter to get the locale from
930 * @param type type of the locale we're looking for (valid or actual)
931 * @param status error code for the operation
932 * @return the locale name
935 U_STABLE
const char* U_EXPORT2
936 udat_getLocaleByType(const UDateFormat
*fmt
,
937 ULocDataLocaleType type
,
941 * Extract the date pattern from a UDateFormat set for relative date formatting.
942 * The pattern will follow the pattern syntax rules.
943 * @param fmt The formatter to query.
944 * @param result A pointer to a buffer to receive the pattern.
945 * @param resultLength The maximum size of result.
946 * @param status A pointer to a UErrorCode to receive any errors
947 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
948 * @see udat_applyPatternRelative
949 * @internal ICU 4.2 technology preview
951 U_INTERNAL
int32_t U_EXPORT2
952 udat_toPatternRelativeDate(const UDateFormat
*fmt
,
954 int32_t resultLength
,
958 * Extract the time pattern from a UDateFormat set for relative date formatting.
959 * The pattern will follow the pattern syntax rules.
960 * @param fmt The formatter to query.
961 * @param result A pointer to a buffer to receive the pattern.
962 * @param resultLength The maximum size of result.
963 * @param status A pointer to a UErrorCode to receive any errors
964 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
965 * @see udat_applyPatternRelative
966 * @internal ICU 4.2 technology preview
968 U_INTERNAL
int32_t U_EXPORT2
969 udat_toPatternRelativeTime(const UDateFormat
*fmt
,
971 int32_t resultLength
,
975 * Set the date & time patterns used by a UDateFormat set for relative date formatting.
976 * The patterns should follow the pattern syntax rules.
977 * @param format The formatter to set.
978 * @param datePattern The new date pattern
979 * @param datePatternLength The length of datePattern, or -1 if null-terminated.
980 * @param timePattern The new time pattern
981 * @param timePatternLength The length of timePattern, or -1 if null-terminated.
982 * @param status A pointer to a UErrorCode to receive any errors
983 * @see udat_toPatternRelativeDate, udat_toPatternRelativeTime
984 * @internal ICU 4.2 technology preview
986 U_INTERNAL
void U_EXPORT2
987 udat_applyPatternRelative(UDateFormat
*format
,
988 const UChar
*datePattern
,
989 int32_t datePatternLength
,
990 const UChar
*timePattern
,
991 int32_t timePatternLength
,
995 #endif /* #if !UCONFIG_NO_FORMATTING */