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