1 /*
2  *******************************************************************************
3  * Copyright (C) 1996-2015, 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 #include "unicode/udisplaycontext.h"
19 #include "unicode/ufieldpositer.h"
20 /**
21  * \file
22  * \brief C API: DateFormat
23  *
24  * <h2> Date Format C API</h2>
25  *
26  * Date Format C API  consists of functions that convert dates and
27  * times from their internal representations to textual form and back again in a
28  * language-independent manner. Converting from the internal representation (milliseconds
29  * since midnight, January 1, 1970) to text is known as "formatting," and converting
30  * from text to millis is known as "parsing."  We currently define only one concrete
31  * structure UDateFormat, which can handle pretty much all normal
32  * date formatting and parsing actions.
33  * <P>
34  * Date Format helps you to format and parse dates for any locale. Your code can
35  * be completely independent of the locale conventions for months, days of the
36  * week, or even the calendar format: lunar vs. solar.
37  * <P>
38  * To format a date for the current Locale with default time and date style,
39  * use one of the static factory methods:
40  * <pre>
41  * \code
42  *  UErrorCode status = U_ZERO_ERROR;
43  *  UChar *myString;
44  *  int32_t myStrlen = 0;
45  *  UDateFormat* dfmt = udat_open(UDAT_DEFAULT, UDAT_DEFAULT, NULL, NULL, -1, NULL, -1, &status);
46  *  myStrlen = udat_format(dfmt, myDate, NULL, myStrlen, NULL, &status);
47  *  if (status==U_BUFFER_OVERFLOW_ERROR){
48  *      status=U_ZERO_ERROR;
49  *      myString=(UChar*)malloc(sizeof(UChar) * (myStrlen+1) );
50  *      udat_format(dfmt, myDate, myString, myStrlen+1, NULL, &status);
51  *  }
52  * \endcode
53  * </pre>
54  * If you are formatting multiple numbers, it is more efficient to get the
55  * format and use it multiple times so that the system doesn't have to fetch the
56  * information about the local language and country conventions multiple times.
57  * <pre>
58  * \code
59  *  UErrorCode status = U_ZERO_ERROR;
60  *  int32_t i, myStrlen = 0;
61  *  UChar* myString;
62  *  char buffer[1024];
63  *  UDate myDateArr[] = { 0.0, 100000000.0, 2000000000.0 }; // test values
64  *  UDateFormat* df = udat_open(UDAT_DEFAULT, UDAT_DEFAULT, NULL, NULL, -1, NULL, 0, &status);
65  *  for (i = 0; i < 3; i++) {
66  *      myStrlen = udat_format(df, myDateArr[i], NULL, myStrlen, NULL, &status);
67  *      if(status == U_BUFFER_OVERFLOW_ERROR){
68  *          status = U_ZERO_ERROR;
69  *          myString = (UChar*)malloc(sizeof(UChar) * (myStrlen+1) );
70  *          udat_format(df, myDateArr[i], myString, myStrlen+1, NULL, &status);
71  *          printf("%s\n", u_austrcpy(buffer, myString) );
72  *          free(myString);
73  *      }
74  *  }
75  * \endcode
76  * </pre>
77  * To get specific fields of a date, you can use UFieldPosition to
78  * get specific fields.
79  * <pre>
80  * \code
81  *  UErrorCode status = U_ZERO_ERROR;
82  *  UFieldPosition pos;
83  *  UChar *myString;
84  *  int32_t myStrlen = 0;
85  *  char buffer[1024];
86  *
87  *  pos.field = 1;  // Same as the DateFormat::EField enum
88  *  UDateFormat* dfmt = udat_open(UDAT_DEFAULT, UDAT_DEFAULT, NULL, -1, NULL, 0, &status);
89  *  myStrlen = udat_format(dfmt, myDate, NULL, myStrlen, &pos, &status);
90  *  if (status==U_BUFFER_OVERFLOW_ERROR){
91  *      status=U_ZERO_ERROR;
92  *      myString=(UChar*)malloc(sizeof(UChar) * (myStrlen+1) );
93  *      udat_format(dfmt, myDate, myString, myStrlen+1, &pos, &status);
94  *  }
95  *  printf("date format: %s\n", u_austrcpy(buffer, myString));
96  *  buffer[pos.endIndex] = 0;   // NULL terminate the string.
97  *  printf("UFieldPosition position equals %s\n", &buffer[pos.beginIndex]);
98  * \endcode
99  * </pre>
100  * To format a date for a different Locale, specify it in the call to
101  * udat_open()
102  * <pre>
103  * \code
104  *        UDateFormat* df = udat_open(UDAT_SHORT, UDAT_SHORT, "fr_FR", NULL, -1, NULL, 0, &status);
105  * \endcode
106  * </pre>
107  * You can use a DateFormat API udat_parse() to parse.
108  * <pre>
109  * \code
110  *  UErrorCode status = U_ZERO_ERROR;
111  *  int32_t parsepos=0;
112  *  UDate myDate = udat_parse(df, myString, u_strlen(myString), &parsepos, &status);
113  * \endcode
114  * </pre>
115  *  You can pass in different options for the arguments for date and time style
116  *  to control the length of the result; from SHORT to MEDIUM to LONG to FULL.
117  *  The exact result depends on the locale, but generally:
118  *  see UDateFormatStyle for more details
119  * <ul type=round>
120  *   <li>   UDAT_SHORT is completely numeric, such as 12/13/52 or 3:30pm
121  *   <li>   UDAT_MEDIUM is longer, such as Jan 12, 1952
122  *   <li>   UDAT_LONG is longer, such as January 12, 1952 or 3:30:32pm
123  *   <li>   UDAT_FULL is pretty completely specified, such as
124  *          Tuesday, April 12, 1952 AD or 3:30:42pm PST.
125  * </ul>
126  * You can also set the time zone on the format if you wish.
127  * <P>
128  * You can also use forms of the parse and format methods with Parse Position and
129  * UFieldPosition to allow you to
130  * <ul type=round>
131  *   <li>   Progressively parse through pieces of a string.
132  *   <li>   Align any particular field, or find out where it is for selection
133  *          on the screen.
134  * </ul>
135  * <p><strong>Date and Time Patterns:</strong></p>
136  *
137  * <p>Date and time formats are specified by <em>date and time pattern</em> strings.
138  * Within date and time pattern strings, all unquoted ASCII letters [A-Za-z] are reserved
139  * as pattern letters representing calendar fields. <code>UDateFormat</code> supports
140  * the date and time formatting algorithm and pattern letters defined by
141  * <a href="http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table">UTS#35
142  * Unicode Locale Data Markup Language (LDML)</a> and further documented for ICU in the
143  * <a href="https://sites.google.com/site/icuprojectuserguide/formatparse/datetime?pli=1#TOC-Date-Field-Symbol-Table">ICU
144  * User Guide</a>.</p>
145  */
146 
147 /** A date formatter.
148  *  For usage in C programs.
149  *  @stable ICU 2.6
150  */
151 typedef void* UDateFormat;
152 
153 /** The possible date/time format styles
154  *  @stable ICU 2.6
155  */
156 typedef enum UDateFormatStyle {
157     /** Full style */
158     UDAT_FULL,
159     /** Long style */
160     UDAT_LONG,
161     /** Medium style */
162     UDAT_MEDIUM,
163     /** Short style */
164     UDAT_SHORT,
165     /** Default style */
166     UDAT_DEFAULT = UDAT_MEDIUM,
167 
168     /** Bitfield for relative date */
169     UDAT_RELATIVE = (1 << 7),
170 
171     UDAT_FULL_RELATIVE = UDAT_FULL | UDAT_RELATIVE,
172 
173     UDAT_LONG_RELATIVE = UDAT_LONG | UDAT_RELATIVE,
174 
175     UDAT_MEDIUM_RELATIVE = UDAT_MEDIUM | UDAT_RELATIVE,
176 
177     UDAT_SHORT_RELATIVE = UDAT_SHORT | UDAT_RELATIVE,
178 
179 
180     /** No style */
181     UDAT_NONE = -1,
182 
183     /**
184      * Use the pattern given in the parameter to udat_open
185      * @see udat_open
186      * @stable ICU 50
187      */
188     UDAT_PATTERN = -2,
189 
190 #ifndef U_HIDE_INTERNAL_API
191     /** @internal alias to UDAT_PATTERN */
192     UDAT_IGNORE = UDAT_PATTERN
193 #endif /* U_HIDE_INTERNAL_API */
194 } UDateFormatStyle;
195 
196 /* Skeletons for dates. */
197 
198 /**
199  * Constant for date skeleton with year.
200  * @stable ICU 4.0
201  */
202 #define UDAT_YEAR                       "y"
203 /**
204  * Constant for date skeleton with quarter.
205  * @stable ICU 51
206  */
207 #define UDAT_QUARTER                    "QQQQ"
208 /**
209  * Constant for date skeleton with abbreviated quarter.
210  * @stable ICU 51
211  */
212 #define UDAT_ABBR_QUARTER               "QQQ"
213 /**
214  * Constant for date skeleton with year and quarter.
215  * @stable ICU 4.0
216  */
217 #define UDAT_YEAR_QUARTER               "yQQQQ"
218 /**
219  * Constant for date skeleton with year and abbreviated quarter.
220  * @stable ICU 4.0
221  */
222 #define UDAT_YEAR_ABBR_QUARTER          "yQQQ"
223 /**
224  * Constant for date skeleton with month.
225  * @stable ICU 4.0
226  */
227 #define UDAT_MONTH                      "MMMM"
228 /**
229  * Constant for date skeleton with abbreviated month.
230  * @stable ICU 4.0
231  */
232 #define UDAT_ABBR_MONTH                 "MMM"
233 /**
234  * Constant for date skeleton with numeric month.
235  * @stable ICU 4.0
236  */
237 #define UDAT_NUM_MONTH                  "M"
238 /**
239  * Constant for date skeleton with year and month.
240  * @stable ICU 4.0
241  */
242 #define UDAT_YEAR_MONTH                 "yMMMM"
243 /**
244  * Constant for date skeleton with year and abbreviated month.
245  * @stable ICU 4.0
246  */
247 #define UDAT_YEAR_ABBR_MONTH            "yMMM"
248 /**
249  * Constant for date skeleton with year and numeric month.
250  * @stable ICU 4.0
251  */
252 #define UDAT_YEAR_NUM_MONTH             "yM"
253 /**
254  * Constant for date skeleton with day.
255  * @stable ICU 4.0
256  */
257 #define UDAT_DAY                        "d"
258 /**
259  * Constant for date skeleton with year, month, and day.
260  * Used in combinations date + time, date + time + zone, or time + zone.
261  * @stable ICU 4.0
262  */
263 #define UDAT_YEAR_MONTH_DAY             "yMMMMd"
264 /**
265  * Constant for date skeleton with year, abbreviated month, and day.
266  * Used in combinations date + time, date + time + zone, or time + zone.
267  * @stable ICU 4.0
268  */
269 #define UDAT_YEAR_ABBR_MONTH_DAY        "yMMMd"
270 /**
271  * Constant for date skeleton with year, numeric month, and day.
272  * Used in combinations date + time, date + time + zone, or time + zone.
273  * @stable ICU 4.0
274  */
275 #define UDAT_YEAR_NUM_MONTH_DAY         "yMd"
276 /**
277  * Constant for date skeleton with weekday.
278  * @stable ICU 51
279  */
280 #define UDAT_WEEKDAY                    "EEEE"
281 /**
282  * Constant for date skeleton with abbreviated weekday.
283  * @stable ICU 51
284  */
285 #define UDAT_ABBR_WEEKDAY               "E"
286 /**
287  * Constant for date skeleton with year, month, weekday, and day.
288  * Used in combinations date + time, date + time + zone, or time + zone.
289  * @stable ICU 4.0
290  */
291 #define UDAT_YEAR_MONTH_WEEKDAY_DAY     "yMMMMEEEEd"
292 /**
293  * Constant for date skeleton with year, abbreviated month, weekday, and day.
294  * Used in combinations date + time, date + time + zone, or time + zone.
295  * @stable ICU 4.0
296  */
297 #define UDAT_YEAR_ABBR_MONTH_WEEKDAY_DAY "yMMMEd"
298 /**
299  * Constant for date skeleton with year, numeric month, weekday, and day.
300  * Used in combinations date + time, date + time + zone, or time + zone.
301  * @stable ICU 4.0
302  */
303 #define UDAT_YEAR_NUM_MONTH_WEEKDAY_DAY "yMEd"
304 /**
305  * Constant for date skeleton with long month and day.
306  * Used in combinations date + time, date + time + zone, or time + zone.
307  * @stable ICU 4.0
308  */
309 #define UDAT_MONTH_DAY                  "MMMMd"
310 /**
311  * Constant for date skeleton with abbreviated month and day.
312  * Used in combinations date + time, date + time + zone, or time + zone.
313  * @stable ICU 4.0
314  */
315 #define UDAT_ABBR_MONTH_DAY             "MMMd"
316 /**
317  * Constant for date skeleton with numeric month and day.
318  * Used in combinations date + time, date + time + zone, or time + zone.
319  * @stable ICU 4.0
320  */
321 #define UDAT_NUM_MONTH_DAY              "Md"
322 /**
323  * Constant for date skeleton with month, weekday, and day.
324  * Used in combinations date + time, date + time + zone, or time + zone.
325  * @stable ICU 4.0
326  */
327 #define UDAT_MONTH_WEEKDAY_DAY          "MMMMEEEEd"
328 /**
329  * Constant for date skeleton with abbreviated month, weekday, and day.
330  * Used in combinations date + time, date + time + zone, or time + zone.
331  * @stable ICU 4.0
332  */
333 #define UDAT_ABBR_MONTH_WEEKDAY_DAY     "MMMEd"
334 /**
335  * Constant for date skeleton with numeric month, weekday, and day.
336  * Used in combinations date + time, date + time + zone, or time + zone.
337  * @stable ICU 4.0
338  */
339 #define UDAT_NUM_MONTH_WEEKDAY_DAY      "MEd"
340 
341 /* Skeletons for times. */
342 
343 /**
344  * Constant for date skeleton with hour, with the locale's preferred hour format (12 or 24).
345  * @stable ICU 4.0
346  */
347 #define UDAT_HOUR                       "j"
348 /**
349  * Constant for date skeleton with hour in 24-hour presentation.
350  * @stable ICU 51
351  */
352 #define UDAT_HOUR24                     "H"
353 /**
354  * Constant for date skeleton with minute.
355  * @stable ICU 51
356  */
357 #define UDAT_MINUTE                     "m"
358 /**
359  * Constant for date skeleton with hour and minute, with the locale's preferred hour format (12 or 24).
360  * Used in combinations date + time, date + time + zone, or time + zone.
361  * @stable ICU 4.0
362  */
363 #define UDAT_HOUR_MINUTE                "jm"
364 /**
365  * Constant for date skeleton with hour and minute in 24-hour presentation.
366  * Used in combinations date + time, date + time + zone, or time + zone.
367  * @stable ICU 4.0
368  */
369 #define UDAT_HOUR24_MINUTE              "Hm"
370 /**
371  * Constant for date skeleton with second.
372  * @stable ICU 51
373  */
374 #define UDAT_SECOND                     "s"
375 /**
376  * Constant for date skeleton with hour, minute, and second,
377  * with the locale's preferred hour format (12 or 24).
378  * Used in combinations date + time, date + time + zone, or time + zone.
379  * @stable ICU 4.0
380  */
381 #define UDAT_HOUR_MINUTE_SECOND         "jms"
382 /**
383  * Constant for date skeleton with hour, minute, and second in
384  * 24-hour presentation.
385  * Used in combinations date + time, date + time + zone, or time + zone.
386  * @stable ICU 4.0
387  */
388 #define UDAT_HOUR24_MINUTE_SECOND       "Hms"
389 /**
390  * Constant for date skeleton with minute and second.
391  * Used in combinations date + time, date + time + zone, or time + zone.
392  * @stable ICU 4.0
393  */
394 #define UDAT_MINUTE_SECOND              "ms"
395 
396 /* Skeletons for time zones. */
397 
398 /**
399  * Constant for <i>generic location format</i>, such as Los Angeles Time;
400  * used in combinations date + time + zone, or time + zone.
401  * @see <a href="http://unicode.org/reports/tr35/#Date_Format_Patterns">LDML Date Format Patterns</a>
402  * @see <a href="http://unicode.org/reports/tr35/#Time_Zone_Fallback">LDML Time Zone Fallback</a>
403  * @stable ICU 51
404  */
405 #define UDAT_LOCATION_TZ "VVVV"
406 /**
407  * Constant for <i>generic non-location format</i>, such as Pacific Time;
408  * used in combinations date + time + zone, or time + zone.
409  * @see <a href="http://unicode.org/reports/tr35/#Date_Format_Patterns">LDML Date Format Patterns</a>
410  * @see <a href="http://unicode.org/reports/tr35/#Time_Zone_Fallback">LDML Time Zone Fallback</a>
411  * @stable ICU 51
412  */
413 #define UDAT_GENERIC_TZ "vvvv"
414 /**
415  * Constant for <i>generic non-location format</i>, abbreviated if possible, such as PT;
416  * used in combinations date + time + zone, or time + zone.
417  * @see <a href="http://unicode.org/reports/tr35/#Date_Format_Patterns">LDML Date Format Patterns</a>
418  * @see <a href="http://unicode.org/reports/tr35/#Time_Zone_Fallback">LDML Time Zone Fallback</a>
419  * @stable ICU 51
420  */
421 #define UDAT_ABBR_GENERIC_TZ "v"
422 /**
423  * Constant for <i>specific non-location format</i>, such as Pacific Daylight Time;
424  * used in combinations date + time + zone, or time + zone.
425  * @see <a href="http://unicode.org/reports/tr35/#Date_Format_Patterns">LDML Date Format Patterns</a>
426  * @see <a href="http://unicode.org/reports/tr35/#Time_Zone_Fallback">LDML Time Zone Fallback</a>
427  * @stable ICU 51
428  */
429 #define UDAT_SPECIFIC_TZ "zzzz"
430 /**
431  * Constant for <i>specific non-location format</i>, abbreviated if possible, such as PDT;
432  * used in combinations date + time + zone, or time + zone.
433  * @see <a href="http://unicode.org/reports/tr35/#Date_Format_Patterns">LDML Date Format Patterns</a>
434  * @see <a href="http://unicode.org/reports/tr35/#Time_Zone_Fallback">LDML Time Zone Fallback</a>
435  * @stable ICU 51
436  */
437 #define UDAT_ABBR_SPECIFIC_TZ "z"
438 /**
439  * Constant for <i>localized GMT/UTC format</i>, such as GMT+8:00 or HPG-8:00;
440  * used in combinations date + time + zone, or time + zone.
441  * @see <a href="http://unicode.org/reports/tr35/#Date_Format_Patterns">LDML Date Format Patterns</a>
442  * @see <a href="http://unicode.org/reports/tr35/#Time_Zone_Fallback">LDML Time Zone Fallback</a>
443  * @stable ICU 51
444  */
445 #define UDAT_ABBR_UTC_TZ "ZZZZ"
446 
447 /* deprecated skeleton constants */
448 
449 #ifndef U_HIDE_DEPRECATED_API
450 /**
451  * Constant for date skeleton with standalone month.
452  * @deprecated ICU 50 Use UDAT_MONTH instead.
453  */
454 #define UDAT_STANDALONE_MONTH           "LLLL"
455 /**
456  * Constant for date skeleton with standalone abbreviated month.
457  * @deprecated ICU 50 Use UDAT_ABBR_MONTH instead.
458  */
459 #define UDAT_ABBR_STANDALONE_MONTH      "LLL"
460 
461 /**
462  * Constant for date skeleton with hour, minute, and generic timezone.
463  * @deprecated ICU 50 Use instead UDAT_HOUR_MINUTE UDAT_ABBR_GENERIC_TZ or some other timezone presentation.
464  */
465 #define UDAT_HOUR_MINUTE_GENERIC_TZ     "jmv"
466 /**
467  * Constant for date skeleton with hour, minute, and timezone.
468  * @deprecated ICU 50 Use instead UDAT_HOUR_MINUTE UDAT_ABBR_SPECIFIC_TZ or some other timezone presentation.
469  */
470 #define UDAT_HOUR_MINUTE_TZ             "jmz"
471 /**
472  * Constant for date skeleton with hour and generic timezone.
473  * @deprecated ICU 50 Use instead UDAT_HOUR UDAT_ABBR_GENERIC_TZ or some other timezone presentation.
474  */
475 #define UDAT_HOUR_GENERIC_TZ            "jv"
476 /**
477  * Constant for date skeleton with hour and timezone.
478  * @deprecated ICU 50 Use instead UDAT_HOUR UDAT_ABBR_SPECIFIC_TZ or some other timezone presentation.
479  */
480 #define UDAT_HOUR_TZ                    "jz"
481 #endif  /* U_HIDE_DEPRECATED_API */
482 
483 /**
484  * FieldPosition and UFieldPosition selectors for format fields
485  * defined by DateFormat and UDateFormat.
486  * @stable ICU 3.0
487  */
488 typedef enum UDateFormatField {
489     /**
490      * FieldPosition and UFieldPosition selector for 'G' field alignment,
491      * corresponding to the UCAL_ERA field.
492      * @stable ICU 3.0
493      */
494     UDAT_ERA_FIELD = 0,
495 
496     /**
497      * FieldPosition and UFieldPosition selector for 'y' field alignment,
498      * corresponding to the UCAL_YEAR field.
499      * @stable ICU 3.0
500      */
501     UDAT_YEAR_FIELD = 1,
502 
503     /**
504      * FieldPosition and UFieldPosition selector for 'M' field alignment,
505      * corresponding to the UCAL_MONTH field.
506      * @stable ICU 3.0
507      */
508     UDAT_MONTH_FIELD = 2,
509 
510     /**
511      * FieldPosition and UFieldPosition selector for 'd' field alignment,
512      * corresponding to the UCAL_DATE field.
513      * @stable ICU 3.0
514      */
515     UDAT_DATE_FIELD = 3,
516 
517     /**
518      * FieldPosition and UFieldPosition selector for 'k' field alignment,
519      * corresponding to the UCAL_HOUR_OF_DAY field.
520      * UDAT_HOUR_OF_DAY1_FIELD is used for the one-based 24-hour clock.
521      * For example, 23:59 + 01:00 results in 24:59.
522      * @stable ICU 3.0
523      */
524     UDAT_HOUR_OF_DAY1_FIELD = 4,
525 
526     /**
527      * FieldPosition and UFieldPosition selector for 'H' field alignment,
528      * corresponding to the UCAL_HOUR_OF_DAY field.
529      * UDAT_HOUR_OF_DAY0_FIELD is used for the zero-based 24-hour clock.
530      * For example, 23:59 + 01:00 results in 00:59.
531      * @stable ICU 3.0
532      */
533     UDAT_HOUR_OF_DAY0_FIELD = 5,
534 
535     /**
536      * FieldPosition and UFieldPosition selector for 'm' field alignment,
537      * corresponding to the UCAL_MINUTE field.
538      * @stable ICU 3.0
539      */
540     UDAT_MINUTE_FIELD = 6,
541 
542     /**
543      * FieldPosition and UFieldPosition selector for 's' field alignment,
544      * corresponding to the UCAL_SECOND field.
545      * @stable ICU 3.0
546      */
547     UDAT_SECOND_FIELD = 7,
548 
549     /**
550      * FieldPosition and UFieldPosition selector for 'S' field alignment,
551      * corresponding to the UCAL_MILLISECOND field.
552      *
553      * Note: Time formats that use 'S' can display a maximum of three
554      * significant digits for fractional seconds, corresponding to millisecond
555      * resolution and a fractional seconds sub-pattern of SSS. If the
556      * sub-pattern is S or SS, the fractional seconds value will be truncated
557      * (not rounded) to the number of display places specified. If the
558      * fractional seconds sub-pattern is longer than SSS, the additional
559      * display places will be filled with zeros.
560      * @stable ICU 3.0
561      */
562     UDAT_FRACTIONAL_SECOND_FIELD = 8,
563 
564     /**
565      * FieldPosition and UFieldPosition selector for 'E' field alignment,
566      * corresponding to the UCAL_DAY_OF_WEEK field.
567      * @stable ICU 3.0
568      */
569     UDAT_DAY_OF_WEEK_FIELD = 9,
570 
571     /**
572      * FieldPosition and UFieldPosition selector for 'D' field alignment,
573      * corresponding to the UCAL_DAY_OF_YEAR field.
574      * @stable ICU 3.0
575      */
576     UDAT_DAY_OF_YEAR_FIELD = 10,
577 
578     /**
579      * FieldPosition and UFieldPosition selector for 'F' field alignment,
580      * corresponding to the UCAL_DAY_OF_WEEK_IN_MONTH field.
581      * @stable ICU 3.0
582      */
583     UDAT_DAY_OF_WEEK_IN_MONTH_FIELD = 11,
584 
585     /**
586      * FieldPosition and UFieldPosition selector for 'w' field alignment,
587      * corresponding to the UCAL_WEEK_OF_YEAR field.
588      * @stable ICU 3.0
589      */
590     UDAT_WEEK_OF_YEAR_FIELD = 12,
591 
592     /**
593      * FieldPosition and UFieldPosition selector for 'W' field alignment,
594      * corresponding to the UCAL_WEEK_OF_MONTH field.
595      * @stable ICU 3.0
596      */
597     UDAT_WEEK_OF_MONTH_FIELD = 13,
598 
599     /**
600      * FieldPosition and UFieldPosition selector for 'a' field alignment,
601      * corresponding to the UCAL_AM_PM field.
602      * @stable ICU 3.0
603      */
604     UDAT_AM_PM_FIELD = 14,
605 
606     /**
607      * FieldPosition and UFieldPosition selector for 'h' field alignment,
608      * corresponding to the UCAL_HOUR field.
609      * UDAT_HOUR1_FIELD is used for the one-based 12-hour clock.
610      * For example, 11:30 PM + 1 hour results in 12:30 AM.
611      * @stable ICU 3.0
612      */
613     UDAT_HOUR1_FIELD = 15,
614 
615     /**
616      * FieldPosition and UFieldPosition selector for 'K' field alignment,
617      * corresponding to the UCAL_HOUR field.
618      * UDAT_HOUR0_FIELD is used for the zero-based 12-hour clock.
619      * For example, 11:30 PM + 1 hour results in 00:30 AM.
620      * @stable ICU 3.0
621      */
622     UDAT_HOUR0_FIELD = 16,
623 
624     /**
625      * FieldPosition and UFieldPosition selector for 'z' field alignment,
626      * corresponding to the UCAL_ZONE_OFFSET and
627      * UCAL_DST_OFFSET fields.
628      * @stable ICU 3.0
629      */
630     UDAT_TIMEZONE_FIELD = 17,
631 
632     /**
633      * FieldPosition and UFieldPosition selector for 'Y' field alignment,
634      * corresponding to the UCAL_YEAR_WOY field.
635      * @stable ICU 3.0
636      */
637     UDAT_YEAR_WOY_FIELD = 18,
638 
639     /**
640      * FieldPosition and UFieldPosition selector for 'e' field alignment,
641      * corresponding to the UCAL_DOW_LOCAL field.
642      * @stable ICU 3.0
643      */
644     UDAT_DOW_LOCAL_FIELD = 19,
645 
646     /**
647      * FieldPosition and UFieldPosition selector for 'u' field alignment,
648      * corresponding to the UCAL_EXTENDED_YEAR field.
649      * @stable ICU 3.0
650      */
651     UDAT_EXTENDED_YEAR_FIELD = 20,
652 
653     /**
654      * FieldPosition and UFieldPosition selector for 'g' field alignment,
655      * corresponding to the UCAL_JULIAN_DAY field.
656      * @stable ICU 3.0
657      */
658     UDAT_JULIAN_DAY_FIELD = 21,
659 
660     /**
661      * FieldPosition and UFieldPosition selector for 'A' field alignment,
662      * corresponding to the UCAL_MILLISECONDS_IN_DAY field.
663      * @stable ICU 3.0
664      */
665     UDAT_MILLISECONDS_IN_DAY_FIELD = 22,
666 
667     /**
668      * FieldPosition and UFieldPosition selector for 'Z' field alignment,
669      * corresponding to the UCAL_ZONE_OFFSET and
670      * UCAL_DST_OFFSET fields.
671      * @stable ICU 3.0
672      */
673     UDAT_TIMEZONE_RFC_FIELD = 23,
674 
675     /**
676      * FieldPosition and UFieldPosition selector for 'v' field alignment,
677      * corresponding to the UCAL_ZONE_OFFSET field.
678      * @stable ICU 3.4
679      */
680     UDAT_TIMEZONE_GENERIC_FIELD = 24,
681     /**
682      * FieldPosition selector for 'c' field alignment,
683      * corresponding to the {@link #UCAL_DOW_LOCAL} field.
684      * This displays the stand alone day name, if available.
685      * @stable ICU 3.4
686      */
687     UDAT_STANDALONE_DAY_FIELD = 25,
688 
689     /**
690      * FieldPosition selector for 'L' field alignment,
691      * corresponding to the {@link #UCAL_MONTH} field.
692      * This displays the stand alone month name, if available.
693      * @stable ICU 3.4
694      */
695     UDAT_STANDALONE_MONTH_FIELD = 26,
696 
697     /**
698      * FieldPosition selector for "Q" field alignment,
699      * corresponding to quarters. This is implemented
700      * using the {@link #UCAL_MONTH} field. This
701      * displays the quarter.
702      * @stable ICU 3.6
703      */
704     UDAT_QUARTER_FIELD = 27,
705 
706     /**
707      * FieldPosition selector for the "q" field alignment,
708      * corresponding to stand-alone quarters. This is
709      * implemented using the {@link #UCAL_MONTH} field.
710      * This displays the stand-alone quarter.
711      * @stable ICU 3.6
712      */
713     UDAT_STANDALONE_QUARTER_FIELD = 28,
714 
715     /**
716      * FieldPosition and UFieldPosition selector for 'V' field alignment,
717      * corresponding to the UCAL_ZONE_OFFSET field.
718      * @stable ICU 3.8
719      */
720     UDAT_TIMEZONE_SPECIAL_FIELD = 29,
721 
722     /**
723      * FieldPosition selector for "U" field alignment,
724      * corresponding to cyclic year names. This is implemented
725      * using the {@link #UCAL_YEAR} field. This displays
726      * the cyclic year name, if available.
727      * @stable ICU 49
728      */
729     UDAT_YEAR_NAME_FIELD = 30,
730 
731     /**
732      * FieldPosition selector for 'O' field alignment,
733      * corresponding to the UCAL_ZONE_OFFSET and UCAL_DST_OFFSETfields.
734      * This displays the localized GMT format.
735      * @stable ICU 51
736      */
737     UDAT_TIMEZONE_LOCALIZED_GMT_OFFSET_FIELD = 31,
738 
739     /**
740      * FieldPosition selector for 'X' field alignment,
741      * corresponding to the UCAL_ZONE_OFFSET and UCAL_DST_OFFSETfields.
742      * This displays the ISO 8601 local time offset format or UTC indicator ("Z").
743      * @stable ICU 51
744      */
745     UDAT_TIMEZONE_ISO_FIELD = 32,
746 
747     /**
748      * FieldPosition selector for 'x' field alignment,
749      * corresponding to the UCAL_ZONE_OFFSET and UCAL_DST_OFFSET fields.
750      * This displays the ISO 8601 local time offset format.
751      * @stable ICU 51
752      */
753     UDAT_TIMEZONE_ISO_LOCAL_FIELD = 33,
754 
755 #ifndef U_HIDE_INTERNAL_API
756     /**
757      * FieldPosition and UFieldPosition selector for 'r' field alignment,
758      * no directly corresponding UCAL_ field.
759      * @internal ICU 53
760      */
761     UDAT_RELATED_YEAR_FIELD = 34,
762 #endif /* U_HIDE_INTERNAL_API */
763 
764 #ifndef U_HIDE_DRAFT_API
765     /**
766      * FieldPosition and UFieldPosition selector for time separator,
767      * no corresponding UCAL_ field. No pattern character is currently
768      * defined for this.
769      * @draft ICU 55
770      */
771     UDAT_TIME_SEPARATOR_FIELD = 35,
772 #endif  /* U_HIDE_DRAFT_API */
773 
774    /**
775      * Number of FieldPosition and UFieldPosition selectors for
776      * DateFormat and UDateFormat.
777      * Valid selectors range from 0 to UDAT_FIELD_COUNT-1.
778      * This value is subject to change if new fields are defined
779      * in the future.
780      * @stable ICU 3.0
781      */
782     UDAT_FIELD_COUNT = 36
783 
784 } UDateFormatField;
785 
786 
787 #ifndef U_HIDE_INTERNAL_API
788 /**
789  * Is a pattern character defined for UDAT_TIME_SEPARATOR_FIELD?
790  * In ICU 55 it was COLON, but that was withdrawn in ICU 56.
791  * @internal ICU 56
792  */
793 #define UDAT_HAS_PATTERN_CHAR_FOR_TIME_SEPARATOR 0
794 #endif /* U_HIDE_INTERNAL_API */
795 
796 
797 /**
798  * Maps from a UDateFormatField to the corresponding UCalendarDateFields.
799  * Note: since the mapping is many-to-one, there is no inverse mapping.
800  * @param field the UDateFormatField.
801  * @return the UCalendarDateField.  This will be UCAL_FIELD_COUNT in case
802  * of error (e.g., the input field is UDAT_FIELD_COUNT).
803  * @stable ICU 4.4
804  */
805 U_STABLE UCalendarDateFields U_EXPORT2
806 udat_toCalendarDateField(UDateFormatField field);
807 
808 
809 /**
810  * Open a new UDateFormat for formatting and parsing dates and times.
811  * A UDateFormat may be used to format dates in calls to {@link #udat_format },
812  * and to parse dates in calls to {@link #udat_parse }.
813  * @param timeStyle The style used to format times; one of UDAT_FULL, UDAT_LONG,
814  * UDAT_MEDIUM, UDAT_SHORT, UDAT_DEFAULT, or UDAT_NONE (relative time styles
815  * are not currently supported).
816  * When the pattern parameter is used, pass in UDAT_PATTERN for both timeStyle and dateStyle.
817  * @param dateStyle The style used to format dates; one of UDAT_FULL, UDAT_LONG,
818  * UDAT_MEDIUM, UDAT_SHORT, UDAT_DEFAULT, UDAT_FULL_RELATIVE, UDAT_LONG_RELATIVE,
819  * UDAT_MEDIUM_RELATIVE, UDAT_SHORT_RELATIVE, or UDAT_NONE.
820  * When the pattern parameter is used, pass in UDAT_PATTERN for both timeStyle and dateStyle.
821  * As currently implemented,
822  * relative date formatting only affects a limited range of calendar days before or
823  * after the current date, based on the CLDR &lt;field type="day"&gt;/&lt;relative&gt; data: For
824  * example, in English, "Yesterday", "Today", and "Tomorrow". Outside of this range,
825  * dates are formatted using the corresponding non-relative style.
826  * @param locale The locale specifying the formatting conventions
827  * @param tzID A timezone ID specifying the timezone to use.  If 0, use
828  * the default timezone.
829  * @param tzIDLength The length of tzID, or -1 if null-terminated.
830  * @param pattern A pattern specifying the format to use.
831  * @param patternLength The number of characters in the pattern, or -1 if null-terminated.
832  * @param status A pointer to an UErrorCode to receive any errors
833  * @return A pointer to a UDateFormat to use for formatting dates and times, or 0 if
834  * an error occurred.
835  * @stable ICU 2.0
836  */
837 U_STABLE UDateFormat* U_EXPORT2
838 udat_open(UDateFormatStyle  timeStyle,
839           UDateFormatStyle  dateStyle,
840           const char        *locale,
841           const UChar       *tzID,
842           int32_t           tzIDLength,
843           const UChar       *pattern,
844           int32_t           patternLength,
845           UErrorCode        *status);
846 
847 
848 /**
849 * Close a UDateFormat.
850 * Once closed, a UDateFormat may no longer be used.
851 * @param format The formatter to close.
852 * @stable ICU 2.0
853 */
854 U_STABLE void U_EXPORT2
855 udat_close(UDateFormat* format);
856 
857 
858 /**
859  * DateFormat boolean attributes
860  *
861  * @stable ICU 53
862  */
863 typedef enum UDateFormatBooleanAttribute {
864    /**
865      * indicates whether whitespace is allowed. Includes trailing dot tolerance.
866      * @stable ICU 53
867      */
868     UDAT_PARSE_ALLOW_WHITESPACE = 0,
869     /**
870      * indicates tolerance of numeric data when String data may be assumed. eg: UDAT_YEAR_NAME_FIELD,
871      * UDAT_STANDALONE_MONTH_FIELD, UDAT_DAY_OF_WEEK_FIELD
872      * @stable ICU 53
873      */
874     UDAT_PARSE_ALLOW_NUMERIC = 1,
875 #ifndef U_HIDE_DRAFT_API
876     /**
877      * indicates tolerance of a partial literal match
878      * e.g. accepting "--mon-02-march-2011" for a pattern of "'--: 'EEE-WW-MMMM-yyyy"
879      * @draft ICU 56
880      */
881     UDAT_PARSE_PARTIAL_LITERAL_MATCH = 2,
882     /**
883      * indicates tolerance of pattern mismatch between input data and specified format pattern.
884      * e.g. accepting "September" for a month pattern of MMM ("Sep")
885      * @draft ICU 56
886      */
887     UDAT_PARSE_MULTIPLE_PATTERNS_FOR_MATCH = 3,
888 #endif /* U_HIDE_DRAFT_API */
889     /**
890      * count boolean date format constants
891      * @stable ICU 53
892      */
893     UDAT_BOOLEAN_ATTRIBUTE_COUNT = 4
894 } UDateFormatBooleanAttribute;
895 
896 /**
897  * Get a boolean attribute associated with a UDateFormat.
898  * An example would be a true value for a key of UDAT_PARSE_ALLOW_WHITESPACE indicating allowing whitespace leniency.
899  * If the formatter does not understand the attribute, -1 is returned.
900  * @param fmt The formatter to query.
901  * @param attr The attribute to query; e.g. UDAT_PARSE_ALLOW_WHITESPACE.
902  * @param status A pointer to an UErrorCode to receive any errors
903  * @return The value of attr.
904  * @stable ICU 53
905  */
906 U_STABLE UBool U_EXPORT2
907 udat_getBooleanAttribute(const UDateFormat* fmt, UDateFormatBooleanAttribute attr, UErrorCode* status);
908 
909 /**
910  * Set a boolean attribute associated with a UDateFormat.
911  * An example of a boolean attribute is parse leniency control.  If the formatter does not understand
912  * the attribute, the call is ignored.
913  * @param fmt The formatter to set.
914  * @param attr The attribute to set; one of UDAT_PARSE_ALLOW_WHITESPACE or UDAT_PARSE_ALLOW_NUMERIC
915  * @param newValue The new value of attr.
916  * @param status A pointer to an UErrorCode to receive any errors
917  * @stable ICU 53
918  */
919 U_STABLE void U_EXPORT2
920 udat_setBooleanAttribute(UDateFormat *fmt, UDateFormatBooleanAttribute attr, UBool newValue, UErrorCode* status);
921 
922 
923 
924 #if U_SHOW_CPLUSPLUS_API
925 
926 U_NAMESPACE_BEGIN
927 
928 /**
929  * \class LocalUDateFormatPointer
930  * "Smart pointer" class, closes a UDateFormat via udat_close().
931  * For most methods see the LocalPointerBase base class.
932  *
933  * @see LocalPointerBase
934  * @see LocalPointer
935  * @stable ICU 4.4
936  */
937 U_DEFINE_LOCAL_OPEN_POINTER(LocalUDateFormatPointer, UDateFormat, udat_close);
938 
939 U_NAMESPACE_END
940 
941 #endif
942 
943 /**
944  * Open a copy of a UDateFormat.
945  * This function performs a deep copy.
946  * @param fmt The format to copy
947  * @param status A pointer to an UErrorCode to receive any errors.
948  * @return A pointer to a UDateFormat identical to fmt.
949  * @stable ICU 2.0
950  */
951 U_STABLE UDateFormat* U_EXPORT2
952 udat_clone(const UDateFormat *fmt,
953        UErrorCode *status);
954 
955 /**
956 * Format a date using a UDateFormat.
957 * The date will be formatted using the conventions specified in {@link #udat_open }
958 * @param format The formatter to use
959 * @param dateToFormat The date to format
960 * @param result A pointer to a buffer to receive the formatted number.
961 * @param resultLength The maximum size of result.
962 * @param position A pointer to a UFieldPosition.  On input, position->field
963 * is read.  On output, position->beginIndex and position->endIndex indicate
964 * the beginning and ending indices of field number position->field, if such
965 * a field exists.  This parameter may be NULL, in which case no field
966 * position data is returned.
967 * @param status A pointer to an UErrorCode to receive any errors
968 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
969 * @see udat_parse
970 * @see UFieldPosition
971 * @stable ICU 2.0
972 */
973 U_STABLE int32_t U_EXPORT2
974 udat_format(    const    UDateFormat*    format,
975                         UDate           dateToFormat,
976                         UChar*          result,
977                         int32_t         resultLength,
978                         UFieldPosition* position,
979                         UErrorCode*     status);
980 
981 #ifndef U_HIDE_DRAFT_API
982 /**
983 * Format a date using an UDateFormat.
984 * The date will be formatted using the conventions specified in {@link #udat_open }
985 * @param format The formatter to use
986 * @param calendar The calendar to format. The calendar instance might be
987 *                 mutated if fields are not yet fully calculated, though
988 *                 the function won't change the logical date and time held
989 *                 by the instance.
990 * @param result A pointer to a buffer to receive the formatted number.
991 * @param capacity The maximum size of result.
992 * @param position A pointer to a UFieldPosition.  On input, position->field
993 * is read.  On output, position->beginIndex and position->endIndex indicate
994 * the beginning and ending indices of field number position->field, if such
995 * a field exists.  This parameter may be NULL, in which case no field
996 * position data is returned.
997 * @param status A pointer to an UErrorCode to receive any errors
998 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
999 * @see udat_format
1000 * @see udat_parseCalendar
1001 * @see UFieldPosition
1002 * @draft ICU 55
1003 */
1004 U_DRAFT int32_t U_EXPORT2
1005 udat_formatCalendar(    const UDateFormat*  format,
1006                         UCalendar*      calendar,
1007                         UChar*          result,
1008                         int32_t         capacity,
1009                         UFieldPosition* position,
1010                         UErrorCode*     status);
1011 
1012 /**
1013 * Format a date using a UDateFormat.
1014 * The date will be formatted using the conventions specified in {@link #udat_open}
1015 * @param format
1016 *          The formatter to use
1017 * @param dateToFormat
1018 *          The date to format
1019 * @param result
1020 *          A pointer to a buffer to receive the formatted number.
1021 * @param resultLength
1022 *          The maximum size of result.
1023 * @param fpositer
1024 *          A pointer to a UFieldPositionIterator created by {@link #ufieldpositer_open}
1025 *          (may be NULL if field position information is not needed). Any
1026 *          iteration information already present in the UFieldPositionIterator
1027 *          will be deleted, and the iterator will be reset to apply to the
1028 *          fields in the formatted string created by this function call; the
1029 *          field values provided by {@link #ufieldpositer_next} will be from the
1030 *          UDateFormatField enum.
1031 * @param status
1032 *          A pointer to a UErrorCode to receive any errors
1033 * @return
1034 *          The total buffer size needed; if greater than resultLength, the output was truncated.
1035 * @see udat_parse
1036 * @see UFieldPositionIterator
1037 * @draft ICU 55
1038 */
1039 U_DRAFT int32_t U_EXPORT2
1040 udat_formatForFields(   const UDateFormat* format,
1041                         UDate           dateToFormat,
1042                         UChar*          result,
1043                         int32_t         resultLength,
1044                         UFieldPositionIterator* fpositer,
1045                         UErrorCode*     status);
1046 
1047 /**
1048 * Format a date using a UDateFormat.
1049 * The date will be formatted using the conventions specified in {@link #udat_open }
1050 * @param format
1051 *          The formatter to use
1052 * @param calendar
1053 *          The calendar to format. The calendar instance might be mutated if fields
1054 *          are not yet fully calculated, though the function won't change the logical
1055 *          date and time held by the instance.
1056 * @param result
1057 *          A pointer to a buffer to receive the formatted number.
1058 * @param capacity
1059 *          The maximum size of result.
1060 * @param fpositer
1061 *          A pointer to a UFieldPositionIterator created by {@link #ufieldpositer_open}
1062 *          (may be NULL if field position information is not needed). Any
1063 *          iteration information already present in the UFieldPositionIterator
1064 *          will be deleted, and the iterator will be reset to apply to the
1065 *          fields in the formatted string created by this function call; the
1066 *          field values provided by {@link #ufieldpositer_next} will be from the
1067 *          UDateFormatField enum.
1068 * @param status
1069 *          A pointer to a UErrorCode to receive any errors
1070 * @return
1071 *          The total buffer size needed; if greater than resultLength, the output was truncated.
1072 * @see udat_format
1073 * @see udat_parseCalendar
1074 * @see UFieldPositionIterator
1075 * @draft ICU 55
1076 */
1077 U_DRAFT int32_t U_EXPORT2
1078 udat_formatCalendarForFields( const UDateFormat* format,
1079                         UCalendar*      calendar,
1080                         UChar*          result,
1081                         int32_t         capacity,
1082                         UFieldPositionIterator* fpositer,
1083                         UErrorCode*     status);
1084 
1085 #endif  /* U_HIDE_DRAFT_API */
1086 
1087 /**
1088 * Parse a string into an date/time using a UDateFormat.
1089 * The date will be parsed using the conventions specified in {@link #udat_open }.
1090 * <P>
1091 * Note that the normal date formats associated with some calendars - such
1092 * as the Chinese lunar calendar - do not specify enough fields to enable
1093 * dates to be parsed unambiguously. In the case of the Chinese lunar
1094 * calendar, while the year within the current 60-year cycle is specified,
1095 * the number of such cycles since the start date of the calendar (in the
1096 * UCAL_ERA field of the UCalendar object) is not normally part of the format,
1097 * and parsing may assume the wrong era. For cases such as this it is
1098 * recommended that clients parse using udat_parseCalendar with the UCalendar
1099 * passed in set to the current date, or to a date within the era/cycle that
1100 * should be assumed if absent in the format.
1101 *
1102 * @param format The formatter to use.
1103 * @param text The text to parse.
1104 * @param textLength The length of text, or -1 if null-terminated.
1105 * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which
1106 * to begin parsing.  If not 0, on output the offset at which parsing ended.
1107 * @param status A pointer to an UErrorCode to receive any errors
1108 * @return The value of the parsed date/time
1109 * @see udat_format
1110 * @stable ICU 2.0
1111 */
1112 U_STABLE UDate U_EXPORT2
1113 udat_parse(const    UDateFormat*    format,
1114            const    UChar*          text,
1115                     int32_t         textLength,
1116                     int32_t         *parsePos,
1117                     UErrorCode      *status);
1118 
1119 /**
1120 * Parse a string into an date/time using a UDateFormat.
1121 * The date will be parsed using the conventions specified in {@link #udat_open }.
1122 * @param format The formatter to use.
1123 * @param calendar A calendar set on input to the date and time to be used for
1124 *                 missing values in the date/time string being parsed, and set
1125 *                 on output to the parsed date/time. When the calendar type is
1126 *                 different from the internal calendar held by the UDateFormat
1127 *                 instance, the internal calendar will be cloned to a work
1128 *                 calendar set to the same milliseconds and time zone as this
1129 *                 calendar parameter, field values will be parsed based on the
1130 *                 work calendar, then the result (milliseconds and time zone)
1131 *                 will be set in this calendar.
1132 * @param text The text to parse.
1133 * @param textLength The length of text, or -1 if null-terminated.
1134 * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which
1135 * to begin parsing.  If not 0, on output the offset at which parsing ended.
1136 * @param status A pointer to an UErrorCode to receive any errors
1137 * @see udat_format
1138 * @stable ICU 2.0
1139 */
1140 U_STABLE void U_EXPORT2
1141 udat_parseCalendar(const    UDateFormat*    format,
1142                             UCalendar*      calendar,
1143                    const    UChar*          text,
1144                             int32_t         textLength,
1145                             int32_t         *parsePos,
1146                             UErrorCode      *status);
1147 
1148 /**
1149 * Determine if an UDateFormat will perform lenient parsing.
1150 * With lenient parsing, the parser may use heuristics to interpret inputs that do not
1151 * precisely match the pattern. With strict parsing, inputs must match the pattern.
1152 * @param fmt The formatter to query
1153 * @return TRUE if fmt is set to perform lenient parsing, FALSE otherwise.
1154 * @see udat_setLenient
1155 * @stable ICU 2.0
1156 */
1157 U_STABLE UBool U_EXPORT2
1158 udat_isLenient(const UDateFormat* fmt);
1159 
1160 /**
1161 * Specify whether an UDateFormat will perform lenient parsing.
1162 * With lenient parsing, the parser may use heuristics to interpret inputs that do not
1163 * precisely match the pattern. With strict parsing, inputs must match the pattern.
1164 * @param fmt The formatter to set
1165 * @param isLenient TRUE if fmt should perform lenient parsing, FALSE otherwise.
1166 * @see dat_isLenient
1167 * @stable ICU 2.0
1168 */
1169 U_STABLE void U_EXPORT2
1170 udat_setLenient(    UDateFormat*    fmt,
1171                     UBool          isLenient);
1172 
1173 /**
1174 * Get the UCalendar associated with an UDateFormat.
1175 * A UDateFormat uses a UCalendar to convert a raw value to, for example,
1176 * the day of the week.
1177 * @param fmt The formatter to query.
1178 * @return A pointer to the UCalendar used by fmt.
1179 * @see udat_setCalendar
1180 * @stable ICU 2.0
1181 */
1182 U_STABLE const UCalendar* U_EXPORT2
1183 udat_getCalendar(const UDateFormat* fmt);
1184 
1185 /**
1186 * Set the UCalendar associated with an UDateFormat.
1187 * A UDateFormat uses a UCalendar to convert a raw value to, for example,
1188 * the day of the week.
1189 * @param fmt The formatter to set.
1190 * @param calendarToSet A pointer to an UCalendar to be used by fmt.
1191 * @see udat_setCalendar
1192 * @stable ICU 2.0
1193 */
1194 U_STABLE void U_EXPORT2
1195 udat_setCalendar(            UDateFormat*    fmt,
1196                     const   UCalendar*      calendarToSet);
1197 
1198 /**
1199 * Get the UNumberFormat associated with an UDateFormat.
1200 * A UDateFormat uses a UNumberFormat to format numbers within a date,
1201 * for example the day number.
1202 * @param fmt The formatter to query.
1203 * @return A pointer to the UNumberFormat used by fmt to format numbers.
1204 * @see udat_setNumberFormat
1205 * @stable ICU 2.0
1206 */
1207 U_STABLE const UNumberFormat* U_EXPORT2
1208 udat_getNumberFormat(const UDateFormat* fmt);
1209 
1210 /**
1211 * Get the UNumberFormat for specific field associated with an UDateFormat.
1212 * For example: 'y' for year and 'M' for month
1213 * @param fmt The formatter to query.
1214 * @param field the field to query
1215 * @return A pointer to the UNumberFormat used by fmt to format field numbers.
1216 * @see udat_setNumberFormatForField
1217 * @stable ICU 54
1218 */
1219 U_STABLE const UNumberFormat* U_EXPORT2
1220 udat_getNumberFormatForField(const UDateFormat* fmt, UChar field);
1221 
1222 /**
1223 * Set the UNumberFormat for specific field associated with an UDateFormat.
1224 * It can be a single field like: "y"(year) or "M"(month)
1225 * It can be several field combined together: "yM"(year and month)
1226 * Note:
1227 * 1 symbol field is enough for multiple symbol field (so "y" will override "yy", "yyy")
1228 * If the field is not numeric, then override has no effect (like "MMM" will use abbreviation, not numerical field)
1229 *
1230 * @param fields the fields to set
1231 * @param fmt The formatter to set.
1232 * @param numberFormatToSet A pointer to the UNumberFormat to be used by fmt to format numbers.
1233 * @param status error code passed around (memory allocation or invalid fields)
1234 * @see udat_getNumberFormatForField
1235 * @stable ICU 54
1236 */
1237 U_STABLE void U_EXPORT2
1238 udat_adoptNumberFormatForFields(  UDateFormat* fmt,
1239                             const UChar* fields,
1240                                   UNumberFormat*  numberFormatToSet,
1241                                   UErrorCode* status);
1242 /**
1243 * Set the UNumberFormat associated with an UDateFormat.
1244 * A UDateFormat uses a UNumberFormat to format numbers within a date,
1245 * for example the day number.
1246 * This method also clears per field NumberFormat instances previously
1247 * set by {@see udat_setNumberFormatForField}
1248 * @param fmt The formatter to set.
1249 * @param numberFormatToSet A pointer to the UNumberFormat to be used by fmt to format numbers.
1250 * @see udat_getNumberFormat
1251 * @see udat_setNumberFormatForField
1252 * @stable ICU 2.0
1253 */
1254 U_STABLE void U_EXPORT2
1255 udat_setNumberFormat(            UDateFormat*    fmt,
1256                         const   UNumberFormat*  numberFormatToSet);
1257 /**
1258 * Adopt the UNumberFormat associated with an UDateFormat.
1259 * A UDateFormat uses a UNumberFormat to format numbers within a date,
1260 * for example the day number.
1261 * @param fmt The formatter to set.
1262 * @param numberFormatToAdopt A pointer to the UNumberFormat to be used by fmt to format numbers.
1263 * @see udat_getNumberFormat
1264 * @stable ICU 54
1265 */
1266 U_STABLE void U_EXPORT2
1267 udat_adoptNumberFormat(            UDateFormat*    fmt,
1268                                    UNumberFormat*  numberFormatToAdopt);
1269 /**
1270 * Get a locale for which date/time formatting patterns are available.
1271 * A UDateFormat in a locale returned by this function will perform the correct
1272 * formatting and parsing for the locale.
1273 * @param localeIndex The index of the desired locale.
1274 * @return A locale for which date/time formatting patterns are available, or 0 if none.
1275 * @see udat_countAvailable
1276 * @stable ICU 2.0
1277 */
1278 U_STABLE const char* U_EXPORT2
1279 udat_getAvailable(int32_t localeIndex);
1280 
1281 /**
1282 * Determine how many locales have date/time  formatting patterns available.
1283 * This function is most useful as determining the loop ending condition for
1284 * calls to {@link #udat_getAvailable }.
1285 * @return The number of locales for which date/time formatting patterns are available.
1286 * @see udat_getAvailable
1287 * @stable ICU 2.0
1288 */
1289 U_STABLE int32_t U_EXPORT2
1290 udat_countAvailable(void);
1291 
1292 /**
1293 * Get the year relative to which all 2-digit years are interpreted.
1294 * For example, if the 2-digit start year is 2100, the year 99 will be
1295 * interpreted as 2199.
1296 * @param fmt The formatter to query.
1297 * @param status A pointer to an UErrorCode to receive any errors
1298 * @return The year relative to which all 2-digit years are interpreted.
1299 * @see udat_Set2DigitYearStart
1300 * @stable ICU 2.0
1301 */
1302 U_STABLE UDate U_EXPORT2
1303 udat_get2DigitYearStart(    const   UDateFormat     *fmt,
1304                                     UErrorCode      *status);
1305 
1306 /**
1307 * Set the year relative to which all 2-digit years will be interpreted.
1308 * For example, if the 2-digit start year is 2100, the year 99 will be
1309 * interpreted as 2199.
1310 * @param fmt The formatter to set.
1311 * @param d The year relative to which all 2-digit years will be interpreted.
1312 * @param status A pointer to an UErrorCode to receive any errors
1313 * @see udat_Set2DigitYearStart
1314 * @stable ICU 2.0
1315 */
1316 U_STABLE void U_EXPORT2
1317 udat_set2DigitYearStart(    UDateFormat     *fmt,
1318                             UDate           d,
1319                             UErrorCode      *status);
1320 
1321 /**
1322 * Extract the pattern from a UDateFormat.
1323 * The pattern will follow the pattern syntax rules.
1324 * @param fmt The formatter to query.
1325 * @param localized TRUE if the pattern should be localized, FALSE otherwise.
1326 * @param result A pointer to a buffer to receive the pattern.
1327 * @param resultLength The maximum size of result.
1328 * @param status A pointer to an UErrorCode to receive any errors
1329 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
1330 * @see udat_applyPattern
1331 * @stable ICU 2.0
1332 */
1333 U_STABLE int32_t U_EXPORT2
1334 udat_toPattern(    const   UDateFormat     *fmt,
1335                         UBool          localized,
1336                         UChar           *result,
1337                         int32_t         resultLength,
1338                         UErrorCode      *status);
1339 
1340 /**
1341 * Set the pattern used by an UDateFormat.
1342 * The pattern should follow the pattern syntax rules.
1343 * @param format The formatter to set.
1344 * @param localized TRUE if the pattern is localized, FALSE otherwise.
1345 * @param pattern The new pattern
1346 * @param patternLength The length of pattern, or -1 if null-terminated.
1347 * @see udat_toPattern
1348 * @stable ICU 2.0
1349 */
1350 U_STABLE void U_EXPORT2
1351 udat_applyPattern(            UDateFormat     *format,
1352                             UBool          localized,
1353                     const   UChar           *pattern,
1354                             int32_t         patternLength);
1355 
1356 /**
1357  * The possible types of date format symbols
1358  * @stable ICU 2.6
1359  */
1360 typedef enum UDateFormatSymbolType {
1361     /** The era names, for example AD */
1362     UDAT_ERAS,
1363     /** The month names, for example February */
1364     UDAT_MONTHS,
1365     /** The short month names, for example Feb. */
1366     UDAT_SHORT_MONTHS,
1367     /** The CLDR-style format "wide" weekday names, for example Monday */
1368     UDAT_WEEKDAYS,
1369     /**
1370      * The CLDR-style format "abbreviated" (not "short") weekday names, for example "Mon."
1371      * For the CLDR-style format "short" weekday names, use UDAT_SHORTER_WEEKDAYS.
1372      */
1373     UDAT_SHORT_WEEKDAYS,
1374     /** The AM/PM names, for example AM */
1375     UDAT_AM_PMS,
1376     /** The localized characters */
1377     UDAT_LOCALIZED_CHARS,
1378     /** The long era names, for example Anno Domini */
1379     UDAT_ERA_NAMES,
1380     /** The narrow month names, for example F */
1381     UDAT_NARROW_MONTHS,
1382     /** The CLDR-style format "narrow" weekday names, for example "M" */
1383     UDAT_NARROW_WEEKDAYS,
1384     /** Standalone context versions of months */
1385     UDAT_STANDALONE_MONTHS,
1386     UDAT_STANDALONE_SHORT_MONTHS,
1387     UDAT_STANDALONE_NARROW_MONTHS,
1388     /** The CLDR-style stand-alone "wide" weekday names */
1389     UDAT_STANDALONE_WEEKDAYS,
1390     /**
1391      * The CLDR-style stand-alone "abbreviated" (not "short") weekday names.
1392      * For the CLDR-style stand-alone "short" weekday names, use UDAT_STANDALONE_SHORTER_WEEKDAYS.
1393      */
1394     UDAT_STANDALONE_SHORT_WEEKDAYS,
1395     /** The CLDR-style stand-alone "narrow" weekday names */
1396     UDAT_STANDALONE_NARROW_WEEKDAYS,
1397     /** The quarters, for example 1st Quarter */
1398     UDAT_QUARTERS,
1399     /** The short quarter names, for example Q1 */
1400     UDAT_SHORT_QUARTERS,
1401     /** Standalone context versions of quarters */
1402     UDAT_STANDALONE_QUARTERS,
1403     UDAT_STANDALONE_SHORT_QUARTERS,
1404     /**
1405      * The CLDR-style short weekday names, e.g. "Su", Mo", etc.
1406      * These are named "SHORTER" to contrast with the constants using _SHORT_
1407      * above, which actually get the CLDR-style *abbreviated* versions of the
1408      * corresponding names.
1409      * @stable ICU 51
1410      */
1411     UDAT_SHORTER_WEEKDAYS,
1412     /**
1413      * Standalone version of UDAT_SHORTER_WEEKDAYS.
1414      * @stable ICU 51
1415      */
1416     UDAT_STANDALONE_SHORTER_WEEKDAYS,
1417     /**
1418      * Cyclic year names (only supported for some calendars, and only for FORMAT usage;
1419      * udat_setSymbols not supported for UDAT_CYCLIC_YEARS_WIDE)
1420      * @stable ICU 54
1421      */
1422     UDAT_CYCLIC_YEARS_WIDE,
1423     /**
1424      * Cyclic year names (only supported for some calendars, and only for FORMAT usage)
1425      * @stable ICU 54
1426      */
1427     UDAT_CYCLIC_YEARS_ABBREVIATED,
1428     /**
1429      * Cyclic year names (only supported for some calendars, and only for FORMAT usage;
1430      * udat_setSymbols not supported for UDAT_CYCLIC_YEARS_NARROW)
1431      * @stable ICU 54
1432      */
1433     UDAT_CYCLIC_YEARS_NARROW,
1434     /**
1435      * Calendar zodiac  names (only supported for some calendars, and only for FORMAT usage;
1436      * udat_setSymbols not supported for UDAT_ZODIAC_NAMES_WIDE)
1437      * @stable ICU 54
1438      */
1439     UDAT_ZODIAC_NAMES_WIDE,
1440     /**
1441      * Calendar zodiac  names (only supported for some calendars, and only for FORMAT usage)
1442      * @stable ICU 54
1443      */
1444     UDAT_ZODIAC_NAMES_ABBREVIATED,
1445     /**
1446      * Calendar zodiac  names (only supported for some calendars, and only for FORMAT usage;
1447      * udat_setSymbols not supported for UDAT_ZODIAC_NAMES_NARROW)
1448      * @stable ICU 54
1449      */
1450     UDAT_ZODIAC_NAMES_NARROW
1451 } UDateFormatSymbolType;
1452 
1453 struct UDateFormatSymbols;
1454 /** Date format symbols.
1455  *  For usage in C programs.
1456  *  @stable ICU 2.6
1457  */
1458 typedef struct UDateFormatSymbols UDateFormatSymbols;
1459 
1460 /**
1461 * Get the symbols associated with an UDateFormat.
1462 * The symbols are what a UDateFormat uses to represent locale-specific data,
1463 * for example month or day names.
1464 * @param fmt The formatter to query.
1465 * @param type The type of symbols to get.  One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS,
1466 * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS
1467 * @param symbolIndex The desired symbol of type type.
1468 * @param result A pointer to a buffer to receive the pattern.
1469 * @param resultLength The maximum size of result.
1470 * @param status A pointer to an UErrorCode to receive any errors
1471 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
1472 * @see udat_countSymbols
1473 * @see udat_setSymbols
1474 * @stable ICU 2.0
1475 */
1476 U_STABLE int32_t U_EXPORT2
1477 udat_getSymbols(const   UDateFormat             *fmt,
1478                         UDateFormatSymbolType   type,
1479                         int32_t                 symbolIndex,
1480                         UChar                   *result,
1481                         int32_t                 resultLength,
1482                         UErrorCode              *status);
1483 
1484 /**
1485 * Count the number of particular symbols for an UDateFormat.
1486 * This function is most useful as for detemining the loop termination condition
1487 * for calls to {@link #udat_getSymbols }.
1488 * @param fmt The formatter to query.
1489 * @param type The type of symbols to count.  One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS,
1490 * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS
1491 * @return The number of symbols of type type.
1492 * @see udat_getSymbols
1493 * @see udat_setSymbols
1494 * @stable ICU 2.0
1495 */
1496 U_STABLE int32_t U_EXPORT2
1497 udat_countSymbols(    const    UDateFormat                *fmt,
1498                             UDateFormatSymbolType    type);
1499 
1500 /**
1501 * Set the symbols associated with an UDateFormat.
1502 * The symbols are what a UDateFormat uses to represent locale-specific data,
1503 * for example month or day names.
1504 * @param format The formatter to set
1505 * @param type The type of symbols to set.  One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS,
1506 * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS
1507 * @param symbolIndex The index of the symbol to set of type type.
1508 * @param value The new value
1509 * @param valueLength The length of value, or -1 if null-terminated
1510 * @param status A pointer to an UErrorCode to receive any errors
1511 * @see udat_getSymbols
1512 * @see udat_countSymbols
1513 * @stable ICU 2.0
1514 */
1515 U_STABLE void U_EXPORT2
1516 udat_setSymbols(    UDateFormat             *format,
1517                     UDateFormatSymbolType   type,
1518                     int32_t                 symbolIndex,
1519                     UChar                   *value,
1520                     int32_t                 valueLength,
1521                     UErrorCode              *status);
1522 
1523 /**
1524  * Get the locale for this date format object.
1525  * You can choose between valid and actual locale.
1526  * @param fmt The formatter to get the locale from
1527  * @param type type of the locale we're looking for (valid or actual)
1528  * @param status error code for the operation
1529  * @return the locale name
1530  * @stable ICU 2.8
1531  */
1532 U_STABLE const char* U_EXPORT2
1533 udat_getLocaleByType(const UDateFormat *fmt,
1534                      ULocDataLocaleType type,
1535                      UErrorCode* status);
1536 
1537 /**
1538  * Set a particular UDisplayContext value in the formatter, such as
1539  * UDISPCTX_CAPITALIZATION_FOR_STANDALONE.
1540  * @param fmt The formatter for which to set a UDisplayContext value.
1541  * @param value The UDisplayContext value to set.
1542  * @param status A pointer to an UErrorCode to receive any errors
1543  * @stable ICU 51
1544  */
1545 U_DRAFT void U_EXPORT2
1546 udat_setContext(UDateFormat* fmt, UDisplayContext value, UErrorCode* status);
1547 
1548 /**
1549  * Get the formatter's UDisplayContext value for the specified UDisplayContextType,
1550  * such as UDISPCTX_TYPE_CAPITALIZATION.
1551  * @param fmt The formatter to query.
1552  * @param type The UDisplayContextType whose value to return
1553  * @param status A pointer to an UErrorCode to receive any errors
1554  * @return The UDisplayContextValue for the specified type.
1555  * @stable ICU 53
1556  */
1557 U_STABLE UDisplayContext U_EXPORT2
1558 udat_getContext(const UDateFormat* fmt, UDisplayContextType type, UErrorCode* status);
1559 
1560 #ifndef U_HIDE_INTERNAL_API
1561 /**
1562 * Extract the date pattern from a UDateFormat set for relative date formatting.
1563 * The pattern will follow the pattern syntax rules.
1564 * @param fmt The formatter to query.
1565 * @param result A pointer to a buffer to receive the pattern.
1566 * @param resultLength The maximum size of result.
1567 * @param status A pointer to a UErrorCode to receive any errors
1568 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
1569 * @see udat_applyPatternRelative
1570 * @internal ICU 4.2 technology preview
1571 */
1572 U_INTERNAL int32_t U_EXPORT2
1573 udat_toPatternRelativeDate(const UDateFormat *fmt,
1574                            UChar             *result,
1575                            int32_t           resultLength,
1576                            UErrorCode        *status);
1577 
1578 /**
1579 * Extract the time pattern from a UDateFormat set for relative date formatting.
1580 * The pattern will follow the pattern syntax rules.
1581 * @param fmt The formatter to query.
1582 * @param result A pointer to a buffer to receive the pattern.
1583 * @param resultLength The maximum size of result.
1584 * @param status A pointer to a UErrorCode to receive any errors
1585 * @return The total buffer size needed; if greater than resultLength, the output was truncated.
1586 * @see udat_applyPatternRelative
1587 * @internal ICU 4.2 technology preview
1588 */
1589 U_INTERNAL int32_t U_EXPORT2
1590 udat_toPatternRelativeTime(const UDateFormat *fmt,
1591                            UChar             *result,
1592                            int32_t           resultLength,
1593                            UErrorCode        *status);
1594 
1595 /**
1596 * Set the date & time patterns used by a UDateFormat set for relative date formatting.
1597 * The patterns should follow the pattern syntax rules.
1598 * @param format The formatter to set.
1599 * @param datePattern The new date pattern
1600 * @param datePatternLength The length of datePattern, or -1 if null-terminated.
1601 * @param timePattern The new time pattern
1602 * @param timePatternLength The length of timePattern, or -1 if null-terminated.
1603 * @param status A pointer to a UErrorCode to receive any errors
1604 * @see udat_toPatternRelativeDate, udat_toPatternRelativeTime
1605 * @internal ICU 4.2 technology preview
1606 */
1607 U_INTERNAL void U_EXPORT2
1608 udat_applyPatternRelative(UDateFormat *format,
1609                           const UChar *datePattern,
1610                           int32_t     datePatternLength,
1611                           const UChar *timePattern,
1612                           int32_t     timePatternLength,
1613                           UErrorCode  *status);
1614 
1615 /**
1616  * @internal
1617  * @see udat_open
1618  */
1619 typedef UDateFormat* (U_EXPORT2 *UDateFormatOpener) (UDateFormatStyle  timeStyle,
1620                                                     UDateFormatStyle  dateStyle,
1621                                                     const char        *locale,
1622                                                     const UChar       *tzID,
1623                                                     int32_t           tzIDLength,
1624                                                     const UChar       *pattern,
1625                                                     int32_t           patternLength,
1626                                                     UErrorCode        *status);
1627 
1628 /**
1629  * Register a provider factory
1630  * @internal ICU 49
1631  */
1632 U_INTERNAL void U_EXPORT2
1633 udat_registerOpener(UDateFormatOpener opener, UErrorCode *status);
1634 
1635 /**
1636  * Un-Register a provider factory
1637  * @internal ICU 49
1638  */
1639 U_INTERNAL UDateFormatOpener U_EXPORT2
1640 udat_unregisterOpener(UDateFormatOpener opener, UErrorCode *status);
1641 #endif  /* U_HIDE_INTERNAL_API */
1642 
1643 
1644 #endif /* #if !UCONFIG_NO_FORMATTING */
1645 
1646 #endif
1647