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