]> git.saurik.com Git - apple/icu.git/blob - icuSources/i18n/unicode/udat.h
ICU-491.11.1.tar.gz
[apple/icu.git] / icuSources / i18n / unicode / udat.h
1 /*
2 *******************************************************************************
3 * Copyright (C) 1996-2012, International Business Machines
4 * Corporation and others. 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/localpointer.h"
16 #include "unicode/ucal.h"
17 #include "unicode/unum.h"
18 /**
19 * \file
20 * \brief C API: DateFormat
21 *
22 * <h2> Date Format C API</h2>
23 *
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.
31 * <P>
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.
35 * <P>
36 * To format a date for the current Locale with default time and date style,
37 * use one of the static factory methods:
38 * <pre>
39 * \code
40 * UErrorCode status = U_ZERO_ERROR;
41 * UChar *myString;
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);
49 * }
50 * \endcode
51 * </pre>
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.
55 * <pre>
56 * \code
57 * UErrorCode status = U_ZERO_ERROR;
58 * int32_t i, myStrlen = 0;
59 * UChar* myString;
60 * char buffer[1024];
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) );
70 * free(myString);
71 * }
72 * }
73 * \endcode
74 * </pre>
75 * To get specific fields of a date, you can use UFieldPosition to
76 * get specific fields.
77 * <pre>
78 * \code
79 * UErrorCode status = U_ZERO_ERROR;
80 * UFieldPosition pos;
81 * UChar *myString;
82 * int32_t myStrlen = 0;
83 * char buffer[1024];
84 *
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);
92 * }
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]);
96 * \endcode
97 * </pre>
98 * To format a date for a different Locale, specify it in the call to
99 * udat_open()
100 * <pre>
101 * \code
102 * UDateFormat* df = udat_open(UDAT_SHORT, UDAT_SHORT, "fr_FR", NULL, -1, NULL, 0, &status);
103 * \endcode
104 * </pre>
105 * You can use a DateFormat API udat_parse() to parse.
106 * <pre>
107 * \code
108 * UErrorCode status = U_ZERO_ERROR;
109 * int32_t parsepos=0;
110 * UDate myDate = udat_parse(df, myString, u_strlen(myString), &parsepos, &status);
111 * \endcode
112 * </pre>
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
117 * <ul type=round>
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.
123 * </ul>
124 * You can also set the time zone on the format if you wish.
125 * <P>
126 * You can also use forms of the parse and format methods with Parse Position and
127 * UFieldPosition to allow you to
128 * <ul type=round>
129 * <li> Progressively parse through pieces of a string.
130 * <li> Align any particular field, or find out where it is for selection
131 * on the screen.
132 * </ul>
133 */
134
135 /** A date formatter.
136 * For usage in C programs.
137 * @stable ICU 2.6
138 */
139 typedef void* UDateFormat;
140
141 /** The possible date/time format styles
142 * @stable ICU 2.6
143 */
144 typedef enum UDateFormatStyle {
145 /** Full style */
146 UDAT_FULL,
147 /** Long style */
148 UDAT_LONG,
149 /** Medium style */
150 UDAT_MEDIUM,
151 /** Short style */
152 UDAT_SHORT,
153 /** Default style */
154 UDAT_DEFAULT = UDAT_MEDIUM,
155
156 /** Bitfield for relative date */
157 UDAT_RELATIVE = (1 << 7),
158
159 UDAT_FULL_RELATIVE = UDAT_FULL | UDAT_RELATIVE,
160
161 UDAT_LONG_RELATIVE = UDAT_LONG | UDAT_RELATIVE,
162
163 UDAT_MEDIUM_RELATIVE = UDAT_MEDIUM | UDAT_RELATIVE,
164
165 UDAT_SHORT_RELATIVE = UDAT_SHORT | UDAT_RELATIVE,
166
167
168 /** No style */
169 UDAT_NONE = -1,
170 /** for internal API use only */
171 UDAT_IGNORE = -2
172
173 } UDateFormatStyle;
174
175 /* Cannot use #ifndef U_HIDE_DRAFT_API for UDateFormatContextType and UDateFormatContextValue
176 * since a SimpleDateFormat virtual method & data member depends on them */
177 /** Date format context types
178 * @draft ICU 49
179 */
180 typedef enum UDateFormatContextType {
181 /**
182 * Type (key) for specifying the capitalization context for which a date
183 * is to be formatted (possible values are in UDateFormatContextValue).
184 * @draft ICU 49
185 */
186 UDAT_CAPITALIZATION = 1
187 } UDateFormatContextType;
188
189 /** Values for date format context types
190 * @draft ICU 49
191 */
192 typedef enum UDateFormatContextValue {
193 /** Values for any UDateFormatContextType (key) */
194 /**
195 * Value for any UDateFormatContextType (such as UDAT_CAPITALIZATION) if the
196 * relevant context to be used in formatting a date is unknown (this is the
197 * default value for any UDateFormatContextType when no value has been
198 * explicitly specified for that UDateFormatContextType).
199 * @draft ICU 49
200 */
201 UDAT_CONTEXT_UNKNOWN = 0,
202 #if !UCONFIG_NO_BREAK_ITERATION
203 /** Values for type (key) UDAT_CAPITALIZATION */
204 /**
205 * UDAT_CAPITALIZATION value if a date (or date symbol) is to be formatted
206 * with capitalization appropriate for the middle of a sentence.
207 * @draft ICU 49
208 */
209 UDAT_CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE = 1,
210 /**
211 * UDAT_CAPITALIZATION value if a date (or date symbol) is to be formatted
212 * with capitalization appropriate for the beginning of a sentence.
213 * @draft ICU 49
214 */
215 UDAT_CAPITALIZATION_FOR_BEGINNING_OF_SENTENCE = 2,
216 /**
217 * UDAT_CAPITALIZATION value if a date (or date symbol) is to be formatted
218 * with capitalization appropriate for a user-interface list or menu item.
219 * @draft ICU 49
220 */
221 UDAT_CAPITALIZATION_FOR_UI_LIST_OR_MENU = 3,
222 /**
223 * UDAT_CAPITALIZATION value if a date (or date symbol) is to be formatted
224 * with capitalization appropriate for stand-alone usage such as an
225 * isolated name on a calendar page.
226 * @draft ICU 49
227 */
228 UDAT_CAPITALIZATION_FOR_STANDALONE = 4
229 #endif
230 } UDateFormatContextValue;
231
232 /**
233 * @{
234 * Below are a set of pre-defined skeletons.
235 *
236 * <P>
237 * A skeleton
238 * <ol>
239 * <li>
240 * only keeps the field pattern letter and ignores all other parts
241 * in a pattern, such as space, punctuations, and string literals.
242 * </li>
243 * <li>
244 * hides the order of fields.
245 * </li>
246 * <li>
247 * might hide a field's pattern letter length.
248 *
249 * For those non-digit calendar fields, the pattern letter length is
250 * important, such as MMM, MMMM, and MMMMM; EEE and EEEE,
251 * and the field's pattern letter length is honored.
252 *
253 * For the digit calendar fields, such as M or MM, d or dd, yy or yyyy,
254 * the field pattern length is ignored and the best match, which is defined
255 * in date time patterns, will be returned without honor the field pattern
256 * letter length in skeleton.
257 * </li>
258 * </ol>
259 *
260 * @stable ICU 4.0
261 */
262
263 #define UDAT_MINUTE_SECOND "ms"
264 #define UDAT_HOUR24_MINUTE "Hm"
265 #define UDAT_HOUR24_MINUTE_SECOND "Hms"
266 #define UDAT_HOUR_MINUTE_SECOND "hms"
267 #define UDAT_STANDALONE_MONTH "LLLL"
268 #define UDAT_ABBR_STANDALONE_MONTH "LLL"
269 #define UDAT_YEAR_QUARTER "yQQQ"
270 #define UDAT_YEAR_ABBR_QUARTER "yQ"
271
272 /** @} */
273
274 /**
275 * @{
276 * Below are a set of pre-defined skeletons that
277 * have pre-defined interval patterns in resource files.
278 * Users are encouraged to use them in date interval format factory methods.
279 *
280 * @stable ICU 4.0
281 */
282 #define UDAT_HOUR_MINUTE "hm"
283 #define UDAT_YEAR "y"
284 #define UDAT_DAY "d"
285 #define UDAT_NUM_MONTH_WEEKDAY_DAY "MEd"
286 #define UDAT_YEAR_NUM_MONTH "yM"
287 #define UDAT_NUM_MONTH_DAY "Md"
288 #define UDAT_YEAR_NUM_MONTH_WEEKDAY_DAY "yMEd"
289 #define UDAT_ABBR_MONTH_WEEKDAY_DAY "MMMEd"
290 #define UDAT_YEAR_MONTH "yMMMM"
291 #define UDAT_YEAR_ABBR_MONTH "yMMM"
292 #define UDAT_MONTH_DAY "MMMMd"
293 #define UDAT_ABBR_MONTH_DAY "MMMd"
294 #define UDAT_MONTH_WEEKDAY_DAY "MMMMEEEEd"
295 #define UDAT_YEAR_ABBR_MONTH_WEEKDAY_DAY "yMMMEd"
296 #define UDAT_YEAR_MONTH_WEEKDAY_DAY "yMMMMEEEEd"
297 #define UDAT_YEAR_MONTH_DAY "yMMMMd"
298 #define UDAT_YEAR_ABBR_MONTH_DAY "yMMMd"
299 #define UDAT_YEAR_NUM_MONTH_DAY "yMd"
300 #define UDAT_NUM_MONTH "M"
301 #define UDAT_ABBR_MONTH "MMM"
302 #define UDAT_MONTH "MMMM"
303 #define UDAT_HOUR_MINUTE_GENERIC_TZ "hmv"
304 #define UDAT_HOUR_MINUTE_TZ "hmz"
305 #define UDAT_HOUR "h"
306 #define UDAT_HOUR_GENERIC_TZ "hv"
307 #define UDAT_HOUR_TZ "hz"
308
309 /** @} */
310
311
312 /**
313 * FieldPosition and UFieldPosition selectors for format fields
314 * defined by DateFormat and UDateFormat.
315 * @stable ICU 3.0
316 */
317 typedef enum UDateFormatField {
318 /**
319 * FieldPosition and UFieldPosition selector for 'G' field alignment,
320 * corresponding to the UCAL_ERA field.
321 * @stable ICU 3.0
322 */
323 UDAT_ERA_FIELD = 0,
324
325 /**
326 * FieldPosition and UFieldPosition selector for 'y' field alignment,
327 * corresponding to the UCAL_YEAR field.
328 * @stable ICU 3.0
329 */
330 UDAT_YEAR_FIELD = 1,
331
332 /**
333 * FieldPosition and UFieldPosition selector for 'M' field alignment,
334 * corresponding to the UCAL_MONTH field.
335 * @stable ICU 3.0
336 */
337 UDAT_MONTH_FIELD = 2,
338
339 /**
340 * FieldPosition and UFieldPosition selector for 'd' field alignment,
341 * corresponding to the UCAL_DATE field.
342 * @stable ICU 3.0
343 */
344 UDAT_DATE_FIELD = 3,
345
346 /**
347 * FieldPosition and UFieldPosition selector for 'k' field alignment,
348 * corresponding to the UCAL_HOUR_OF_DAY field.
349 * UDAT_HOUR_OF_DAY1_FIELD is used for the one-based 24-hour clock.
350 * For example, 23:59 + 01:00 results in 24:59.
351 * @stable ICU 3.0
352 */
353 UDAT_HOUR_OF_DAY1_FIELD = 4,
354
355 /**
356 * FieldPosition and UFieldPosition selector for 'H' field alignment,
357 * corresponding to the UCAL_HOUR_OF_DAY field.
358 * UDAT_HOUR_OF_DAY0_FIELD is used for the zero-based 24-hour clock.
359 * For example, 23:59 + 01:00 results in 00:59.
360 * @stable ICU 3.0
361 */
362 UDAT_HOUR_OF_DAY0_FIELD = 5,
363
364 /**
365 * FieldPosition and UFieldPosition selector for 'm' field alignment,
366 * corresponding to the UCAL_MINUTE field.
367 * @stable ICU 3.0
368 */
369 UDAT_MINUTE_FIELD = 6,
370
371 /**
372 * FieldPosition and UFieldPosition selector for 's' field alignment,
373 * corresponding to the UCAL_SECOND field.
374 * @stable ICU 3.0
375 */
376 UDAT_SECOND_FIELD = 7,
377
378 /**
379 * FieldPosition and UFieldPosition selector for 'S' field alignment,
380 * corresponding to the UCAL_MILLISECOND field.
381 * @stable ICU 3.0
382 */
383 UDAT_FRACTIONAL_SECOND_FIELD = 8,
384
385 /**
386 * FieldPosition and UFieldPosition selector for 'E' field alignment,
387 * corresponding to the UCAL_DAY_OF_WEEK field.
388 * @stable ICU 3.0
389 */
390 UDAT_DAY_OF_WEEK_FIELD = 9,
391
392 /**
393 * FieldPosition and UFieldPosition selector for 'D' field alignment,
394 * corresponding to the UCAL_DAY_OF_YEAR field.
395 * @stable ICU 3.0
396 */
397 UDAT_DAY_OF_YEAR_FIELD = 10,
398
399 /**
400 * FieldPosition and UFieldPosition selector for 'F' field alignment,
401 * corresponding to the UCAL_DAY_OF_WEEK_IN_MONTH field.
402 * @stable ICU 3.0
403 */
404 UDAT_DAY_OF_WEEK_IN_MONTH_FIELD = 11,
405
406 /**
407 * FieldPosition and UFieldPosition selector for 'w' field alignment,
408 * corresponding to the UCAL_WEEK_OF_YEAR field.
409 * @stable ICU 3.0
410 */
411 UDAT_WEEK_OF_YEAR_FIELD = 12,
412
413 /**
414 * FieldPosition and UFieldPosition selector for 'W' field alignment,
415 * corresponding to the UCAL_WEEK_OF_MONTH field.
416 * @stable ICU 3.0
417 */
418 UDAT_WEEK_OF_MONTH_FIELD = 13,
419
420 /**
421 * FieldPosition and UFieldPosition selector for 'a' field alignment,
422 * corresponding to the UCAL_AM_PM field.
423 * @stable ICU 3.0
424 */
425 UDAT_AM_PM_FIELD = 14,
426
427 /**
428 * FieldPosition and UFieldPosition selector for 'h' field alignment,
429 * corresponding to the UCAL_HOUR field.
430 * UDAT_HOUR1_FIELD is used for the one-based 12-hour clock.
431 * For example, 11:30 PM + 1 hour results in 12:30 AM.
432 * @stable ICU 3.0
433 */
434 UDAT_HOUR1_FIELD = 15,
435
436 /**
437 * FieldPosition and UFieldPosition selector for 'K' field alignment,
438 * corresponding to the UCAL_HOUR field.
439 * UDAT_HOUR0_FIELD is used for the zero-based 12-hour clock.
440 * For example, 11:30 PM + 1 hour results in 00:30 AM.
441 * @stable ICU 3.0
442 */
443 UDAT_HOUR0_FIELD = 16,
444
445 /**
446 * FieldPosition and UFieldPosition selector for 'z' field alignment,
447 * corresponding to the UCAL_ZONE_OFFSET and
448 * UCAL_DST_OFFSET fields.
449 * @stable ICU 3.0
450 */
451 UDAT_TIMEZONE_FIELD = 17,
452
453 /**
454 * FieldPosition and UFieldPosition selector for 'Y' field alignment,
455 * corresponding to the UCAL_YEAR_WOY field.
456 * @stable ICU 3.0
457 */
458 UDAT_YEAR_WOY_FIELD = 18,
459
460 /**
461 * FieldPosition and UFieldPosition selector for 'e' field alignment,
462 * corresponding to the UCAL_DOW_LOCAL field.
463 * @stable ICU 3.0
464 */
465 UDAT_DOW_LOCAL_FIELD = 19,
466
467 /**
468 * FieldPosition and UFieldPosition selector for 'u' field alignment,
469 * corresponding to the UCAL_EXTENDED_YEAR field.
470 * @stable ICU 3.0
471 */
472 UDAT_EXTENDED_YEAR_FIELD = 20,
473
474 /**
475 * FieldPosition and UFieldPosition selector for 'g' field alignment,
476 * corresponding to the UCAL_JULIAN_DAY field.
477 * @stable ICU 3.0
478 */
479 UDAT_JULIAN_DAY_FIELD = 21,
480
481 /**
482 * FieldPosition and UFieldPosition selector for 'A' field alignment,
483 * corresponding to the UCAL_MILLISECONDS_IN_DAY field.
484 * @stable ICU 3.0
485 */
486 UDAT_MILLISECONDS_IN_DAY_FIELD = 22,
487
488 /**
489 * FieldPosition and UFieldPosition selector for 'Z' field alignment,
490 * corresponding to the UCAL_ZONE_OFFSET and
491 * UCAL_DST_OFFSET fields.
492 * @stable ICU 3.0
493 */
494 UDAT_TIMEZONE_RFC_FIELD = 23,
495
496 /**
497 * FieldPosition and UFieldPosition selector for 'v' field alignment,
498 * corresponding to the UCAL_ZONE_OFFSET field.
499 * @stable ICU 3.4
500 */
501 UDAT_TIMEZONE_GENERIC_FIELD = 24,
502 /**
503 * FieldPosition selector for 'c' field alignment,
504 * corresponding to the {@link #UCAL_DOW_LOCAL} field.
505 * This displays the stand alone day name, if available.
506 * @stable ICU 3.4
507 */
508 UDAT_STANDALONE_DAY_FIELD = 25,
509
510 /**
511 * FieldPosition selector for 'L' field alignment,
512 * corresponding to the {@link #UCAL_MONTH} field.
513 * This displays the stand alone month name, if available.
514 * @stable ICU 3.4
515 */
516 UDAT_STANDALONE_MONTH_FIELD = 26,
517
518 /**
519 * FieldPosition selector for "Q" field alignment,
520 * corresponding to quarters. This is implemented
521 * using the {@link #UCAL_MONTH} field. This
522 * displays the quarter.
523 * @stable ICU 3.6
524 */
525 UDAT_QUARTER_FIELD = 27,
526
527 /**
528 * FieldPosition selector for the "q" field alignment,
529 * corresponding to stand-alone quarters. This is
530 * implemented using the {@link #UCAL_MONTH} field.
531 * This displays the stand-alone quarter.
532 * @stable ICU 3.6
533 */
534 UDAT_STANDALONE_QUARTER_FIELD = 28,
535
536 /**
537 * FieldPosition and UFieldPosition selector for 'V' field alignment,
538 * corresponding to the UCAL_ZONE_OFFSET field.
539 * @stable ICU 3.8
540 */
541 UDAT_TIMEZONE_SPECIAL_FIELD = 29,
542
543 /**
544 * FieldPosition selector for "U" field alignment,
545 * corresponding to cyclic year names. This is implemented
546 * using the {@link #UCAL_YEAR} field. This displays
547 * the cyclic year name, if available.
548 * @draft ICU 49
549 */
550 UDAT_YEAR_NAME_FIELD = 30,
551
552 /**
553 * Number of FieldPosition and UFieldPosition selectors for
554 * DateFormat and UDateFormat.
555 * Valid selectors range from 0 to UDAT_FIELD_COUNT-1.
556 * This value is subject to change if new fields are defined
557 * in the future.
558 * @stable ICU 3.0
559 */
560 UDAT_FIELD_COUNT = 31
561
562 } UDateFormatField;
563
564
565 /**
566 * Maps from a UDateFormatField to the corresponding UCalendarDateFields.
567 * Note: since the mapping is many-to-one, there is no inverse mapping.
568 * @param field the UDateFormatField.
569 * @return the UCalendarDateField. This will be UCAL_FIELD_COUNT in case
570 * of error (e.g., the input field is UDAT_FIELD_COUNT).
571 * @stable ICU 4.4
572 */
573 U_STABLE UCalendarDateFields U_EXPORT2
574 udat_toCalendarDateField(UDateFormatField field);
575
576
577 /**
578 * Open a new UDateFormat for formatting and parsing dates and times.
579 * A UDateFormat may be used to format dates in calls to {@link #udat_format },
580 * and to parse dates in calls to {@link #udat_parse }.
581 * @param timeStyle The style used to format times; one of UDAT_FULL, UDAT_LONG,
582 * UDAT_MEDIUM, UDAT_SHORT, UDAT_DEFAULT, or UDAT_NONE (relative time styles
583 * are not currently supported).
584 * @param dateStyle The style used to format dates; one of UDAT_FULL, UDAT_LONG,
585 * UDAT_MEDIUM, UDAT_SHORT, UDAT_DEFAULT, UDAT_FULL_RELATIVE, UDAT_LONG_RELATIVE,
586 * UDAT_MEDIUM_RELATIVE, UDAT_SHORT_RELATIVE, or UDAT_NONE. As currently implemented,
587 * relative date formatting only affects a limited range of calendar days before or
588 * after the current date, based on the CLDR &lt;field type="day"&gt;/&lt;relative&gt; data: For
589 * example, in English, "Yesterday", "Today", and "Tomorrow". Outside of this range,
590 * dates are formatted using the corresponding non-relative style.
591 * @param locale The locale specifying the formatting conventions
592 * @param tzID A timezone ID specifying the timezone to use. If 0, use
593 * the default timezone.
594 * @param tzIDLength The length of tzID, or -1 if null-terminated.
595 * @param pattern A pattern specifying the format to use.
596 * @param patternLength The number of characters in the pattern, or -1 if null-terminated.
597 * @param status A pointer to an UErrorCode to receive any errors
598 * @return A pointer to a UDateFormat to use for formatting dates and times, or 0 if
599 * an error occurred.
600 * @stable ICU 2.0
601 */
602 U_STABLE UDateFormat* U_EXPORT2
603 udat_open(UDateFormatStyle timeStyle,
604 UDateFormatStyle dateStyle,
605 const char *locale,
606 const UChar *tzID,
607 int32_t tzIDLength,
608 const UChar *pattern,
609 int32_t patternLength,
610 UErrorCode *status);
611
612
613 /**
614 * Close a UDateFormat.
615 * Once closed, a UDateFormat may no longer be used.
616 * @param format The formatter to close.
617 * @stable ICU 2.0
618 */
619 U_STABLE void U_EXPORT2
620 udat_close(UDateFormat* format);
621
622 #if U_SHOW_CPLUSPLUS_API
623
624 U_NAMESPACE_BEGIN
625
626 /**
627 * \class LocalUDateFormatPointer
628 * "Smart pointer" class, closes a UDateFormat via udat_close().
629 * For most methods see the LocalPointerBase base class.
630 *
631 * @see LocalPointerBase
632 * @see LocalPointer
633 * @stable ICU 4.4
634 */
635 U_DEFINE_LOCAL_OPEN_POINTER(LocalUDateFormatPointer, UDateFormat, udat_close);
636
637 U_NAMESPACE_END
638
639 #endif
640
641 /**
642 * Open a copy of a UDateFormat.
643 * This function performs a deep copy.
644 * @param fmt The format to copy
645 * @param status A pointer to an UErrorCode to receive any errors.
646 * @return A pointer to a UDateFormat identical to fmt.
647 * @stable ICU 2.0
648 */
649 U_STABLE UDateFormat* U_EXPORT2
650 udat_clone(const UDateFormat *fmt,
651 UErrorCode *status);
652
653 /**
654 * Format a date using an UDateFormat.
655 * The date will be formatted using the conventions specified in {@link #udat_open }
656 * @param format The formatter to use
657 * @param dateToFormat The date to format
658 * @param result A pointer to a buffer to receive the formatted number.
659 * @param resultLength The maximum size of result.
660 * @param position A pointer to a UFieldPosition. On input, position->field
661 * is read. On output, position->beginIndex and position->endIndex indicate
662 * the beginning and ending indices of field number position->field, if such
663 * a field exists. This parameter may be NULL, in which case no field
664 * position data is returned.
665 * @param status A pointer to an UErrorCode to receive any errors
666 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
667 * @see udat_parse
668 * @see UFieldPosition
669 * @stable ICU 2.0
670 */
671 U_STABLE int32_t U_EXPORT2
672 udat_format( const UDateFormat* format,
673 UDate dateToFormat,
674 UChar* result,
675 int32_t resultLength,
676 UFieldPosition* position,
677 UErrorCode* status);
678
679 /**
680 * Parse a string into an date/time using a UDateFormat.
681 * The date will be parsed using the conventions specified in {@link #udat_open }.
682 * <P>
683 * Note that the normal date formats associated with some calendars - such
684 * as the Chinese lunar calendar - do not specify enough fields to enable
685 * dates to be parsed unambiguously. In the case of the Chinese lunar
686 * calendar, while the year within the current 60-year cycle is specified,
687 * the number of such cycles since the start date of the calendar (in the
688 * UCAL_ERA field of the UCalendar object) is not normally part of the format,
689 * and parsing may assume the wrong era. For cases such as this it is
690 * recommended that clients parse using udat_parseCalendar with the UCalendar
691 * passed in set to the current date, or to a date within the era/cycle that
692 * should be assumed if absent in the format.
693 *
694 * @param format The formatter to use.
695 * @param text The text to parse.
696 * @param textLength The length of text, or -1 if null-terminated.
697 * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which
698 * to begin parsing. If not 0, on output the offset at which parsing ended.
699 * @param status A pointer to an UErrorCode to receive any errors
700 * @return The value of the parsed date/time
701 * @see udat_format
702 * @stable ICU 2.0
703 */
704 U_STABLE UDate U_EXPORT2
705 udat_parse(const UDateFormat* format,
706 const UChar* text,
707 int32_t textLength,
708 int32_t *parsePos,
709 UErrorCode *status);
710
711 /**
712 * Parse a string into an date/time using a UDateFormat.
713 * The date will be parsed using the conventions specified in {@link #udat_open }.
714 * @param format The formatter to use.
715 * @param calendar A calendar set on input to the date and time to be used for
716 * missing values in the date/time string being parsed, and set
717 * on output to the parsed date/time. When the calendar type is
718 * different from the internal calendar held by the UDateFormat
719 * instance, the internal calendar will be cloned to a work
720 * calendar set to the same milliseconds and time zone as this
721 * calendar parameter, field values will be parsed based on the
722 * work calendar, then the result (milliseconds and time zone)
723 * will be set in this calendar.
724 * @param text The text to parse.
725 * @param textLength The length of text, or -1 if null-terminated.
726 * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which
727 * to begin parsing. If not 0, on output the offset at which parsing ended.
728 * @param status A pointer to an UErrorCode to receive any errors
729 * @see udat_format
730 * @stable ICU 2.0
731 */
732 U_STABLE void U_EXPORT2
733 udat_parseCalendar(const UDateFormat* format,
734 UCalendar* calendar,
735 const UChar* text,
736 int32_t textLength,
737 int32_t *parsePos,
738 UErrorCode *status);
739
740 /**
741 * Determine if an UDateFormat will perform lenient parsing.
742 * With lenient parsing, the parser may use heuristics to interpret inputs that do not
743 * precisely match the pattern. With strict parsing, inputs must match the pattern.
744 * @param fmt The formatter to query
745 * @return TRUE if fmt is set to perform lenient parsing, FALSE otherwise.
746 * @see udat_setLenient
747 * @stable ICU 2.0
748 */
749 U_STABLE UBool U_EXPORT2
750 udat_isLenient(const UDateFormat* fmt);
751
752 /**
753 * Specify whether an UDateFormat will perform lenient parsing.
754 * With lenient parsing, the parser may use heuristics to interpret inputs that do not
755 * precisely match the pattern. With strict parsing, inputs must match the pattern.
756 * @param fmt The formatter to set
757 * @param isLenient TRUE if fmt should perform lenient parsing, FALSE otherwise.
758 * @see dat_isLenient
759 * @stable ICU 2.0
760 */
761 U_STABLE void U_EXPORT2
762 udat_setLenient( UDateFormat* fmt,
763 UBool isLenient);
764
765 /**
766 * Get the UCalendar associated with an UDateFormat.
767 * A UDateFormat uses a UCalendar to convert a raw value to, for example,
768 * the day of the week.
769 * @param fmt The formatter to query.
770 * @return A pointer to the UCalendar used by fmt.
771 * @see udat_setCalendar
772 * @stable ICU 2.0
773 */
774 U_STABLE const UCalendar* U_EXPORT2
775 udat_getCalendar(const UDateFormat* fmt);
776
777 /**
778 * Set the UCalendar associated with an UDateFormat.
779 * A UDateFormat uses a UCalendar to convert a raw value to, for example,
780 * the day of the week.
781 * @param fmt The formatter to set.
782 * @param calendarToSet A pointer to an UCalendar to be used by fmt.
783 * @see udat_setCalendar
784 * @stable ICU 2.0
785 */
786 U_STABLE void U_EXPORT2
787 udat_setCalendar( UDateFormat* fmt,
788 const UCalendar* calendarToSet);
789
790 /**
791 * Get the UNumberFormat associated with an UDateFormat.
792 * A UDateFormat uses a UNumberFormat to format numbers within a date,
793 * for example the day number.
794 * @param fmt The formatter to query.
795 * @return A pointer to the UNumberFormat used by fmt to format numbers.
796 * @see udat_setNumberFormat
797 * @stable ICU 2.0
798 */
799 U_STABLE const UNumberFormat* U_EXPORT2
800 udat_getNumberFormat(const UDateFormat* fmt);
801
802 /**
803 * Set the UNumberFormat associated with an UDateFormat.
804 * A UDateFormat uses a UNumberFormat to format numbers within a date,
805 * for example the day number.
806 * @param fmt The formatter to set.
807 * @param numberFormatToSet A pointer to the UNumberFormat to be used by fmt to format numbers.
808 * @see udat_getNumberFormat
809 * @stable ICU 2.0
810 */
811 U_STABLE void U_EXPORT2
812 udat_setNumberFormat( UDateFormat* fmt,
813 const UNumberFormat* numberFormatToSet);
814
815 /**
816 * Get a locale for which date/time formatting patterns are available.
817 * A UDateFormat in a locale returned by this function will perform the correct
818 * formatting and parsing for the locale.
819 * @param localeIndex The index of the desired locale.
820 * @return A locale for which date/time formatting patterns are available, or 0 if none.
821 * @see udat_countAvailable
822 * @stable ICU 2.0
823 */
824 U_STABLE const char* U_EXPORT2
825 udat_getAvailable(int32_t localeIndex);
826
827 /**
828 * Determine how many locales have date/time formatting patterns available.
829 * This function is most useful as determining the loop ending condition for
830 * calls to {@link #udat_getAvailable }.
831 * @return The number of locales for which date/time formatting patterns are available.
832 * @see udat_getAvailable
833 * @stable ICU 2.0
834 */
835 U_STABLE int32_t U_EXPORT2
836 udat_countAvailable(void);
837
838 /**
839 * Get the year relative to which all 2-digit years are interpreted.
840 * For example, if the 2-digit start year is 2100, the year 99 will be
841 * interpreted as 2199.
842 * @param fmt The formatter to query.
843 * @param status A pointer to an UErrorCode to receive any errors
844 * @return The year relative to which all 2-digit years are interpreted.
845 * @see udat_Set2DigitYearStart
846 * @stable ICU 2.0
847 */
848 U_STABLE UDate U_EXPORT2
849 udat_get2DigitYearStart( const UDateFormat *fmt,
850 UErrorCode *status);
851
852 /**
853 * Set the year relative to which all 2-digit years will be interpreted.
854 * For example, if the 2-digit start year is 2100, the year 99 will be
855 * interpreted as 2199.
856 * @param fmt The formatter to set.
857 * @param d The year relative to which all 2-digit years will be interpreted.
858 * @param status A pointer to an UErrorCode to receive any errors
859 * @see udat_Set2DigitYearStart
860 * @stable ICU 2.0
861 */
862 U_STABLE void U_EXPORT2
863 udat_set2DigitYearStart( UDateFormat *fmt,
864 UDate d,
865 UErrorCode *status);
866
867 /**
868 * Extract the pattern from a UDateFormat.
869 * The pattern will follow the pattern syntax rules.
870 * @param fmt The formatter to query.
871 * @param localized TRUE if the pattern should be localized, FALSE otherwise.
872 * @param result A pointer to a buffer to receive the pattern.
873 * @param resultLength The maximum size of result.
874 * @param status A pointer to an UErrorCode to receive any errors
875 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
876 * @see udat_applyPattern
877 * @stable ICU 2.0
878 */
879 U_STABLE int32_t U_EXPORT2
880 udat_toPattern( const UDateFormat *fmt,
881 UBool localized,
882 UChar *result,
883 int32_t resultLength,
884 UErrorCode *status);
885
886 /**
887 * Set the pattern used by an UDateFormat.
888 * The pattern should follow the pattern syntax rules.
889 * @param format The formatter to set.
890 * @param localized TRUE if the pattern is localized, FALSE otherwise.
891 * @param pattern The new pattern
892 * @param patternLength The length of pattern, or -1 if null-terminated.
893 * @see udat_toPattern
894 * @stable ICU 2.0
895 */
896 U_STABLE void U_EXPORT2
897 udat_applyPattern( UDateFormat *format,
898 UBool localized,
899 const UChar *pattern,
900 int32_t patternLength);
901
902 /**
903 * The possible types of date format symbols
904 * @stable ICU 2.6
905 */
906 typedef enum UDateFormatSymbolType {
907 /** The era names, for example AD */
908 UDAT_ERAS,
909 /** The month names, for example February */
910 UDAT_MONTHS,
911 /** The short month names, for example Feb. */
912 UDAT_SHORT_MONTHS,
913 /** The weekday names, for example Monday */
914 UDAT_WEEKDAYS,
915 /** The short weekday names, for example Mon. */
916 UDAT_SHORT_WEEKDAYS,
917 /** The AM/PM names, for example AM */
918 UDAT_AM_PMS,
919 /** The localized characters */
920 UDAT_LOCALIZED_CHARS,
921 /** The long era names, for example Anno Domini */
922 UDAT_ERA_NAMES,
923 /** The narrow month names, for example F */
924 UDAT_NARROW_MONTHS,
925 /** The narrow weekday names, for example N */
926 UDAT_NARROW_WEEKDAYS,
927 /** Standalone context versions of months */
928 UDAT_STANDALONE_MONTHS,
929 UDAT_STANDALONE_SHORT_MONTHS,
930 UDAT_STANDALONE_NARROW_MONTHS,
931 /** Standalone context versions of weekdays */
932 UDAT_STANDALONE_WEEKDAYS,
933 UDAT_STANDALONE_SHORT_WEEKDAYS,
934 UDAT_STANDALONE_NARROW_WEEKDAYS,
935 /** The quarters, for example 1st Quarter */
936 UDAT_QUARTERS,
937 /** The short quarter names, for example Q1 */
938 UDAT_SHORT_QUARTERS,
939 /** Standalone context versions of quarters */
940 UDAT_STANDALONE_QUARTERS,
941 UDAT_STANDALONE_SHORT_QUARTERS
942
943 } UDateFormatSymbolType;
944
945 struct UDateFormatSymbols;
946 /** Date format symbols.
947 * For usage in C programs.
948 * @stable ICU 2.6
949 */
950 typedef struct UDateFormatSymbols UDateFormatSymbols;
951
952 /**
953 * Get the symbols associated with an UDateFormat.
954 * The symbols are what a UDateFormat uses to represent locale-specific data,
955 * for example month or day names.
956 * @param fmt The formatter to query.
957 * @param type The type of symbols to get. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS,
958 * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS
959 * @param symbolIndex The desired symbol of type type.
960 * @param result A pointer to a buffer to receive the pattern.
961 * @param resultLength The maximum size of result.
962 * @param status A pointer to an UErrorCode to receive any errors
963 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
964 * @see udat_countSymbols
965 * @see udat_setSymbols
966 * @stable ICU 2.0
967 */
968 U_STABLE int32_t U_EXPORT2
969 udat_getSymbols(const UDateFormat *fmt,
970 UDateFormatSymbolType type,
971 int32_t symbolIndex,
972 UChar *result,
973 int32_t resultLength,
974 UErrorCode *status);
975
976 /**
977 * Count the number of particular symbols for an UDateFormat.
978 * This function is most useful as for detemining the loop termination condition
979 * for calls to {@link #udat_getSymbols }.
980 * @param fmt The formatter to query.
981 * @param type The type of symbols to count. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS,
982 * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS
983 * @return The number of symbols of type type.
984 * @see udat_getSymbols
985 * @see udat_setSymbols
986 * @stable ICU 2.0
987 */
988 U_STABLE int32_t U_EXPORT2
989 udat_countSymbols( const UDateFormat *fmt,
990 UDateFormatSymbolType type);
991
992 /**
993 * Set the symbols associated with an UDateFormat.
994 * The symbols are what a UDateFormat uses to represent locale-specific data,
995 * for example month or day names.
996 * @param format The formatter to set
997 * @param type The type of symbols to set. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS,
998 * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS
999 * @param symbolIndex The index of the symbol to set of type type.
1000 * @param value The new value
1001 * @param valueLength The length of value, or -1 if null-terminated
1002 * @param status A pointer to an UErrorCode to receive any errors
1003 * @see udat_getSymbols
1004 * @see udat_countSymbols
1005 * @stable ICU 2.0
1006 */
1007 U_STABLE void U_EXPORT2
1008 udat_setSymbols( UDateFormat *format,
1009 UDateFormatSymbolType type,
1010 int32_t symbolIndex,
1011 UChar *value,
1012 int32_t valueLength,
1013 UErrorCode *status);
1014
1015 /**
1016 * Get the locale for this date format object.
1017 * You can choose between valid and actual locale.
1018 * @param fmt The formatter to get the locale from
1019 * @param type type of the locale we're looking for (valid or actual)
1020 * @param status error code for the operation
1021 * @return the locale name
1022 * @stable ICU 2.8
1023 */
1024 U_STABLE const char* U_EXPORT2
1025 udat_getLocaleByType(const UDateFormat *fmt,
1026 ULocDataLocaleType type,
1027 UErrorCode* status);
1028
1029 #ifndef U_HIDE_DRAFT_API
1030 /**
1031 * Set the formatter's default value for a particular context type,
1032 * such as UDAT_CAPITALIZATION.
1033 * @param fmt The formatter for which to set a context type's default value.
1034 * @param type The context type for which the default value should be set.
1035 * @param value The default value to set for the specified context type.
1036 * @param status A pointer to an UErrorCode to receive any errors
1037 * @draft ICU 49
1038 */
1039 U_DRAFT void U_EXPORT2
1040 udat_setDefaultContext(UDateFormat* fmt,
1041 UDateFormatContextType type, UDateFormatContextValue value,
1042 UErrorCode* status);
1043
1044 /**
1045 * Get the formatter's default value for a particular context type,
1046 * such as UDAT_CAPITALIZATION.
1047 * @param fmt The formatter from which to get a context type's default value.
1048 * @param type The context type for which the default value should be obtained.
1049 * @param status A pointer to an UErrorCode to receive any errors
1050 * @return The current default value for the specified context type.
1051 * @draft ICU 49
1052 */
1053 U_DRAFT int32_t U_EXPORT2
1054 udat_getDefaultContext(UDateFormat* fmt,
1055 UDateFormatContextType type,
1056 UErrorCode* status);
1057 #endif /* U_HIDE_DRAFT_API */
1058
1059 #ifndef U_HIDE_INTERNAL_API
1060 /**
1061 * Extract the date pattern from a UDateFormat set for relative date formatting.
1062 * The pattern will follow the pattern syntax rules.
1063 * @param fmt The formatter to query.
1064 * @param result A pointer to a buffer to receive the pattern.
1065 * @param resultLength The maximum size of result.
1066 * @param status A pointer to a UErrorCode to receive any errors
1067 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
1068 * @see udat_applyPatternRelative
1069 * @internal ICU 4.2 technology preview
1070 */
1071 U_INTERNAL int32_t U_EXPORT2
1072 udat_toPatternRelativeDate(const UDateFormat *fmt,
1073 UChar *result,
1074 int32_t resultLength,
1075 UErrorCode *status);
1076
1077 /**
1078 * Extract the time pattern from a UDateFormat set for relative date formatting.
1079 * The pattern will follow the pattern syntax rules.
1080 * @param fmt The formatter to query.
1081 * @param result A pointer to a buffer to receive the pattern.
1082 * @param resultLength The maximum size of result.
1083 * @param status A pointer to a UErrorCode to receive any errors
1084 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
1085 * @see udat_applyPatternRelative
1086 * @internal ICU 4.2 technology preview
1087 */
1088 U_INTERNAL int32_t U_EXPORT2
1089 udat_toPatternRelativeTime(const UDateFormat *fmt,
1090 UChar *result,
1091 int32_t resultLength,
1092 UErrorCode *status);
1093
1094 /**
1095 * Set the date & time patterns used by a UDateFormat set for relative date formatting.
1096 * The patterns should follow the pattern syntax rules.
1097 * @param format The formatter to set.
1098 * @param datePattern The new date pattern
1099 * @param datePatternLength The length of datePattern, or -1 if null-terminated.
1100 * @param timePattern The new time pattern
1101 * @param timePatternLength The length of timePattern, or -1 if null-terminated.
1102 * @param status A pointer to a UErrorCode to receive any errors
1103 * @see udat_toPatternRelativeDate, udat_toPatternRelativeTime
1104 * @internal ICU 4.2 technology preview
1105 */
1106 U_INTERNAL void U_EXPORT2
1107 udat_applyPatternRelative(UDateFormat *format,
1108 const UChar *datePattern,
1109 int32_t datePatternLength,
1110 const UChar *timePattern,
1111 int32_t timePatternLength,
1112 UErrorCode *status);
1113 #endif /* U_HIDE_INTERNAL_API */
1114
1115 /**
1116 * @internal
1117 * @see udat_open
1118 */
1119 typedef UDateFormat* (U_EXPORT2 *UDateFormatOpener) (UDateFormatStyle timeStyle,
1120 UDateFormatStyle dateStyle,
1121 const char *locale,
1122 const UChar *tzID,
1123 int32_t tzIDLength,
1124 const UChar *pattern,
1125 int32_t patternLength,
1126 UErrorCode *status);
1127
1128 /**
1129 * Register a provider factory
1130 * @internal ICU 49
1131 */
1132 U_INTERNAL void U_EXPORT2
1133 udat_registerOpener(UDateFormatOpener opener, UErrorCode *status);
1134
1135 /**
1136 * Un-Register a provider factory
1137 * @internal ICU 49
1138 */
1139 U_INTERNAL UDateFormatOpener U_EXPORT2
1140 udat_unregisterOpener(UDateFormatOpener opener, UErrorCode *status);
1141
1142
1143 #endif /* #if !UCONFIG_NO_FORMATTING */
1144
1145 #endif