2 *******************************************************************************
3 * Copyright (C) 1996-2009, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 *******************************************************************************
11 #include "unicode/utypes.h"
13 #if !UCONFIG_NO_FORMATTING
15 #include "unicode/ucal.h"
16 #include "unicode/unum.h"
19 * \brief C API: DateFormat
21 * <h2> Date Format C API</h2>
23 * Date Format C API consists of functions that convert dates and
24 * times from their internal representations to textual form and back again in a
25 * language-independent manner. Converting from the internal representation (milliseconds
26 * since midnight, January 1, 1970) to text is known as "formatting," and converting
27 * from text to millis is known as "parsing." We currently define only one concrete
28 * structure UDateFormat, which can handle pretty much all normal
29 * date formatting and parsing actions.
31 * Date Format helps you to format and parse dates for any locale. Your code can
32 * be completely independent of the locale conventions for months, days of the
33 * week, or even the calendar format: lunar vs. solar.
35 * To format a date for the current Locale with default time and date style,
36 * use one of the static factory methods:
39 * UErrorCode status = U_ZERO_ERROR;
41 * int32_t myStrlen = 0;
42 * UDateFormat* dfmt = udat_open(UDAT_DEFAULT, UDAT_DEFAULT, NULL, NULL, -1, NULL, -1, &status);
43 * myStrlen = udat_format(dfmt, myDate, NULL, myStrlen, NULL, &status);
44 * if (status==U_BUFFER_OVERFLOW_ERROR){
45 * status=U_ZERO_ERROR;
46 * myString=(UChar*)malloc(sizeof(UChar) * (myStrlen+1) );
47 * udat_format(dfmt, myDate, myString, myStrlen+1, NULL, &status);
51 * If you are formatting multiple numbers, it is more efficient to get the
52 * format and use it multiple times so that the system doesn't have to fetch the
53 * information about the local language and country conventions multiple times.
56 * UErrorCode status = U_ZERO_ERROR;
57 * int32_t i, myStrlen = 0;
60 * UDate myDateArr[] = { 0.0, 100000000.0, 2000000000.0 }; // test values
61 * UDateFormat* df = udat_open(UDAT_DEFAULT, UDAT_DEFAULT, NULL, NULL, -1, NULL, 0, &status);
62 * for (i = 0; i < 3; i++) {
63 * myStrlen = udat_format(df, myDateArr[i], NULL, myStrlen, NULL, &status);
64 * if(status == U_BUFFER_OVERFLOW_ERROR){
65 * status = U_ZERO_ERROR;
66 * myString = (UChar*)malloc(sizeof(UChar) * (myStrlen+1) );
67 * udat_format(df, myDateArr[i], myString, myStrlen+1, NULL, &status);
68 * printf("%s\n", u_austrcpy(buffer, myString) );
74 * To get specific fields of a date, you can use UFieldPosition to
75 * get specific fields.
78 * UErrorCode status = U_ZERO_ERROR;
81 * int32_t myStrlen = 0;
84 * pos.field = 1; // Same as the DateFormat::EField enum
85 * UDateFormat* dfmt = udat_open(UDAT_DEFAULT, UDAT_DEFAULT, NULL, -1, NULL, 0, &status);
86 * myStrlen = udat_format(dfmt, myDate, NULL, myStrlen, &pos, &status);
87 * if (status==U_BUFFER_OVERFLOW_ERROR){
88 * status=U_ZERO_ERROR;
89 * myString=(UChar*)malloc(sizeof(UChar) * (myStrlen+1) );
90 * udat_format(dfmt, myDate, myString, myStrlen+1, &pos, &status);
92 * printf("date format: %s\n", u_austrcpy(buffer, myString));
93 * buffer[pos.endIndex] = 0; // NULL terminate the string.
94 * printf("UFieldPosition position equals %s\n", &buffer[pos.beginIndex]);
97 * To format a date for a different Locale, specify it in the call to
101 * UDateFormat* df = udat_open(UDAT_SHORT, UDAT_SHORT, "fr_FR", NULL, -1, NULL, 0, &status);
104 * You can use a DateFormat API udat_parse() to parse.
107 * UErrorCode status = U_ZERO_ERROR;
108 * int32_t parsepos=0;
109 * UDate myDate = udat_parse(df, myString, u_strlen(myString), &parsepos, &status);
112 * You can pass in different options for the arguments for date and time style
113 * to control the length of the result; from SHORT to MEDIUM to LONG to FULL.
114 * The exact result depends on the locale, but generally:
115 * see UDateFormatStyle for more details
117 * <li> UDAT_SHORT is completely numeric, such as 12/13/52 or 3:30pm
118 * <li> UDAT_MEDIUM is longer, such as Jan 12, 1952
119 * <li> UDAT_LONG is longer, such as January 12, 1952 or 3:30:32pm
120 * <li> UDAT_FULL is pretty completely specified, such as
121 * Tuesday, April 12, 1952 AD or 3:30:42pm PST.
123 * You can also set the time zone on the format if you wish.
125 * You can also use forms of the parse and format methods with Parse Position and
126 * UFieldPosition to allow you to
128 * <li> Progressively parse through pieces of a string.
129 * <li> Align any particular field, or find out where it is for selection
134 /** A date formatter.
135 * For usage in C programs.
138 typedef void* UDateFormat
;
140 /** The possible date/time format styles
143 typedef enum UDateFormatStyle
{
153 UDAT_DEFAULT
= UDAT_MEDIUM
,
155 /** Bitfield for relative date */
156 UDAT_RELATIVE
= (1 << 7),
158 UDAT_FULL_RELATIVE
= UDAT_FULL
| UDAT_RELATIVE
,
160 UDAT_LONG_RELATIVE
= UDAT_LONG
| UDAT_RELATIVE
,
162 UDAT_MEDIUM_RELATIVE
= UDAT_MEDIUM
| UDAT_RELATIVE
,
164 UDAT_SHORT_RELATIVE
= UDAT_SHORT
| UDAT_RELATIVE
,
169 /** for internal API use only */
177 * Below are a set of pre-defined skeletons.
183 * only keeps the field pattern letter and ignores all other parts
184 * in a pattern, such as space, punctuations, and string literals.
187 * hides the order of fields.
190 * might hide a field's pattern letter length.
192 * For those non-digit calendar fields, the pattern letter length is
193 * important, such as MMM, MMMM, and MMMMM; EEE and EEEE,
194 * and the field's pattern letter length is honored.
196 * For the digit calendar fields, such as M or MM, d or dd, yy or yyyy,
197 * the field pattern length is ignored and the best match, which is defined
198 * in date time patterns, will be returned without honor the field pattern
199 * letter length in skeleton.
206 #define UDAT_MINUTE_SECOND "ms"
207 #define UDAT_HOUR24_MINUTE "Hm"
208 #define UDAT_HOUR24_MINUTE_SECOND "Hms"
209 #define UDAT_HOUR_MINUTE_SECOND "hms"
210 #define UDAT_STANDALONE_MONTH "LLLL"
211 #define UDAT_ABBR_STANDALONE_MONTH "LLL"
212 #define UDAT_YEAR_QUARTER "yQQQ"
213 #define UDAT_YEAR_ABBR_QUARTER "yQ"
219 * Below are a set of pre-defined skeletons that
220 * have pre-defined interval patterns in resource files.
221 * Users are encouraged to use them in date interval format factory methods.
224 #define UDAT_HOUR_MINUTE "hm"
225 #define UDAT_YEAR "y"
227 #define UDAT_NUM_MONTH_WEEKDAY_DAY "MEd"
228 #define UDAT_YEAR_NUM_MONTH "yM"
229 #define UDAT_NUM_MONTH_DAY "Md"
230 #define UDAT_YEAR_NUM_MONTH_WEEKDAY_DAY "yMEd"
231 #define UDAT_ABBR_MONTH_WEEKDAY_DAY "MMMEd"
232 #define UDAT_YEAR_MONTH "yMMMM"
233 #define UDAT_YEAR_ABBR_MONTH "yMMM"
234 #define UDAT_MONTH_DAY "MMMMd"
235 #define UDAT_ABBR_MONTH_DAY "MMMd"
236 #define UDAT_MONTH_WEEKDAY_DAY "MMMMEEEEd"
237 #define UDAT_YEAR_ABBR_MONTH_WEEKDAY_DAY "yMMMEd"
238 #define UDAT_YEAR_MONTH_WEEKDAY_DAY "yMMMMEEEEd"
239 #define UDAT_YEAR_MONTH_DAY "yMMMMd"
240 #define UDAT_YEAR_ABBR_MONTH_DAY "yMMMd"
241 #define UDAT_YEAR_NUM_MONTH_DAY "yMd"
242 #define UDAT_NUM_MONTH "M"
243 #define UDAT_ABBR_MONTH "MMM"
244 #define UDAT_MONTH "MMMM"
245 #define UDAT_HOUR_MINUTE_GENERIC_TZ "hmv"
246 #define UDAT_HOUR_MINUTE_TZ "hmz"
247 #define UDAT_HOUR "h"
248 #define UDAT_HOUR_GENERIC_TZ "hv"
249 #define UDAT_HOUR_TZ "hz"
255 * FieldPosition and UFieldPosition selectors for format fields
256 * defined by DateFormat and UDateFormat.
259 typedef enum UDateFormatField
{
261 * FieldPosition and UFieldPosition selector for 'G' field alignment,
262 * corresponding to the UCAL_ERA field.
268 * FieldPosition and UFieldPosition selector for 'y' field alignment,
269 * corresponding to the UCAL_YEAR field.
275 * FieldPosition and UFieldPosition selector for 'M' field alignment,
276 * corresponding to the UCAL_MONTH field.
279 UDAT_MONTH_FIELD
= 2,
282 * FieldPosition and UFieldPosition selector for 'd' field alignment,
283 * corresponding to the UCAL_DATE field.
289 * FieldPosition and UFieldPosition selector for 'k' field alignment,
290 * corresponding to the UCAL_HOUR_OF_DAY field.
291 * UDAT_HOUR_OF_DAY1_FIELD is used for the one-based 24-hour clock.
292 * For example, 23:59 + 01:00 results in 24:59.
295 UDAT_HOUR_OF_DAY1_FIELD
= 4,
298 * FieldPosition and UFieldPosition selector for 'H' field alignment,
299 * corresponding to the UCAL_HOUR_OF_DAY field.
300 * UDAT_HOUR_OF_DAY0_FIELD is used for the zero-based 24-hour clock.
301 * For example, 23:59 + 01:00 results in 00:59.
304 UDAT_HOUR_OF_DAY0_FIELD
= 5,
307 * FieldPosition and UFieldPosition selector for 'm' field alignment,
308 * corresponding to the UCAL_MINUTE field.
311 UDAT_MINUTE_FIELD
= 6,
314 * FieldPosition and UFieldPosition selector for 's' field alignment,
315 * corresponding to the UCAL_SECOND field.
318 UDAT_SECOND_FIELD
= 7,
321 * FieldPosition and UFieldPosition selector for 'S' field alignment,
322 * corresponding to the UCAL_MILLISECOND field.
325 UDAT_FRACTIONAL_SECOND_FIELD
= 8,
328 * FieldPosition and UFieldPosition selector for 'E' field alignment,
329 * corresponding to the UCAL_DAY_OF_WEEK field.
332 UDAT_DAY_OF_WEEK_FIELD
= 9,
335 * FieldPosition and UFieldPosition selector for 'D' field alignment,
336 * corresponding to the UCAL_DAY_OF_YEAR field.
339 UDAT_DAY_OF_YEAR_FIELD
= 10,
342 * FieldPosition and UFieldPosition selector for 'F' field alignment,
343 * corresponding to the UCAL_DAY_OF_WEEK_IN_MONTH field.
346 UDAT_DAY_OF_WEEK_IN_MONTH_FIELD
= 11,
349 * FieldPosition and UFieldPosition selector for 'w' field alignment,
350 * corresponding to the UCAL_WEEK_OF_YEAR field.
353 UDAT_WEEK_OF_YEAR_FIELD
= 12,
356 * FieldPosition and UFieldPosition selector for 'W' field alignment,
357 * corresponding to the UCAL_WEEK_OF_MONTH field.
360 UDAT_WEEK_OF_MONTH_FIELD
= 13,
363 * FieldPosition and UFieldPosition selector for 'a' field alignment,
364 * corresponding to the UCAL_AM_PM field.
367 UDAT_AM_PM_FIELD
= 14,
370 * FieldPosition and UFieldPosition selector for 'h' field alignment,
371 * corresponding to the UCAL_HOUR field.
372 * UDAT_HOUR1_FIELD is used for the one-based 12-hour clock.
373 * For example, 11:30 PM + 1 hour results in 12:30 AM.
376 UDAT_HOUR1_FIELD
= 15,
379 * FieldPosition and UFieldPosition selector for 'K' field alignment,
380 * corresponding to the UCAL_HOUR field.
381 * UDAT_HOUR0_FIELD is used for the zero-based 12-hour clock.
382 * For example, 11:30 PM + 1 hour results in 00:30 AM.
385 UDAT_HOUR0_FIELD
= 16,
388 * FieldPosition and UFieldPosition selector for 'z' field alignment,
389 * corresponding to the UCAL_ZONE_OFFSET and
390 * UCAL_DST_OFFSET fields.
393 UDAT_TIMEZONE_FIELD
= 17,
396 * FieldPosition and UFieldPosition selector for 'Y' field alignment,
397 * corresponding to the UCAL_YEAR_WOY field.
400 UDAT_YEAR_WOY_FIELD
= 18,
403 * FieldPosition and UFieldPosition selector for 'e' field alignment,
404 * corresponding to the UCAL_DOW_LOCAL field.
407 UDAT_DOW_LOCAL_FIELD
= 19,
410 * FieldPosition and UFieldPosition selector for 'u' field alignment,
411 * corresponding to the UCAL_EXTENDED_YEAR field.
414 UDAT_EXTENDED_YEAR_FIELD
= 20,
417 * FieldPosition and UFieldPosition selector for 'g' field alignment,
418 * corresponding to the UCAL_JULIAN_DAY field.
421 UDAT_JULIAN_DAY_FIELD
= 21,
424 * FieldPosition and UFieldPosition selector for 'A' field alignment,
425 * corresponding to the UCAL_MILLISECONDS_IN_DAY field.
428 UDAT_MILLISECONDS_IN_DAY_FIELD
= 22,
431 * FieldPosition and UFieldPosition selector for 'Z' field alignment,
432 * corresponding to the UCAL_ZONE_OFFSET and
433 * UCAL_DST_OFFSET fields.
436 UDAT_TIMEZONE_RFC_FIELD
= 23,
439 * FieldPosition and UFieldPosition selector for 'v' field alignment,
440 * corresponding to the UCAL_ZONE_OFFSET field.
443 UDAT_TIMEZONE_GENERIC_FIELD
= 24,
445 * FieldPosition selector for 'c' field alignment,
446 * corresponding to the {@link #UCAL_DATE} field.
447 * This displays the stand alone day name, if available.
450 UDAT_STANDALONE_DAY_FIELD
= 25,
453 * FieldPosition selector for 'L' field alignment,
454 * corresponding to the {@link #UCAL_MONTH} field.
455 * This displays the stand alone month name, if available.
458 UDAT_STANDALONE_MONTH_FIELD
= 26,
461 * FieldPosition selector for "Q" field alignment,
462 * corresponding to quarters. This is implemented
463 * using the {@link #UCAL_MONTH} field. This
464 * displays the quarter.
467 UDAT_QUARTER_FIELD
= 27,
470 * FieldPosition selector for the "q" field alignment,
471 * corresponding to stand-alone quarters. This is
472 * implemented using the {@link #UCAL_MONTH} field.
473 * This displays the stand-alone quarter.
476 UDAT_STANDALONE_QUARTER_FIELD
= 28,
479 * FieldPosition and UFieldPosition selector for 'V' field alignment,
480 * corresponding to the UCAL_ZONE_OFFSET field.
483 UDAT_TIMEZONE_SPECIAL_FIELD
= 29,
486 * Number of FieldPosition and UFieldPosition selectors for
487 * DateFormat and UDateFormat.
488 * Valid selectors range from 0 to UDAT_FIELD_COUNT-1.
489 * This value is subject to change if new fields are defined
493 UDAT_FIELD_COUNT
= 30
498 * Open a new UDateFormat for formatting and parsing dates and times.
499 * A UDateFormat may be used to format dates in calls to {@link #udat_format },
500 * and to parse dates in calls to {@link #udat_parse }.
501 * @param timeStyle The style used to format times; one of UDAT_FULL, UDAT_LONG,
502 * UDAT_MEDIUM, UDAT_SHORT, UDAT_DEFAULT, or UDAT_NONE (relative time styles
503 * are not currently supported)
504 * @param dateStyle The style used to format dates; one of UDAT_FULL, UDAT_LONG,
505 * UDAT_MEDIUM, UDAT_SHORT, UDAT_DEFAULT, UDAT_FULL_RELATIVE, UDAT_LONG_RELATIVE,
506 * UDAT_MEDIUM_RELATIVE, UDAT_SHORT_RELATIVE, or UDAT_NONE
507 * @param locale The locale specifying the formatting conventions
508 * @param tzID A timezone ID specifying the timezone to use. If 0, use
509 * the default timezone.
510 * @param tzIDLength The length of tzID, or -1 if null-terminated.
511 * @param pattern A pattern specifying the format to use.
512 * @param patternLength The number of characters in the pattern, or -1 if null-terminated.
513 * @param status A pointer to an UErrorCode to receive any errors
514 * @return A pointer to a UDateFormat to use for formatting dates and times, or 0 if
518 U_STABLE UDateFormat
* U_EXPORT2
519 udat_open(UDateFormatStyle timeStyle
,
520 UDateFormatStyle dateStyle
,
524 const UChar
*pattern
,
525 int32_t patternLength
,
530 * Close a UDateFormat.
531 * Once closed, a UDateFormat may no longer be used.
532 * @param format The formatter to close.
535 U_STABLE
void U_EXPORT2
536 udat_close(UDateFormat
* format
);
539 * Open a copy of a UDateFormat.
540 * This function performs a deep copy.
541 * @param fmt The format to copy
542 * @param status A pointer to an UErrorCode to receive any errors.
543 * @return A pointer to a UDateFormat identical to fmt.
546 U_STABLE UDateFormat
* U_EXPORT2
547 udat_clone(const UDateFormat
*fmt
,
551 * Format a date using an UDateFormat.
552 * The date will be formatted using the conventions specified in {@link #udat_open }
553 * @param format The formatter to use
554 * @param dateToFormat The date to format
555 * @param result A pointer to a buffer to receive the formatted number.
556 * @param resultLength The maximum size of result.
557 * @param position A pointer to a UFieldPosition. On input, position->field
558 * is read. On output, position->beginIndex and position->endIndex indicate
559 * the beginning and ending indices of field number position->field, if such
560 * a field exists. This parameter may be NULL, in which case no field
561 * position data is returned.
562 * @param status A pointer to an UErrorCode to receive any errors
563 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
565 * @see UFieldPosition
568 U_STABLE
int32_t U_EXPORT2
569 udat_format( const UDateFormat
* format
,
572 int32_t resultLength
,
573 UFieldPosition
* position
,
577 * Parse a string into an date/time using a UDateFormat.
578 * The date will be parsed using the conventions specified in {@link #udat_open }
579 * @param format The formatter to use.
580 * @param text The text to parse.
581 * @param textLength The length of text, or -1 if null-terminated.
582 * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which
583 * to begin parsing. If not 0, on output the offset at which parsing ended.
584 * @param status A pointer to an UErrorCode to receive any errors
585 * @return The value of the parsed date/time
589 U_STABLE UDate U_EXPORT2
590 udat_parse( const UDateFormat
* format
,
597 * Parse a string into an date/time using a UDateFormat.
598 * The date will be parsed using the conventions specified in {@link #udat_open }
599 * @param format The formatter to use.
600 * @param calendar The calendar in which to store the parsed data.
601 * @param text The text to parse.
602 * @param textLength The length of text, or -1 if null-terminated.
603 * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which
604 * to begin parsing. If not 0, on output the offset at which parsing ended.
605 * @param status A pointer to an UErrorCode to receive any errors
609 U_STABLE
void U_EXPORT2
610 udat_parseCalendar(const UDateFormat
* format
,
618 * Determine if an UDateFormat will perform lenient parsing.
619 * With lenient parsing, the parser may use heuristics to interpret inputs that do not
620 * precisely match the pattern. With strict parsing, inputs must match the pattern.
621 * @param fmt The formatter to query
622 * @return TRUE if fmt is set to perform lenient parsing, FALSE otherwise.
623 * @see udat_setLenient
626 U_STABLE UBool U_EXPORT2
627 udat_isLenient(const UDateFormat
* fmt
);
630 * Specify whether an UDateFormat will perform lenient parsing.
631 * With lenient parsing, the parser may use heuristics to interpret inputs that do not
632 * precisely match the pattern. With strict parsing, inputs must match the pattern.
633 * @param fmt The formatter to set
634 * @param isLenient TRUE if fmt should perform lenient parsing, FALSE otherwise.
638 U_STABLE
void U_EXPORT2
639 udat_setLenient( UDateFormat
* fmt
,
643 * Get the UCalendar associated with an UDateFormat.
644 * A UDateFormat uses a UCalendar to convert a raw value to, for example,
645 * the day of the week.
646 * @param fmt The formatter to query.
647 * @return A pointer to the UCalendar used by fmt.
648 * @see udat_setCalendar
651 U_STABLE
const UCalendar
* U_EXPORT2
652 udat_getCalendar(const UDateFormat
* fmt
);
655 * Set the UCalendar associated with an UDateFormat.
656 * A UDateFormat uses a UCalendar to convert a raw value to, for example,
657 * the day of the week.
658 * @param fmt The formatter to set.
659 * @param calendarToSet A pointer to an UCalendar to be used by fmt.
660 * @see udat_setCalendar
663 U_STABLE
void U_EXPORT2
664 udat_setCalendar( UDateFormat
* fmt
,
665 const UCalendar
* calendarToSet
);
668 * Get the UNumberFormat associated with an UDateFormat.
669 * A UDateFormat uses a UNumberFormat to format numbers within a date,
670 * for example the day number.
671 * @param fmt The formatter to query.
672 * @return A pointer to the UNumberFormat used by fmt to format numbers.
673 * @see udat_setNumberFormat
676 U_STABLE
const UNumberFormat
* U_EXPORT2
677 udat_getNumberFormat(const UDateFormat
* fmt
);
680 * Set the UNumberFormat associated with an UDateFormat.
681 * A UDateFormat uses a UNumberFormat to format numbers within a date,
682 * for example the day number.
683 * @param fmt The formatter to set.
684 * @param numberFormatToSet A pointer to the UNumberFormat to be used by fmt to format numbers.
685 * @see udat_getNumberFormat
688 U_STABLE
void U_EXPORT2
689 udat_setNumberFormat( UDateFormat
* fmt
,
690 const UNumberFormat
* numberFormatToSet
);
693 * Get a locale for which date/time formatting patterns are available.
694 * A UDateFormat in a locale returned by this function will perform the correct
695 * formatting and parsing for the locale.
696 * @param localeIndex The index of the desired locale.
697 * @return A locale for which date/time formatting patterns are available, or 0 if none.
698 * @see udat_countAvailable
701 U_STABLE
const char* U_EXPORT2
702 udat_getAvailable(int32_t localeIndex
);
705 * Determine how many locales have date/time formatting patterns available.
706 * This function is most useful as determining the loop ending condition for
707 * calls to {@link #udat_getAvailable }.
708 * @return The number of locales for which date/time formatting patterns are available.
709 * @see udat_getAvailable
712 U_STABLE
int32_t U_EXPORT2
713 udat_countAvailable(void);
716 * Get the year relative to which all 2-digit years are interpreted.
717 * For example, if the 2-digit start year is 2100, the year 99 will be
718 * interpreted as 2199.
719 * @param fmt The formatter to query.
720 * @param status A pointer to an UErrorCode to receive any errors
721 * @return The year relative to which all 2-digit years are interpreted.
722 * @see udat_Set2DigitYearStart
725 U_STABLE UDate U_EXPORT2
726 udat_get2DigitYearStart( const UDateFormat
*fmt
,
730 * Set the year relative to which all 2-digit years will be interpreted.
731 * For example, if the 2-digit start year is 2100, the year 99 will be
732 * interpreted as 2199.
733 * @param fmt The formatter to set.
734 * @param d The year relative to which all 2-digit years will be interpreted.
735 * @param status A pointer to an UErrorCode to receive any errors
736 * @see udat_Set2DigitYearStart
739 U_STABLE
void U_EXPORT2
740 udat_set2DigitYearStart( UDateFormat
*fmt
,
745 * Extract the pattern from a UDateFormat.
746 * The pattern will follow the pattern syntax rules.
747 * @param fmt The formatter to query.
748 * @param localized TRUE if the pattern should be localized, FALSE otherwise.
749 * @param result A pointer to a buffer to receive the pattern.
750 * @param resultLength The maximum size of result.
751 * @param status A pointer to an UErrorCode to receive any errors
752 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
753 * @see udat_applyPattern
756 U_STABLE
int32_t U_EXPORT2
757 udat_toPattern( const UDateFormat
*fmt
,
760 int32_t resultLength
,
764 * Set the pattern used by an UDateFormat.
765 * The pattern should follow the pattern syntax rules.
766 * @param format The formatter to set.
767 * @param localized TRUE if the pattern is localized, FALSE otherwise.
768 * @param pattern The new pattern
769 * @param patternLength The length of pattern, or -1 if null-terminated.
770 * @see udat_toPattern
773 U_STABLE
void U_EXPORT2
774 udat_applyPattern( UDateFormat
*format
,
776 const UChar
*pattern
,
777 int32_t patternLength
);
780 * The possible types of date format symbols
783 typedef enum UDateFormatSymbolType
{
784 /** The era names, for example AD */
786 /** The month names, for example February */
788 /** The short month names, for example Feb. */
790 /** The weekday names, for example Monday */
792 /** The short weekday names, for example Mon. */
794 /** The AM/PM names, for example AM */
796 /** The localized characters */
797 UDAT_LOCALIZED_CHARS
,
798 /** The long era names, for example Anno Domini */
800 /** The narrow month names, for example F */
802 /** The narrow weekday names, for example N */
803 UDAT_NARROW_WEEKDAYS
,
804 /** Standalone context versions of months */
805 UDAT_STANDALONE_MONTHS
,
806 UDAT_STANDALONE_SHORT_MONTHS
,
807 UDAT_STANDALONE_NARROW_MONTHS
,
808 /** Standalone context versions of weekdays */
809 UDAT_STANDALONE_WEEKDAYS
,
810 UDAT_STANDALONE_SHORT_WEEKDAYS
,
811 UDAT_STANDALONE_NARROW_WEEKDAYS
,
812 /** The quarters, for example 1st Quarter */
814 /** The short quarter names, for example Q1 */
816 /** Standalone context versions of quarters */
817 UDAT_STANDALONE_QUARTERS
,
818 UDAT_STANDALONE_SHORT_QUARTERS
820 } UDateFormatSymbolType
;
822 struct UDateFormatSymbols
;
823 /** Date format symbols.
824 * For usage in C programs.
827 typedef struct UDateFormatSymbols UDateFormatSymbols
;
830 * Get the symbols associated with an UDateFormat.
831 * The symbols are what a UDateFormat uses to represent locale-specific data,
832 * for example month or day names.
833 * @param fmt The formatter to query.
834 * @param type The type of symbols to get. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS,
835 * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS
836 * @param symbolIndex The desired symbol of type type.
837 * @param result A pointer to a buffer to receive the pattern.
838 * @param resultLength The maximum size of result.
839 * @param status A pointer to an UErrorCode to receive any errors
840 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
841 * @see udat_countSymbols
842 * @see udat_setSymbols
845 U_STABLE
int32_t U_EXPORT2
846 udat_getSymbols(const UDateFormat
*fmt
,
847 UDateFormatSymbolType type
,
850 int32_t resultLength
,
854 * Count the number of particular symbols for an UDateFormat.
855 * This function is most useful as for detemining the loop termination condition
856 * for calls to {@link #udat_getSymbols }.
857 * @param fmt The formatter to query.
858 * @param type The type of symbols to count. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS,
859 * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS
860 * @return The number of symbols of type type.
861 * @see udat_getSymbols
862 * @see udat_setSymbols
865 U_STABLE
int32_t U_EXPORT2
866 udat_countSymbols( const UDateFormat
*fmt
,
867 UDateFormatSymbolType type
);
870 * Set the symbols associated with an UDateFormat.
871 * The symbols are what a UDateFormat uses to represent locale-specific data,
872 * for example month or day names.
873 * @param format The formatter to set
874 * @param type The type of symbols to set. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS,
875 * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS
876 * @param symbolIndex The index of the symbol to set of type type.
877 * @param value The new value
878 * @param valueLength The length of value, or -1 if null-terminated
879 * @param status A pointer to an UErrorCode to receive any errors
880 * @see udat_getSymbols
881 * @see udat_countSymbols
884 U_STABLE
void U_EXPORT2
885 udat_setSymbols( UDateFormat
*format
,
886 UDateFormatSymbolType type
,
893 * Get the locale for this date format object.
894 * You can choose between valid and actual locale.
895 * @param fmt The formatter to get the locale from
896 * @param type type of the locale we're looking for (valid or actual)
897 * @param status error code for the operation
898 * @return the locale name
901 U_STABLE
const char* U_EXPORT2
902 udat_getLocaleByType(const UDateFormat
*fmt
,
903 ULocDataLocaleType type
,
907 * Extract the date pattern from a UDateFormat set for relative date formatting.
908 * The pattern will follow the pattern syntax rules.
909 * @param fmt The formatter to query.
910 * @param result A pointer to a buffer to receive the pattern.
911 * @param resultLength The maximum size of result.
912 * @param status A pointer to a UErrorCode to receive any errors
913 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
914 * @see udat_applyPatternRelative
915 * @internal ICU 4.2 technology preview
917 U_INTERNAL
int32_t U_EXPORT2
918 udat_toPatternRelativeDate(const UDateFormat
*fmt
,
920 int32_t resultLength
,
924 * Extract the time pattern from a UDateFormat set for relative date formatting.
925 * The pattern will follow the pattern syntax rules.
926 * @param fmt The formatter to query.
927 * @param result A pointer to a buffer to receive the pattern.
928 * @param resultLength The maximum size of result.
929 * @param status A pointer to a UErrorCode to receive any errors
930 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
931 * @see udat_applyPatternRelative
932 * @internal ICU 4.2 technology preview
934 U_INTERNAL
int32_t U_EXPORT2
935 udat_toPatternRelativeTime(const UDateFormat
*fmt
,
937 int32_t resultLength
,
941 * Set the date & time patterns used by a UDateFormat set for relative date formatting.
942 * The patterns should follow the pattern syntax rules.
943 * @param format The formatter to set.
944 * @param datePattern The new date pattern
945 * @param datePatternLength The length of datePattern, or -1 if null-terminated.
946 * @param timePattern The new time pattern
947 * @param timePatternLength The length of timePattern, or -1 if null-terminated.
948 * @param status A pointer to a UErrorCode to receive any errors
949 * @see udat_toPatternRelativeDate, udat_toPatternRelativeTime
950 * @internal ICU 4.2 technology preview
952 U_INTERNAL
void U_EXPORT2
953 udat_applyPatternRelative(UDateFormat
*format
,
954 const UChar
*datePattern
,
955 int32_t datePatternLength
,
956 const UChar
*timePattern
,
957 int32_t timePatternLength
,
960 #endif /* #if !UCONFIG_NO_FORMATTING */