]> git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/unicode/udat.h
ICU-6.2.8.tar.gz
[apple/icu.git] / icuSources / i18n / unicode / udat.h
1 /*
2 *******************************************************************************
3 * Copyright (C) 1996-2004, International Business Machines Corporation and others. All Rights Reserved.
4 *******************************************************************************
5 */
6
7 #ifndef UDAT_H
8 #define UDAT_H
9
10 #include "unicode/utypes.h"
11
12 #if !UCONFIG_NO_FORMATTING
13
14 #include "unicode/ucal.h"
15 #include "unicode/unum.h"
16 /**
17 * \file
18 * \brief C API: DateFormat
19 *
20 * <h2> Date Format C API</h2>
21 *
22 * Date Format C API consists of functions that convert dates and
23 * times from their internal representations to textual form and back again in a
24 * language-independent manner. Converting from the internal representation (milliseconds
25 * since midnight, January 1, 1970) to text is known as "formatting," and converting
26 * from text to millis is known as "parsing." We currently define only one concrete
27 * structure UDateFormat, which can handle pretty much all normal
28 * date formatting and parsing actions.
29 * <P>
30 * Date Format helps you to format and parse dates for any locale. Your code can
31 * be completely independent of the locale conventions for months, days of the
32 * week, or even the calendar format: lunar vs. solar.
33 * <P>
34 * To format a date for the current Locale with default time and date style,
35 * use one of the static factory methods:
36 * <pre>
37 * \code
38 * UErrorCode status = U_ZERO_ERROR;
39 * UChar *myString;
40 * int32_t myStrlen = 0;
41 * UDateFormat* dfmt = udat_open(UDAT_DEFAULT, UDAT_DEFAULT, NULL, NULL, -1, NULL, -1, &status);
42 * myStrlen = udat_format(dfmt, myDate, NULL, myStrlen, NULL, &status);
43 * if (status==U_BUFFER_OVERFLOW_ERROR){
44 * status=U_ZERO_ERROR;
45 * myString=(UChar*)malloc(sizeof(UChar) * (myStrlen+1) );
46 * udat_format(dfmt, myDate, myString, myStrlen+1, NULL, &status);
47 * }
48 * \endcode
49 * </pre>
50 * If you are formatting multiple numbers, it is more efficient to get the
51 * format and use it multiple times so that the system doesn't have to fetch the
52 * information about the local language and country conventions multiple times.
53 * <pre>
54 * \code
55 * UErrorCode status = U_ZERO_ERROR;
56 * int32_t i, myStrlen = 0;
57 * UChar* myString;
58 * char buffer[1024];
59 * UDate myDateArr[] = { 0.0, 100000000.0, 2000000000.0 }; // test values
60 * UDateFormat* df = udat_open(UDAT_DEFAULT, UDAT_DEFAULT, NULL, NULL, -1, NULL, 0, &status);
61 * for (i = 0; i < 3; i++) {
62 * myStrlen = udat_format(df, myDateArr[i], NULL, myStrlen, NULL, &status);
63 * if(status == U_BUFFER_OVERFLOW_ERROR){
64 * status = U_ZERO_ERROR;
65 * myString = (UChar*)malloc(sizeof(UChar) * (myStrlen+1) );
66 * udat_format(df, myDateArr[i], myString, myStrlen+1, NULL, &status);
67 * printf("%s\n", u_austrcpy(buffer, myString) );
68 * free(myString);
69 * }
70 * }
71 * \endcode
72 * </pre>
73 * To get specific fields of a date, you can use UFieldPosition to
74 * get specific fields.
75 * <pre>
76 * \code
77 * UErrorCode status = U_ZERO_ERROR;
78 * UFieldPosition pos;
79 * UChar *myString;
80 * int32_t myStrlen = 0;
81 * char buffer[1024];
82 *
83 * pos.field = 1; // Same as the DateFormat::EField enum
84 * UDateFormat* dfmt = udat_open(UDAT_DEFAULT, UDAT_DEFAULT, NULL, -1, NULL, 0, &status);
85 * myStrlen = udat_format(dfmt, myDate, NULL, myStrlen, &pos, &status);
86 * if (status==U_BUFFER_OVERFLOW_ERROR){
87 * status=U_ZERO_ERROR;
88 * myString=(UChar*)malloc(sizeof(UChar) * (myStrlen+1) );
89 * udat_format(dfmt, myDate, myString, myStrlen+1, &pos, &status);
90 * }
91 * printf("date format: %s\n", u_austrcpy(buffer, myString));
92 * buffer[pos.endIndex] = 0; // NULL terminate the string.
93 * printf("UFieldPosition position equals %s\n", &buffer[pos.beginIndex]);
94 * \endcode
95 * </pre>
96 * To format a date for a different Locale, specify it in the call to
97 * udat_open()
98 * <pre>
99 * \code
100 * UDateFormat* df = udat_open(UDAT_SHORT, UDAT_SHORT, "fr_FR", NULL, -1, NULL, 0, &status);
101 * \endcode
102 * </pre>
103 * You can use a DateFormat API udat_parse() to parse.
104 * <pre>
105 * \code
106 * UErrorCode status = U_ZERO_ERROR;
107 * int32_t parsepos=0;
108 * UDate myDate = udat_parse(df, myString, u_strlen(myString), &parsepos, &status);
109 * \endcode
110 * </pre>
111 * You can pass in different options for the arguments for date and time style
112 * to control the length of the result; from SHORT to MEDIUM to LONG to FULL.
113 * The exact result depends on the locale, but generally:
114 * see UDateFormatStyle for more details
115 * <ul type=round>
116 * <li> UDAT_SHORT is completely numeric, such as 12/13/52 or 3:30pm
117 * <li> UDAT_MEDIUM is longer, such as Jan 12, 1952
118 * <li> UDAT_LONG is longer, such as January 12, 1952 or 3:30:32pm
119 * <li> UDAT_FULL is pretty completely specified, such as
120 * Tuesday, April 12, 1952 AD or 3:30:42pm PST.
121 * </ul>
122 * You can also set the time zone on the format if you wish.
123 * <P>
124 * You can also use forms of the parse and format methods with Parse Position and
125 * UFieldPosition to allow you to
126 * <ul type=round>
127 * <li> Progressively parse through pieces of a string.
128 * <li> Align any particular field, or find out where it is for selection
129 * on the screen.
130 * </ul>
131 */
132
133 /** A date formatter.
134 * For usage in C programs.
135 * @stable ICU 2.6
136 */
137 typedef void* UDateFormat;
138
139 /** The possible date/time format styles
140 * @stable ICU 2.6
141 */
142 typedef enum UDateFormatStyle {
143 /** Full style */
144 UDAT_FULL,
145 /** Long style */
146 UDAT_LONG,
147 /** Medium style */
148 UDAT_MEDIUM,
149 /** Short style */
150 UDAT_SHORT,
151 /** Default style */
152 UDAT_DEFAULT = UDAT_MEDIUM,
153 /** No style */
154 UDAT_NONE = -1,
155 /** for internal API use only */
156 UDAT_IGNORE = -2
157
158 } UDateFormatStyle;
159
160 /**
161 * FieldPosition and UFieldPosition selectors for format fields
162 * defined by DateFormat and UDateFormat.
163 * @draft ICU 3.0
164 */
165 typedef enum UDateFormatField {
166 /**
167 * FieldPosition and UFieldPosition selector for 'G' field alignment,
168 * corresponding to the UCAL_ERA field.
169 * @draft ICU 3.0
170 */
171 UDAT_ERA_FIELD = 0,
172
173 /**
174 * FieldPosition and UFieldPosition selector for 'y' field alignment,
175 * corresponding to the UCAL_YEAR field.
176 * @draft ICU 3.0
177 */
178 UDAT_YEAR_FIELD = 1,
179
180 /**
181 * FieldPosition and UFieldPosition selector for 'M' field alignment,
182 * corresponding to the UCAL_MONTH field.
183 * @draft ICU 3.0
184 */
185 UDAT_MONTH_FIELD = 2,
186
187 /**
188 * FieldPosition and UFieldPosition selector for 'd' field alignment,
189 * corresponding to the UCAL_DATE field.
190 * @draft ICU 3.0
191 */
192 UDAT_DATE_FIELD = 3,
193
194 /**
195 * FieldPosition and UFieldPosition selector for 'k' field alignment,
196 * corresponding to the UCAL_HOUR_OF_DAY field.
197 * UDAT_HOUR_OF_DAY1_FIELD is used for the one-based 24-hour clock.
198 * For example, 23:59 + 01:00 results in 24:59.
199 * @draft ICU 3.0
200 */
201 UDAT_HOUR_OF_DAY1_FIELD = 4,
202
203 /**
204 * FieldPosition and UFieldPosition selector for 'H' field alignment,
205 * corresponding to the UCAL_HOUR_OF_DAY field.
206 * UDAT_HOUR_OF_DAY0_FIELD is used for the zero-based 24-hour clock.
207 * For example, 23:59 + 01:00 results in 00:59.
208 * @draft ICU 3.0
209 */
210 UDAT_HOUR_OF_DAY0_FIELD = 5,
211
212 /**
213 * FieldPosition and UFieldPosition selector for 'm' field alignment,
214 * corresponding to the UCAL_MINUTE field.
215 * @draft ICU 3.0
216 */
217 UDAT_MINUTE_FIELD = 6,
218
219 /**
220 * FieldPosition and UFieldPosition selector for 's' field alignment,
221 * corresponding to the UCAL_SECOND field.
222 * @draft ICU 3.0
223 */
224 UDAT_SECOND_FIELD = 7,
225
226 /**
227 * FieldPosition and UFieldPosition selector for 'S' field alignment,
228 * corresponding to the UCAL_MILLISECOND field.
229 * @draft ICU 3.0
230 */
231 UDAT_FRACTIONAL_SECOND_FIELD = 8,
232
233 /**
234 * FieldPosition and UFieldPosition selector for 'E' field alignment,
235 * corresponding to the UCAL_DAY_OF_WEEK field.
236 * @draft ICU 3.0
237 */
238 UDAT_DAY_OF_WEEK_FIELD = 9,
239
240 /**
241 * FieldPosition and UFieldPosition selector for 'D' field alignment,
242 * corresponding to the UCAL_DAY_OF_YEAR field.
243 * @draft ICU 3.0
244 */
245 UDAT_DAY_OF_YEAR_FIELD = 10,
246
247 /**
248 * FieldPosition and UFieldPosition selector for 'F' field alignment,
249 * corresponding to the UCAL_DAY_OF_WEEK_IN_MONTH field.
250 * @draft ICU 3.0
251 */
252 UDAT_DAY_OF_WEEK_IN_MONTH_FIELD = 11,
253
254 /**
255 * FieldPosition and UFieldPosition selector for 'w' field alignment,
256 * corresponding to the UCAL_WEEK_OF_YEAR field.
257 * @draft ICU 3.0
258 */
259 UDAT_WEEK_OF_YEAR_FIELD = 12,
260
261 /**
262 * FieldPosition and UFieldPosition selector for 'W' field alignment,
263 * corresponding to the UCAL_WEEK_OF_MONTH field.
264 * @draft ICU 3.0
265 */
266 UDAT_WEEK_OF_MONTH_FIELD = 13,
267
268 /**
269 * FieldPosition and UFieldPosition selector for 'a' field alignment,
270 * corresponding to the UCAL_AM_PM field.
271 * @draft ICU 3.0
272 */
273 UDAT_AM_PM_FIELD = 14,
274
275 /**
276 * FieldPosition and UFieldPosition selector for 'h' field alignment,
277 * corresponding to the UCAL_HOUR field.
278 * UDAT_HOUR1_FIELD is used for the one-based 12-hour clock.
279 * For example, 11:30 PM + 1 hour results in 12:30 AM.
280 * @draft ICU 3.0
281 */
282 UDAT_HOUR1_FIELD = 15,
283
284 /**
285 * FieldPosition and UFieldPosition selector for 'K' field alignment,
286 * corresponding to the UCAL_HOUR field.
287 * UDAT_HOUR0_FIELD is used for the zero-based 12-hour clock.
288 * For example, 11:30 PM + 1 hour results in 00:30 AM.
289 * @draft ICU 3.0
290 */
291 UDAT_HOUR0_FIELD = 16,
292
293 /**
294 * FieldPosition and UFieldPosition selector for 'z' field alignment,
295 * corresponding to the UCAL_ZONE_OFFSET and
296 * UCAL_DST_OFFSET fields.
297 * @draft ICU 3.0
298 */
299 UDAT_TIMEZONE_FIELD = 17,
300
301 /**
302 * FieldPosition and UFieldPosition selector for 'Y' field alignment,
303 * corresponding to the UCAL_YEAR_WOY field.
304 * @draft ICU 3.0
305 */
306 UDAT_YEAR_WOY_FIELD = 18,
307
308 /**
309 * FieldPosition and UFieldPosition selector for 'e' field alignment,
310 * corresponding to the UCAL_DOW_LOCAL field.
311 * @draft ICU 3.0
312 */
313 UDAT_DOW_LOCAL_FIELD = 19,
314
315 /**
316 * FieldPosition and UFieldPosition selector for 'u' field alignment,
317 * corresponding to the UCAL_EXTENDED_YEAR field.
318 * @draft ICU 3.0
319 */
320 UDAT_EXTENDED_YEAR_FIELD = 20,
321
322 /**
323 * FieldPosition and UFieldPosition selector for 'g' field alignment,
324 * corresponding to the UCAL_JULIAN_DAY field.
325 * @draft ICU 3.0
326 */
327 UDAT_JULIAN_DAY_FIELD = 21,
328
329 /**
330 * FieldPosition and UFieldPosition selector for 'A' field alignment,
331 * corresponding to the UCAL_MILLISECONDS_IN_DAY field.
332 * @draft ICU 3.0
333 */
334 UDAT_MILLISECONDS_IN_DAY_FIELD = 22,
335
336 /**
337 * FieldPosition and UFieldPosition selector for 'Z' field alignment,
338 * corresponding to the UCAL_ZONE_OFFSET and
339 * UCAL_DST_OFFSET fields.
340 * @draft ICU 3.0
341 */
342 UDAT_TIMEZONE_RFC_FIELD = 23,
343
344 /**
345 * Number of FieldPosition and UFieldPosition selectors for
346 * DateFormat and UDateFormat.
347 * Valid selectors range from 0 to UDAT_FIELD_COUNT-1.
348 * This value is subject to change if new fields are defined
349 * in the future.
350 * @draft ICU 3.0
351 */
352 UDAT_FIELD_COUNT = 24
353
354 } UDateFormatField;
355
356 /**
357 * Open a new UDateFormat for formatting and parsing dates and times.
358 * A UDateFormat may be used to format dates in calls to {@link #udat_format },
359 * and to parse dates in calls to {@link #udat_parse }.
360 * @param timeStyle The style used to format times; one of UDAT_FULL, UDAT_LONG,
361 * UDAT_MEDIUM, UDAT_SHORT, or UDAT_DEFAULT
362 * @param dateStyle The style used to format dates; one of UDAT_FULL, UDAT_LONG,
363 * UDAT_MEDIUM, UDAT_SHORT, or UDAT_DEFAULT
364 * @param locale The locale specifying the formatting conventions
365 * @param tzID A timezone ID specifying the timezone to use. If 0, use
366 * the default timezone.
367 * @param tzIDLength The length of tzID, or -1 if null-terminated.
368 * @param pattern A pattern specifying the format to use.
369 * @param patternLength The number of characters in the pattern, or -1 if null-terminated.
370 * @param status A pointer to an UErrorCode to receive any errors
371 * @return A pointer to a UDateFormat to use for formatting dates and times, or 0 if
372 * an error occurred.
373 * @stable ICU 2.0
374 */
375 U_STABLE UDateFormat* U_EXPORT2
376 udat_open(UDateFormatStyle timeStyle,
377 UDateFormatStyle dateStyle,
378 const char *locale,
379 const UChar *tzID,
380 int32_t tzIDLength,
381 const UChar *pattern,
382 int32_t patternLength,
383 UErrorCode *status);
384
385
386 /**
387 * Close a UDateFormat.
388 * Once closed, a UDateFormat may no longer be used.
389 * @param format The formatter to close.
390 * @stable ICU 2.0
391 */
392 U_STABLE void U_EXPORT2
393 udat_close(UDateFormat* format);
394
395 /**
396 * Open a copy of a UDateFormat.
397 * This function performs a deep copy.
398 * @param fmt The format to copy
399 * @param status A pointer to an UErrorCode to receive any errors.
400 * @return A pointer to a UDateFormat identical to fmt.
401 * @stable ICU 2.0
402 */
403 U_STABLE UDateFormat* U_EXPORT2
404 udat_clone(const UDateFormat *fmt,
405 UErrorCode *status);
406
407 /**
408 * Format a date using an UDateFormat.
409 * The date will be formatted using the conventions specified in {@link #udat_open }
410 * @param format The formatter to use
411 * @param dateToFormat The date to format
412 * @param result A pointer to a buffer to receive the formatted number.
413 * @param resultLength The maximum size of result.
414 * @param position A pointer to a UFieldPosition. On input, position->field
415 * is read. On output, position->beginIndex and position->endIndex indicate
416 * the beginning and ending indices of field number position->field, if such
417 * a field exists. This parameter may be NULL, in which case no field
418 * position data is returned.
419 * @param status A pointer to an UErrorCode to receive any errors
420 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
421 * @see udat_parse
422 * @see UFieldPosition
423 * @stable ICU 2.0
424 */
425 U_STABLE int32_t U_EXPORT2
426 udat_format( const UDateFormat* format,
427 UDate dateToFormat,
428 UChar* result,
429 int32_t resultLength,
430 UFieldPosition* position,
431 UErrorCode* status);
432
433 /**
434 * Parse a string into an date/time using a UDateFormat.
435 * The date will be parsed using the conventions specified in {@link #udat_open }
436 * @param format The formatter to use.
437 * @param text The text to parse.
438 * @param textLength The length of text, or -1 if null-terminated.
439 * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which
440 * to begin parsing. If not 0, on output the offset at which parsing ended.
441 * @param status A pointer to an UErrorCode to receive any errors
442 * @return The value of the parsed date/time
443 * @see udat_format
444 * @stable ICU 2.0
445 */
446 U_STABLE UDate U_EXPORT2
447 udat_parse( const UDateFormat* format,
448 const UChar* text,
449 int32_t textLength,
450 int32_t *parsePos,
451 UErrorCode *status);
452
453 /**
454 * Parse a string into an date/time using a UDateFormat.
455 * The date will be parsed using the conventions specified in {@link #udat_open }
456 * @param format The formatter to use.
457 * @param calendar The calendar in which to store the parsed data.
458 * @param text The text to parse.
459 * @param textLength The length of text, or -1 if null-terminated.
460 * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which
461 * to begin parsing. If not 0, on output the offset at which parsing ended.
462 * @param status A pointer to an UErrorCode to receive any errors
463 * @see udat_format
464 * @stable ICU 2.0
465 */
466 U_STABLE void U_EXPORT2
467 udat_parseCalendar(const UDateFormat* format,
468 UCalendar* calendar,
469 const UChar* text,
470 int32_t textLength,
471 int32_t *parsePos,
472 UErrorCode *status);
473
474 /**
475 * Determine if an UDateFormat will perform lenient parsing.
476 * With lenient parsing, the parser may use heuristics to interpret inputs that do not
477 * precisely match the pattern. With strict parsing, inputs must match the pattern.
478 * @param fmt The formatter to query
479 * @return TRUE if fmt is set to perform lenient parsing, FALSE otherwise.
480 * @see udat_setLenient
481 * @stable ICU 2.0
482 */
483 U_STABLE UBool U_EXPORT2
484 udat_isLenient(const UDateFormat* fmt);
485
486 /**
487 * Specify whether an UDateFormat will perform lenient parsing.
488 * With lenient parsing, the parser may use heuristics to interpret inputs that do not
489 * precisely match the pattern. With strict parsing, inputs must match the pattern.
490 * @param fmt The formatter to set
491 * @param isLenient TRUE if fmt should perform lenient parsing, FALSE otherwise.
492 * @see dat_isLenient
493 * @stable ICU 2.0
494 */
495 U_STABLE void U_EXPORT2
496 udat_setLenient( UDateFormat* fmt,
497 UBool isLenient);
498
499 /**
500 * Get the UCalendar associated with an UDateFormat.
501 * A UDateFormat uses a UCalendar to convert a raw value to, for example,
502 * the day of the week.
503 * @param fmt The formatter to query.
504 * @return A pointer to the UCalendar used by fmt.
505 * @see udat_setCalendar
506 * @stable ICU 2.0
507 */
508 U_STABLE const UCalendar* U_EXPORT2
509 udat_getCalendar(const UDateFormat* fmt);
510
511 /**
512 * Set the UCalendar associated with an UDateFormat.
513 * A UDateFormat uses a UCalendar to convert a raw value to, for example,
514 * the day of the week.
515 * @param fmt The formatter to set.
516 * @param calendarToSet A pointer to an UCalendar to be used by fmt.
517 * @see udat_setCalendar
518 * @stable ICU 2.0
519 */
520 U_STABLE void U_EXPORT2
521 udat_setCalendar( UDateFormat* fmt,
522 const UCalendar* calendarToSet);
523
524 /**
525 * Get the UNumberFormat associated with an UDateFormat.
526 * A UDateFormat uses a UNumberFormat to format numbers within a date,
527 * for example the day number.
528 * @param fmt The formatter to query.
529 * @return A pointer to the UNumberFormat used by fmt to format numbers.
530 * @see udat_setNumberFormat
531 * @stable ICU 2.0
532 */
533 U_STABLE const UNumberFormat* U_EXPORT2
534 udat_getNumberFormat(const UDateFormat* fmt);
535
536 /**
537 * Set the UNumberFormat associated with an UDateFormat.
538 * A UDateFormat uses a UNumberFormat to format numbers within a date,
539 * for example the day number.
540 * @param fmt The formatter to set.
541 * @param numberFormatToSet A pointer to the UNumberFormat to be used by fmt to format numbers.
542 * @see udat_getNumberFormat
543 * @stable ICU 2.0
544 */
545 U_STABLE void U_EXPORT2
546 udat_setNumberFormat( UDateFormat* fmt,
547 const UNumberFormat* numberFormatToSet);
548
549 /**
550 * Get a locale for which date/time formatting patterns are available.
551 * A UDateFormat in a locale returned by this function will perform the correct
552 * formatting and parsing for the locale.
553 * @param index The index of the desired locale.
554 * @return A locale for which date/time formatting patterns are available, or 0 if none.
555 * @see udat_countAvailable
556 * @stable ICU 2.0
557 */
558 U_STABLE const char* U_EXPORT2
559 udat_getAvailable(int32_t index);
560
561 /**
562 * Determine how many locales have date/time formatting patterns available.
563 * This function is most useful as determining the loop ending condition for
564 * calls to {@link #udat_getAvailable }.
565 * @return The number of locales for which date/time formatting patterns are available.
566 * @see udat_getAvailable
567 * @stable ICU 2.0
568 */
569 U_STABLE int32_t U_EXPORT2
570 udat_countAvailable(void);
571
572 /**
573 * Get the year relative to which all 2-digit years are interpreted.
574 * For example, if the 2-digit start year is 2100, the year 99 will be
575 * interpreted as 2199.
576 * @param fmt The formatter to query.
577 * @param status A pointer to an UErrorCode to receive any errors
578 * @return The year relative to which all 2-digit years are interpreted.
579 * @see udat_Set2DigitYearStart
580 * @stable ICU 2.0
581 */
582 U_STABLE UDate U_EXPORT2
583 udat_get2DigitYearStart( const UDateFormat *fmt,
584 UErrorCode *status);
585
586 /**
587 * Set the year relative to which all 2-digit years will be interpreted.
588 * For example, if the 2-digit start year is 2100, the year 99 will be
589 * interpreted as 2199.
590 * @param fmt The formatter to set.
591 * @param d The year relative to which all 2-digit years will be interpreted.
592 * @param status A pointer to an UErrorCode to receive any errors
593 * @see udat_Set2DigitYearStart
594 * @stable ICU 2.0
595 */
596 U_STABLE void U_EXPORT2
597 udat_set2DigitYearStart( UDateFormat *fmt,
598 UDate d,
599 UErrorCode *status);
600
601 /**
602 * Extract the pattern from a UDateFormat.
603 * The pattern will follow the pattern syntax rules.
604 * @param fmt The formatter to query.
605 * @param localized TRUE if the pattern should be localized, FALSE otherwise.
606 * @param result A pointer to a buffer to receive the pattern.
607 * @param resultLength The maximum size of result.
608 * @param status A pointer to an UErrorCode to receive any errors
609 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
610 * @see udat_applyPattern
611 * @stable ICU 2.0
612 */
613 U_STABLE int32_t U_EXPORT2
614 udat_toPattern( const UDateFormat *fmt,
615 UBool localized,
616 UChar *result,
617 int32_t resultLength,
618 UErrorCode *status);
619
620 /**
621 * Set the pattern used by an UDateFormat.
622 * The pattern should follow the pattern syntax rules.
623 * @param format The formatter to set.
624 * @param localized TRUE if the pattern is localized, FALSE otherwise.
625 * @param pattern The new pattern
626 * @param patternLength The length of pattern, or -1 if null-terminated.
627 * @see udat_toPattern
628 * @stable ICU 2.0
629 */
630 U_STABLE void U_EXPORT2
631 udat_applyPattern( UDateFormat *format,
632 UBool localized,
633 const UChar *pattern,
634 int32_t patternLength);
635
636 /**
637 * The possible types of date format symbols
638 * @stable ICU 2.6
639 */
640 typedef enum UDateFormatSymbolType {
641 /** The era names, for example AD */
642 UDAT_ERAS,
643 /** The month names, for example February */
644 UDAT_MONTHS,
645 /** The short month names, for example Feb. */
646 UDAT_SHORT_MONTHS,
647 /** The weekday names, for example Monday */
648 UDAT_WEEKDAYS,
649 /** The short weekday names, for example Mon. */
650 UDAT_SHORT_WEEKDAYS,
651 /** The AM/PM names, for example AM */
652 UDAT_AM_PMS,
653 /** The localized characters */
654 UDAT_LOCALIZED_CHARS
655 } UDateFormatSymbolType;
656
657 struct UDateFormatSymbols;
658 /** Date format symbols.
659 * For usage in C programs.
660 * @stable ICU 2.6
661 */
662 typedef struct UDateFormatSymbols UDateFormatSymbols;
663
664 /**
665 * Get the symbols associated with an UDateFormat.
666 * The symbols are what a UDateFormat uses to represent locale-specific data,
667 * for example month or day names.
668 * @param fmt The formatter to query.
669 * @param type The type of symbols to get. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS,
670 * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS
671 * @param index The desired symbol of type type.
672 * @param result A pointer to a buffer to receive the pattern.
673 * @param resultLength The maximum size of result.
674 * @param status A pointer to an UErrorCode to receive any errors
675 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
676 * @see udat_countSymbols
677 * @see udat_setSymbols
678 * @stable ICU 2.0
679 */
680 U_STABLE int32_t U_EXPORT2
681 udat_getSymbols(const UDateFormat *fmt,
682 UDateFormatSymbolType type,
683 int32_t index,
684 UChar *result,
685 int32_t resultLength,
686 UErrorCode *status);
687
688 /**
689 * Count the number of particular symbols for an UDateFormat.
690 * This function is most useful as for detemining the loop termination condition
691 * for calls to {@link #udat_getSymbols }.
692 * @param fmt The formatter to query.
693 * @param type The type of symbols to count. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS,
694 * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS
695 * @return The number of symbols of type type.
696 * @see udat_getSymbols
697 * @see udat_setSymbols
698 * @stable ICU 2.0
699 */
700 U_STABLE int32_t U_EXPORT2
701 udat_countSymbols( const UDateFormat *fmt,
702 UDateFormatSymbolType type);
703
704 /**
705 * Set the symbols associated with an UDateFormat.
706 * The symbols are what a UDateFormat uses to represent locale-specific data,
707 * for example month or day names.
708 * @param format The formatter to set
709 * @param type The type of symbols to set. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS,
710 * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS
711 * @param index The index of the symbol to set of type type.
712 * @param value The new value
713 * @param valueLength The length of value, or -1 if null-terminated
714 * @param status A pointer to an UErrorCode to receive any errors
715 * @see udat_getSymbols
716 * @see udat_countSymbols
717 * @stable ICU 2.0
718 */
719 U_STABLE void U_EXPORT2
720 udat_setSymbols( UDateFormat *format,
721 UDateFormatSymbolType type,
722 int32_t index,
723 UChar *value,
724 int32_t valueLength,
725 UErrorCode *status);
726
727 /**
728 * Get the locale for this date format object.
729 * You can choose between valid and actual locale.
730 * @param fmt The formatter to get the locale from
731 * @param type type of the locale we're looking for (valid or actual)
732 * @param status error code for the operation
733 * @return the locale name
734 * @draft ICU 2.8 likely to change in ICU 3.0, based on feedback
735 */
736 U_DRAFT const char* U_EXPORT2
737 udat_getLocaleByType(const UDateFormat *fmt,
738 ULocDataLocaleType type,
739 UErrorCode* status);
740
741 #endif /* #if !UCONFIG_NO_FORMATTING */
742
743 #endif