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 | /* deprecated skeleton constants */ |
454 | |
455 | #ifndef U_HIDE_DEPRECATED_API |
456 | /** |
457 | * Constant for date skeleton with standalone month. |
458 | * @deprecated ICU 50 Use UDAT_MONTH instead. |
459 | */ |
460 | #define UDAT_STANDALONE_MONTH "LLLL" |
461 | /** |
462 | * Constant for date skeleton with standalone abbreviated month. |
463 | * @deprecated ICU 50 Use UDAT_ABBR_MONTH instead. |
464 | */ |
465 | #define UDAT_ABBR_STANDALONE_MONTH "LLL" |
466 | |
467 | /** |
468 | * Constant for date skeleton with hour, minute, and generic timezone. |
469 | * @deprecated ICU 50 Use instead UDAT_HOUR_MINUTE UDAT_ABBR_GENERIC_TZ or some other timezone presentation. |
470 | */ |
471 | #define UDAT_HOUR_MINUTE_GENERIC_TZ "jmv" |
472 | /** |
473 | * Constant for date skeleton with hour, minute, and timezone. |
474 | * @deprecated ICU 50 Use instead UDAT_HOUR_MINUTE UDAT_ABBR_SPECIFIC_TZ or some other timezone presentation. |
475 | */ |
476 | #define UDAT_HOUR_MINUTE_TZ "jmz" |
477 | /** |
478 | * Constant for date skeleton with hour and generic timezone. |
479 | * @deprecated ICU 50 Use instead UDAT_HOUR UDAT_ABBR_GENERIC_TZ or some other timezone presentation. |
480 | */ |
481 | #define UDAT_HOUR_GENERIC_TZ "jv" |
482 | /** |
483 | * Constant for date skeleton with hour and timezone. |
484 | * @deprecated ICU 50 Use instead UDAT_HOUR UDAT_ABBR_SPECIFIC_TZ or some other timezone presentation. |
485 | */ |
486 | #define UDAT_HOUR_TZ "jz" |
487 | #endif /* U_HIDE_DEPRECATED_API */ |
488 | |
489 | #ifndef U_HIDE_INTERNAL_API |
490 | /** |
491 | * Constant for Unicode string name of new (in 2019) Japanese calendar era, |
492 | * root/English abbreviated version (ASCII-range characters). |
493 | * @internal |
494 | */ |
495 | #define JP_ERA_2019_ROOT "Reiwa" |
496 | /** |
497 | * Constant for Unicode string name of new (in 2019) Japanese calendar era, |
498 | * Japanese abbreviated version (Han, or fullwidth Latin for testing). |
499 | * @internal |
500 | */ |
501 | #define JP_ERA_2019_JA "\\u4EE4\\u548C" |
502 | /** |
503 | * Constant for Unicode string name of new (in 2019) Japanese calendar era, |
504 | * root and Japanese narrow version (ASCII-range characters). |
505 | * @internal |
506 | */ |
507 | #define JP_ERA_2019_NARROW "R" |
508 | #endif // U_HIDE_INTERNAL_API |
509 | |
510 | /** |
511 | * FieldPosition and UFieldPosition selectors for format fields |
512 | * defined by DateFormat and UDateFormat. |
513 | * @stable ICU 3.0 |
514 | */ |
515 | typedef enum UDateFormatField { |
516 | /** |
517 | * FieldPosition and UFieldPosition selector for 'G' field alignment, |
518 | * corresponding to the UCAL_ERA field. |
519 | * @stable ICU 3.0 |
520 | */ |
521 | UDAT_ERA_FIELD = 0, |
522 | |
523 | /** |
524 | * FieldPosition and UFieldPosition selector for 'y' field alignment, |
525 | * corresponding to the UCAL_YEAR field. |
526 | * @stable ICU 3.0 |
527 | */ |
528 | UDAT_YEAR_FIELD = 1, |
529 | |
530 | /** |
531 | * FieldPosition and UFieldPosition selector for 'M' field alignment, |
532 | * corresponding to the UCAL_MONTH field. |
533 | * @stable ICU 3.0 |
534 | */ |
535 | UDAT_MONTH_FIELD = 2, |
536 | |
537 | /** |
538 | * FieldPosition and UFieldPosition selector for 'd' field alignment, |
539 | * corresponding to the UCAL_DATE field. |
540 | * @stable ICU 3.0 |
541 | */ |
542 | UDAT_DATE_FIELD = 3, |
543 | |
544 | /** |
545 | * FieldPosition and UFieldPosition selector for 'k' field alignment, |
546 | * corresponding to the UCAL_HOUR_OF_DAY field. |
547 | * UDAT_HOUR_OF_DAY1_FIELD is used for the one-based 24-hour clock. |
548 | * For example, 23:59 + 01:00 results in 24:59. |
549 | * @stable ICU 3.0 |
550 | */ |
551 | UDAT_HOUR_OF_DAY1_FIELD = 4, |
552 | |
553 | /** |
554 | * FieldPosition and UFieldPosition selector for 'H' field alignment, |
555 | * corresponding to the UCAL_HOUR_OF_DAY field. |
556 | * UDAT_HOUR_OF_DAY0_FIELD is used for the zero-based 24-hour clock. |
557 | * For example, 23:59 + 01:00 results in 00:59. |
558 | * @stable ICU 3.0 |
559 | */ |
560 | UDAT_HOUR_OF_DAY0_FIELD = 5, |
561 | |
562 | /** |
563 | * FieldPosition and UFieldPosition selector for 'm' field alignment, |
564 | * corresponding to the UCAL_MINUTE field. |
565 | * @stable ICU 3.0 |
566 | */ |
567 | UDAT_MINUTE_FIELD = 6, |
568 | |
569 | /** |
570 | * FieldPosition and UFieldPosition selector for 's' field alignment, |
571 | * corresponding to the UCAL_SECOND field. |
572 | * @stable ICU 3.0 |
573 | */ |
574 | UDAT_SECOND_FIELD = 7, |
575 | |
576 | /** |
577 | * FieldPosition and UFieldPosition selector for 'S' field alignment, |
578 | * corresponding to the UCAL_MILLISECOND field. |
579 | * |
580 | * Note: Time formats that use 'S' can display a maximum of three |
581 | * significant digits for fractional seconds, corresponding to millisecond |
582 | * resolution and a fractional seconds sub-pattern of SSS. If the |
583 | * sub-pattern is S or SS, the fractional seconds value will be truncated |
584 | * (not rounded) to the number of display places specified. If the |
585 | * fractional seconds sub-pattern is longer than SSS, the additional |
586 | * display places will be filled with zeros. |
587 | * @stable ICU 3.0 |
588 | */ |
589 | UDAT_FRACTIONAL_SECOND_FIELD = 8, |
590 | |
591 | /** |
592 | * FieldPosition and UFieldPosition selector for 'E' field alignment, |
593 | * corresponding to the UCAL_DAY_OF_WEEK field. |
594 | * @stable ICU 3.0 |
595 | */ |
596 | UDAT_DAY_OF_WEEK_FIELD = 9, |
597 | |
598 | /** |
599 | * FieldPosition and UFieldPosition selector for 'D' field alignment, |
600 | * corresponding to the UCAL_DAY_OF_YEAR field. |
601 | * @stable ICU 3.0 |
602 | */ |
603 | UDAT_DAY_OF_YEAR_FIELD = 10, |
604 | |
605 | /** |
606 | * FieldPosition and UFieldPosition selector for 'F' field alignment, |
607 | * corresponding to the UCAL_DAY_OF_WEEK_IN_MONTH field. |
608 | * @stable ICU 3.0 |
609 | */ |
610 | UDAT_DAY_OF_WEEK_IN_MONTH_FIELD = 11, |
611 | |
612 | /** |
613 | * FieldPosition and UFieldPosition selector for 'w' field alignment, |
614 | * corresponding to the UCAL_WEEK_OF_YEAR field. |
615 | * @stable ICU 3.0 |
616 | */ |
617 | UDAT_WEEK_OF_YEAR_FIELD = 12, |
618 | |
619 | /** |
620 | * FieldPosition and UFieldPosition selector for 'W' field alignment, |
621 | * corresponding to the UCAL_WEEK_OF_MONTH field. |
622 | * @stable ICU 3.0 |
623 | */ |
624 | UDAT_WEEK_OF_MONTH_FIELD = 13, |
625 | |
626 | /** |
627 | * FieldPosition and UFieldPosition selector for 'a' field alignment, |
628 | * corresponding to the UCAL_AM_PM field. |
629 | * @stable ICU 3.0 |
630 | */ |
631 | UDAT_AM_PM_FIELD = 14, |
632 | |
633 | /** |
634 | * FieldPosition and UFieldPosition selector for 'h' field alignment, |
635 | * corresponding to the UCAL_HOUR field. |
636 | * UDAT_HOUR1_FIELD is used for the one-based 12-hour clock. |
637 | * For example, 11:30 PM + 1 hour results in 12:30 AM. |
638 | * @stable ICU 3.0 |
639 | */ |
640 | UDAT_HOUR1_FIELD = 15, |
641 | |
642 | /** |
643 | * FieldPosition and UFieldPosition selector for 'K' field alignment, |
644 | * corresponding to the UCAL_HOUR field. |
645 | * UDAT_HOUR0_FIELD is used for the zero-based 12-hour clock. |
646 | * For example, 11:30 PM + 1 hour results in 00:30 AM. |
647 | * @stable ICU 3.0 |
648 | */ |
649 | UDAT_HOUR0_FIELD = 16, |
650 | |
651 | /** |
652 | * FieldPosition and UFieldPosition selector for 'z' field alignment, |
653 | * corresponding to the UCAL_ZONE_OFFSET and |
654 | * UCAL_DST_OFFSET fields. |
655 | * @stable ICU 3.0 |
656 | */ |
657 | UDAT_TIMEZONE_FIELD = 17, |
658 | |
659 | /** |
660 | * FieldPosition and UFieldPosition selector for 'Y' field alignment, |
661 | * corresponding to the UCAL_YEAR_WOY field. |
662 | * @stable ICU 3.0 |
663 | */ |
664 | UDAT_YEAR_WOY_FIELD = 18, |
665 | |
666 | /** |
667 | * FieldPosition and UFieldPosition selector for 'e' field alignment, |
668 | * corresponding to the UCAL_DOW_LOCAL field. |
669 | * @stable ICU 3.0 |
670 | */ |
671 | UDAT_DOW_LOCAL_FIELD = 19, |
672 | |
673 | /** |
674 | * FieldPosition and UFieldPosition selector for 'u' field alignment, |
675 | * corresponding to the UCAL_EXTENDED_YEAR field. |
676 | * @stable ICU 3.0 |
677 | */ |
678 | UDAT_EXTENDED_YEAR_FIELD = 20, |
679 | |
680 | /** |
681 | * FieldPosition and UFieldPosition selector for 'g' field alignment, |
682 | * corresponding to the UCAL_JULIAN_DAY field. |
683 | * @stable ICU 3.0 |
684 | */ |
685 | UDAT_JULIAN_DAY_FIELD = 21, |
686 | |
687 | /** |
688 | * FieldPosition and UFieldPosition selector for 'A' field alignment, |
689 | * corresponding to the UCAL_MILLISECONDS_IN_DAY field. |
690 | * @stable ICU 3.0 |
691 | */ |
692 | UDAT_MILLISECONDS_IN_DAY_FIELD = 22, |
693 | |
694 | /** |
695 | * FieldPosition and UFieldPosition selector for 'Z' field alignment, |
696 | * corresponding to the UCAL_ZONE_OFFSET and |
697 | * UCAL_DST_OFFSET fields. |
698 | * @stable ICU 3.0 |
699 | */ |
700 | UDAT_TIMEZONE_RFC_FIELD = 23, |
701 | |
702 | /** |
703 | * FieldPosition and UFieldPosition selector for 'v' field alignment, |
704 | * corresponding to the UCAL_ZONE_OFFSET field. |
705 | * @stable ICU 3.4 |
706 | */ |
707 | UDAT_TIMEZONE_GENERIC_FIELD = 24, |
708 | /** |
709 | * FieldPosition selector for 'c' field alignment, |
710 | * corresponding to the {@link #UCAL_DOW_LOCAL} field. |
711 | * This displays the stand alone day name, if available. |
712 | * @stable ICU 3.4 |
713 | */ |
714 | UDAT_STANDALONE_DAY_FIELD = 25, |
715 | |
716 | /** |
717 | * FieldPosition selector for 'L' field alignment, |
718 | * corresponding to the {@link #UCAL_MONTH} field. |
719 | * This displays the stand alone month name, if available. |
720 | * @stable ICU 3.4 |
721 | */ |
722 | UDAT_STANDALONE_MONTH_FIELD = 26, |
723 | |
724 | /** |
725 | * FieldPosition selector for "Q" field alignment, |
726 | * corresponding to quarters. This is implemented |
727 | * using the {@link #UCAL_MONTH} field. This |
728 | * displays the quarter. |
729 | * @stable ICU 3.6 |
730 | */ |
731 | UDAT_QUARTER_FIELD = 27, |
732 | |
733 | /** |
734 | * FieldPosition selector for the "q" field alignment, |
735 | * corresponding to stand-alone quarters. This is |
736 | * implemented using the {@link #UCAL_MONTH} field. |
737 | * This displays the stand-alone quarter. |
738 | * @stable ICU 3.6 |
739 | */ |
740 | UDAT_STANDALONE_QUARTER_FIELD = 28, |
741 | |
742 | /** |
743 | * FieldPosition and UFieldPosition selector for 'V' field alignment, |
744 | * corresponding to the UCAL_ZONE_OFFSET field. |
745 | * @stable ICU 3.8 |
746 | */ |
747 | UDAT_TIMEZONE_SPECIAL_FIELD = 29, |
748 | |
749 | /** |
750 | * FieldPosition selector for "U" field alignment, |
751 | * corresponding to cyclic year names. This is implemented |
752 | * using the {@link #UCAL_YEAR} field. This displays |
753 | * the cyclic year name, if available. |
754 | * @stable ICU 49 |
755 | */ |
756 | UDAT_YEAR_NAME_FIELD = 30, |
757 | |
758 | /** |
759 | * FieldPosition selector for 'O' field alignment, |
760 | * corresponding to the UCAL_ZONE_OFFSET and UCAL_DST_OFFSETfields. |
761 | * This displays the localized GMT format. |
762 | * @stable ICU 51 |
763 | */ |
764 | UDAT_TIMEZONE_LOCALIZED_GMT_OFFSET_FIELD = 31, |
765 | |
766 | /** |
767 | * FieldPosition selector for 'X' field alignment, |
768 | * corresponding to the UCAL_ZONE_OFFSET and UCAL_DST_OFFSETfields. |
769 | * This displays the ISO 8601 local time offset format or UTC indicator ("Z"). |
770 | * @stable ICU 51 |
771 | */ |
772 | UDAT_TIMEZONE_ISO_FIELD = 32, |
773 | |
774 | /** |
775 | * FieldPosition selector for 'x' field alignment, |
776 | * corresponding to the UCAL_ZONE_OFFSET and UCAL_DST_OFFSET fields. |
777 | * This displays the ISO 8601 local time offset format. |
778 | * @stable ICU 51 |
779 | */ |
780 | UDAT_TIMEZONE_ISO_LOCAL_FIELD = 33, |
781 | |
782 | #ifndef U_HIDE_INTERNAL_API |
783 | /** |
784 | * FieldPosition and UFieldPosition selector for 'r' field alignment, |
785 | * no directly corresponding UCAL_ field. |
786 | * @internal ICU 53 |
787 | */ |
788 | UDAT_RELATED_YEAR_FIELD = 34, |
789 | #endif /* U_HIDE_INTERNAL_API */ |
790 | |
791 | /** |
792 | * FieldPosition selector for 'b' field alignment. |
793 | * Displays midnight and noon for 12am and 12pm, respectively, if available; |
794 | * otherwise fall back to AM / PM. |
795 | * @stable ICU 57 |
796 | */ |
797 | UDAT_AM_PM_MIDNIGHT_NOON_FIELD = 35, |
798 | |
799 | /* FieldPosition selector for 'B' field alignment. |
800 | * Displays flexible day periods, such as "in the morning", if available. |
801 | * @stable ICU 57 |
802 | */ |
803 | UDAT_FLEXIBLE_DAY_PERIOD_FIELD = 36, |
804 | |
805 | #ifndef U_HIDE_INTERNAL_API |
806 | /** |
807 | * FieldPosition and UFieldPosition selector for time separator, |
808 | * no corresponding UCAL_ field. No pattern character is currently |
809 | * defined for this. |
810 | * @internal |
811 | */ |
812 | UDAT_TIME_SEPARATOR_FIELD = 37, |
813 | #endif /* U_HIDE_INTERNAL_API */ |
814 | |
815 | #ifndef U_HIDE_DEPRECATED_API |
816 | /** |
817 | * Number of FieldPosition and UFieldPosition selectors for |
818 | * DateFormat and UDateFormat. |
819 | * Valid selectors range from 0 to UDAT_FIELD_COUNT-1. |
820 | * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420. |
821 | */ |
822 | UDAT_FIELD_COUNT = 38 |
823 | #endif /* U_HIDE_DEPRECATED_API */ |
824 | } UDateFormatField; |
825 | |
826 | |
827 | #ifndef U_HIDE_INTERNAL_API |
828 | /** |
829 | * Is a pattern character defined for UDAT_TIME_SEPARATOR_FIELD? |
830 | * In ICU 55 it was COLON, but that was withdrawn in ICU 56. |
831 | * @internal ICU 56 |
832 | */ |
833 | #define UDAT_HAS_PATTERN_CHAR_FOR_TIME_SEPARATOR 0 |
834 | #endif /* U_HIDE_INTERNAL_API */ |
835 | |
836 | |
837 | /** |
838 | * Maps from a UDateFormatField to the corresponding UCalendarDateFields. |
839 | * |
840 | * Note 1: Since the mapping is many-to-one, there is no inverse mapping. |
841 | * |
842 | * Note 2: There is no UErrorCode parameter, so in case of error (UDateFormatField is |
843 | * unknown or has no corresponding UCalendarDateFields value), the function returns the |
844 | * current value of UCAL_FIELD_COUNT. However, that value may change from release to |
845 | * release and is consequently deprecated. For a future-proof runtime way of checking |
846 | * for errors: |
847 | * a) First save the value returned by the function when it is passed an invalid value |
848 | * such as "(UDateFormatField)-1". |
849 | * b) Then, to test for errors when passing some other UDateFormatField value, check |
850 | * whether the function returns that saved value. |
851 | * |
852 | * @param field the UDateFormatField. |
853 | * @return the UCalendarDateField. In case of error (UDateFormatField is unknown or has |
854 | * no corresponding UCalendarDateFields value) this will be the current value of |
855 | * UCAL_FIELD_COUNT, but that value may change from release to release. |
856 | * See Note 2 above. |
857 | * @stable ICU 4.4 |
858 | */ |
859 | U_CAPI UCalendarDateFields U_EXPORT2 |
860 | udat_toCalendarDateField(UDateFormatField field); |
861 | |
862 | |
863 | /** |
864 | * Open a new UDateFormat for formatting and parsing dates and times. |
865 | * A UDateFormat may be used to format dates in calls to {@link #udat_format }, |
866 | * and to parse dates in calls to {@link #udat_parse }. |
867 | * @param timeStyle The style used to format times; one of UDAT_FULL, UDAT_LONG, |
868 | * UDAT_MEDIUM, UDAT_SHORT, UDAT_DEFAULT, or UDAT_NONE (relative time styles |
869 | * are not currently supported). |
870 | * When the pattern parameter is used, pass in UDAT_PATTERN for both timeStyle and dateStyle. |
871 | * @param dateStyle The style used to format dates; one of UDAT_FULL, UDAT_LONG, |
872 | * UDAT_MEDIUM, UDAT_SHORT, UDAT_DEFAULT, UDAT_FULL_RELATIVE, UDAT_LONG_RELATIVE, |
873 | * UDAT_MEDIUM_RELATIVE, UDAT_SHORT_RELATIVE, or UDAT_NONE. |
874 | * When the pattern parameter is used, pass in UDAT_PATTERN for both timeStyle and dateStyle. |
875 | * As currently implemented, |
876 | * relative date formatting only affects a limited range of calendar days before or |
877 | * after the current date, based on the CLDR <field type="day">/<relative> data: For |
878 | * example, in English, "Yesterday", "Today", and "Tomorrow". Outside of this range, |
879 | * dates are formatted using the corresponding non-relative style. |
880 | * @param locale The locale specifying the formatting conventions |
881 | * @param tzID A timezone ID specifying the timezone to use. If 0, use |
882 | * the default timezone. |
883 | * @param tzIDLength The length of tzID, or -1 if null-terminated. |
884 | * @param pattern A pattern specifying the format to use. |
885 | * @param patternLength The number of characters in the pattern, or -1 if null-terminated. |
886 | * @param status A pointer to an UErrorCode to receive any errors |
887 | * @return A pointer to a UDateFormat to use for formatting dates and times, or 0 if |
888 | * an error occurred. |
889 | * @stable ICU 2.0 |
890 | */ |
891 | U_CAPI UDateFormat* U_EXPORT2 |
892 | udat_open(UDateFormatStyle timeStyle, |
893 | UDateFormatStyle dateStyle, |
894 | const char *locale, |
895 | const UChar *tzID, |
896 | int32_t tzIDLength, |
897 | const UChar *pattern, |
898 | int32_t patternLength, |
899 | UErrorCode *status); |
900 | |
901 | |
902 | /** |
903 | * Close a UDateFormat. |
904 | * Once closed, a UDateFormat may no longer be used. |
905 | * @param format The formatter to close. |
906 | * @stable ICU 2.0 |
907 | */ |
908 | U_CAPI void U_EXPORT2 |
909 | udat_close(UDateFormat* format); |
910 | |
911 | |
912 | /** |
913 | * DateFormat boolean attributes |
914 | * |
915 | * @stable ICU 53 |
916 | */ |
917 | typedef enum UDateFormatBooleanAttribute { |
918 | /** |
919 | * indicates whether whitespace is allowed. Includes trailing dot tolerance. |
920 | * @stable ICU 53 |
921 | */ |
922 | UDAT_PARSE_ALLOW_WHITESPACE = 0, |
923 | /** |
924 | * indicates tolerance of numeric data when String data may be assumed. eg: UDAT_YEAR_NAME_FIELD, |
925 | * UDAT_STANDALONE_MONTH_FIELD, UDAT_DAY_OF_WEEK_FIELD |
926 | * @stable ICU 53 |
927 | */ |
928 | UDAT_PARSE_ALLOW_NUMERIC = 1, |
929 | /** |
930 | * indicates tolerance of a partial literal match |
931 | * e.g. accepting "--mon-02-march-2011" for a pattern of "'--: 'EEE-WW-MMMM-yyyy" |
932 | * @stable ICU 56 |
933 | */ |
934 | UDAT_PARSE_PARTIAL_LITERAL_MATCH = 2, |
935 | /** |
936 | * indicates tolerance of pattern mismatch between input data and specified format pattern. |
937 | * e.g. accepting "September" for a month pattern of MMM ("Sep") |
938 | * @stable ICU 56 |
939 | */ |
940 | UDAT_PARSE_MULTIPLE_PATTERNS_FOR_MATCH = 3, |
941 | |
942 | /* Do not conditionalize the following with #ifndef U_HIDE_DEPRECATED_API, |
943 | * it is needed for layout of DateFormat object. */ |
944 | #ifndef U_FORCE_HIDE_DEPRECATED_API |
945 | /** |
946 | * One more than the highest normal UDateFormatBooleanAttribute value. |
947 | * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420. |
948 | */ |
949 | UDAT_BOOLEAN_ATTRIBUTE_COUNT = 4 |
950 | #endif // U_FORCE_HIDE_DEPRECATED_API |
951 | } UDateFormatBooleanAttribute; |
952 | |
953 | /** |
954 | * Get a boolean attribute associated with a UDateFormat. |
955 | * An example would be a true value for a key of UDAT_PARSE_ALLOW_WHITESPACE indicating allowing whitespace leniency. |
956 | * If the formatter does not understand the attribute, -1 is returned. |
957 | * @param fmt The formatter to query. |
958 | * @param attr The attribute to query; e.g. UDAT_PARSE_ALLOW_WHITESPACE. |
959 | * @param status A pointer to an UErrorCode to receive any errors |
960 | * @return The value of attr. |
961 | * @stable ICU 53 |
962 | */ |
963 | U_CAPI UBool U_EXPORT2 |
964 | udat_getBooleanAttribute(const UDateFormat* fmt, UDateFormatBooleanAttribute attr, UErrorCode* status); |
965 | |
966 | /** |
967 | * Set a boolean attribute associated with a UDateFormat. |
968 | * An example of a boolean attribute is parse leniency control. If the formatter does not understand |
969 | * the attribute, the call is ignored. |
970 | * @param fmt The formatter to set. |
971 | * @param attr The attribute to set; one of UDAT_PARSE_ALLOW_WHITESPACE or UDAT_PARSE_ALLOW_NUMERIC |
972 | * @param newValue The new value of attr. |
973 | * @param status A pointer to an UErrorCode to receive any errors |
974 | * @stable ICU 53 |
975 | */ |
976 | U_CAPI void U_EXPORT2 |
977 | udat_setBooleanAttribute(UDateFormat *fmt, UDateFormatBooleanAttribute attr, UBool newValue, UErrorCode* status); |
978 | |
979 | /** |
980 | * Hour Cycle. |
981 | * @stable ICU 67 |
982 | */ |
983 | typedef enum UDateFormatHourCycle { |
984 | /** |
985 | * Hour in am/pm (0~11) |
986 | * @stable ICU 67 |
987 | */ |
988 | UDAT_HOUR_CYCLE_11, |
989 | |
990 | /** |
991 | * Hour in am/pm (1~12) |
992 | * @stable ICU 67 |
993 | */ |
994 | UDAT_HOUR_CYCLE_12, |
995 | |
996 | /** |
997 | * Hour in day (0~23) |
998 | * @stable ICU 67 |
999 | */ |
1000 | UDAT_HOUR_CYCLE_23, |
1001 | |
1002 | /** |
1003 | * Hour in day (1~24) |
1004 | * @stable ICU 67 |
1005 | */ |
1006 | UDAT_HOUR_CYCLE_24 |
1007 | } UDateFormatHourCycle; |
1008 | |
1009 | #if U_SHOW_CPLUSPLUS_API |
1010 | |
1011 | U_NAMESPACE_BEGIN |
1012 | |
1013 | /** |
1014 | * \class LocalUDateFormatPointer |
1015 | * "Smart pointer" class, closes a UDateFormat via udat_close(). |
1016 | * For most methods see the LocalPointerBase base class. |
1017 | * |
1018 | * @see LocalPointerBase |
1019 | * @see LocalPointer |
1020 | * @stable ICU 4.4 |
1021 | */ |
1022 | U_DEFINE_LOCAL_OPEN_POINTER(LocalUDateFormatPointer, UDateFormat, udat_close); |
1023 | |
1024 | U_NAMESPACE_END |
1025 | |
1026 | #endif |
1027 | |
1028 | /** |
1029 | * Open a copy of a UDateFormat. |
1030 | * This function performs a deep copy. |
1031 | * @param fmt The format to copy |
1032 | * @param status A pointer to an UErrorCode to receive any errors. |
1033 | * @return A pointer to a UDateFormat identical to fmt. |
1034 | * @stable ICU 2.0 |
1035 | */ |
1036 | U_CAPI UDateFormat* U_EXPORT2 |
1037 | udat_clone(const UDateFormat *fmt, |
1038 | UErrorCode *status); |
1039 | |
1040 | /** |
1041 | * Format a date using a UDateFormat. |
1042 | * The date will be formatted using the conventions specified in {@link #udat_open } |
1043 | * @param format The formatter to use |
1044 | * @param dateToFormat The date to format |
1045 | * @param result A pointer to a buffer to receive the formatted number. |
1046 | * @param resultLength The maximum size of result. |
1047 | * @param position A pointer to a UFieldPosition. On input, position->field |
1048 | * is read. On output, position->beginIndex and position->endIndex indicate |
1049 | * the beginning and ending indices of field number position->field, if such |
1050 | * a field exists. This parameter may be NULL, in which case no field |
1051 | * position data is returned. |
1052 | * @param status A pointer to an UErrorCode to receive any errors |
1053 | * @return The total buffer size needed; if greater than resultLength, the output was truncated. |
1054 | * @see udat_parse |
1055 | * @see UFieldPosition |
1056 | * @stable ICU 2.0 |
1057 | */ |
1058 | U_CAPI int32_t U_EXPORT2 |
1059 | udat_format( const UDateFormat* format, |
1060 | UDate dateToFormat, |
1061 | UChar* result, |
1062 | int32_t resultLength, |
1063 | UFieldPosition* position, |
1064 | UErrorCode* status); |
1065 | |
1066 | /** |
1067 | * Format a date using an UDateFormat. |
1068 | * The date will be formatted using the conventions specified in {@link #udat_open } |
1069 | * @param format The formatter to use |
1070 | * @param calendar The calendar to format. The calendar instance might be |
1071 | * mutated if fields are not yet fully calculated, though |
1072 | * the function won't change the logical date and time held |
1073 | * by the instance. |
1074 | * @param result A pointer to a buffer to receive the formatted number. |
1075 | * @param capacity The maximum size of result. |
1076 | * @param position A pointer to a UFieldPosition. On input, position->field |
1077 | * is read. On output, position->beginIndex and position->endIndex indicate |
1078 | * the beginning and ending indices of field number position->field, if such |
1079 | * a field exists. This parameter may be NULL, in which case no field |
1080 | * position data is returned. |
1081 | * @param status A pointer to an UErrorCode to receive any errors |
1082 | * @return The total buffer size needed; if greater than resultLength, the output was truncated. |
1083 | * @see udat_format |
1084 | * @see udat_parseCalendar |
1085 | * @see UFieldPosition |
1086 | * @stable ICU 55 |
1087 | */ |
1088 | U_CAPI int32_t U_EXPORT2 |
1089 | udat_formatCalendar( const UDateFormat* format, |
1090 | UCalendar* calendar, |
1091 | UChar* result, |
1092 | int32_t capacity, |
1093 | UFieldPosition* position, |
1094 | UErrorCode* status); |
1095 | |
1096 | /** |
1097 | * Format a date using a UDateFormat. |
1098 | * The date will be formatted using the conventions specified in {@link #udat_open} |
1099 | * @param format |
1100 | * The formatter to use |
1101 | * @param dateToFormat |
1102 | * The date to format |
1103 | * @param result |
1104 | * A pointer to a buffer to receive the formatted number. |
1105 | * @param resultLength |
1106 | * The maximum size of result. |
1107 | * @param fpositer |
1108 | * A pointer to a UFieldPositionIterator created by {@link #ufieldpositer_open} |
1109 | * (may be NULL if field position information is not needed). Any |
1110 | * iteration information already present in the UFieldPositionIterator |
1111 | * will be deleted, and the iterator will be reset to apply to the |
1112 | * fields in the formatted string created by this function call; the |
1113 | * field values provided by {@link #ufieldpositer_next} will be from the |
1114 | * UDateFormatField enum. |
1115 | * @param status |
1116 | * A pointer to a UErrorCode to receive any errors |
1117 | * @return |
1118 | * The total buffer size needed; if greater than resultLength, the output was truncated. |
1119 | * @see udat_parse |
1120 | * @see UFieldPositionIterator |
1121 | * @stable ICU 55 |
1122 | */ |
1123 | U_CAPI int32_t U_EXPORT2 |
1124 | udat_formatForFields( const UDateFormat* format, |
1125 | UDate dateToFormat, |
1126 | UChar* result, |
1127 | int32_t resultLength, |
1128 | UFieldPositionIterator* fpositer, |
1129 | UErrorCode* status); |
1130 | |
1131 | /** |
1132 | * Format a date using a UDateFormat. |
1133 | * The date will be formatted using the conventions specified in {@link #udat_open } |
1134 | * @param format |
1135 | * The formatter to use |
1136 | * @param calendar |
1137 | * The calendar to format. The calendar instance might be mutated if fields |
1138 | * are not yet fully calculated, though the function won't change the logical |
1139 | * date and time held by the instance. |
1140 | * @param result |
1141 | * A pointer to a buffer to receive the formatted number. |
1142 | * @param capacity |
1143 | * The maximum size of result. |
1144 | * @param fpositer |
1145 | * A pointer to a UFieldPositionIterator created by {@link #ufieldpositer_open} |
1146 | * (may be NULL if field position information is not needed). Any |
1147 | * iteration information already present in the UFieldPositionIterator |
1148 | * will be deleted, and the iterator will be reset to apply to the |
1149 | * fields in the formatted string created by this function call; the |
1150 | * field values provided by {@link #ufieldpositer_next} will be from the |
1151 | * UDateFormatField enum. |
1152 | * @param status |
1153 | * A pointer to a UErrorCode to receive any errors |
1154 | * @return |
1155 | * The total buffer size needed; if greater than resultLength, the output was truncated. |
1156 | * @see udat_format |
1157 | * @see udat_parseCalendar |
1158 | * @see UFieldPositionIterator |
1159 | * @stable ICU 55 |
1160 | */ |
1161 | U_CAPI int32_t U_EXPORT2 |
1162 | udat_formatCalendarForFields( const UDateFormat* format, |
1163 | UCalendar* calendar, |
1164 | UChar* result, |
1165 | int32_t capacity, |
1166 | UFieldPositionIterator* fpositer, |
1167 | UErrorCode* status); |
1168 | |
1169 | |
1170 | /** |
1171 | * Parse a string into an date/time using a UDateFormat. |
1172 | * The date will be parsed using the conventions specified in {@link #udat_open }. |
1173 | * <P> |
1174 | * Note that the normal date formats associated with some calendars - such |
1175 | * as the Chinese lunar calendar - do not specify enough fields to enable |
1176 | * dates to be parsed unambiguously. In the case of the Chinese lunar |
1177 | * calendar, while the year within the current 60-year cycle is specified, |
1178 | * the number of such cycles since the start date of the calendar (in the |
1179 | * UCAL_ERA field of the UCalendar object) is not normally part of the format, |
1180 | * and parsing may assume the wrong era. For cases such as this it is |
1181 | * recommended that clients parse using udat_parseCalendar with the UCalendar |
1182 | * passed in set to the current date, or to a date within the era/cycle that |
1183 | * should be assumed if absent in the format. |
1184 | * |
1185 | * @param format The formatter to use. |
1186 | * @param text The text to parse. |
1187 | * @param textLength The length of text, or -1 if null-terminated. |
1188 | * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which |
1189 | * to begin parsing. If not 0, on output the offset at which parsing ended. |
1190 | * @param status A pointer to an UErrorCode to receive any errors |
1191 | * @return The value of the parsed date/time |
1192 | * @see udat_format |
1193 | * @stable ICU 2.0 |
1194 | */ |
1195 | U_CAPI UDate U_EXPORT2 |
1196 | udat_parse(const UDateFormat* format, |
1197 | const UChar* text, |
1198 | int32_t textLength, |
1199 | int32_t *parsePos, |
1200 | UErrorCode *status); |
1201 | |
1202 | /** |
1203 | * Parse a string into an date/time using a UDateFormat. |
1204 | * The date will be parsed using the conventions specified in {@link #udat_open }. |
1205 | * @param format The formatter to use. |
1206 | * @param calendar A calendar set on input to the date and time to be used for |
1207 | * missing values in the date/time string being parsed, and set |
1208 | * on output to the parsed date/time. When the calendar type is |
1209 | * different from the internal calendar held by the UDateFormat |
1210 | * instance, the internal calendar will be cloned to a work |
1211 | * calendar set to the same milliseconds and time zone as this |
1212 | * calendar parameter, field values will be parsed based on the |
1213 | * work calendar, then the result (milliseconds and time zone) |
1214 | * will be set in this calendar. |
1215 | * @param text The text to parse. |
1216 | * @param textLength The length of text, or -1 if null-terminated. |
1217 | * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which |
1218 | * to begin parsing. If not 0, on output the offset at which parsing ended. |
1219 | * @param status A pointer to an UErrorCode to receive any errors |
1220 | * @see udat_format |
1221 | * @stable ICU 2.0 |
1222 | */ |
1223 | U_CAPI void U_EXPORT2 |
1224 | udat_parseCalendar(const UDateFormat* format, |
1225 | UCalendar* calendar, |
1226 | const UChar* text, |
1227 | int32_t textLength, |
1228 | int32_t *parsePos, |
1229 | UErrorCode *status); |
1230 | |
1231 | /** |
1232 | * Determine if an UDateFormat will perform lenient parsing. |
1233 | * With lenient parsing, the parser may use heuristics to interpret inputs that do not |
1234 | * precisely match the pattern. With strict parsing, inputs must match the pattern. |
1235 | * @param fmt The formatter to query |
1236 | * @return true if fmt is set to perform lenient parsing, false otherwise. |
1237 | * @see udat_setLenient |
1238 | * @stable ICU 2.0 |
1239 | */ |
1240 | U_CAPI UBool U_EXPORT2 |
1241 | udat_isLenient(const UDateFormat* fmt); |
1242 | |
1243 | /** |
1244 | * Specify whether an UDateFormat will perform lenient parsing. |
1245 | * With lenient parsing, the parser may use heuristics to interpret inputs that do not |
1246 | * precisely match the pattern. With strict parsing, inputs must match the pattern. |
1247 | * @param fmt The formatter to set |
1248 | * @param isLenient true if fmt should perform lenient parsing, false otherwise. |
1249 | * @see dat_isLenient |
1250 | * @stable ICU 2.0 |
1251 | */ |
1252 | U_CAPI void U_EXPORT2 |
1253 | udat_setLenient( UDateFormat* fmt, |
1254 | UBool isLenient); |
1255 | |
1256 | /** |
1257 | * Get the UCalendar associated with an UDateFormat. |
1258 | * A UDateFormat uses a UCalendar to convert a raw value to, for example, |
1259 | * the day of the week. |
1260 | * @param fmt The formatter to query. |
1261 | * @return A pointer to the UCalendar used by fmt. |
1262 | * @see udat_setCalendar |
1263 | * @stable ICU 2.0 |
1264 | */ |
1265 | U_CAPI const UCalendar* U_EXPORT2 |
1266 | udat_getCalendar(const UDateFormat* fmt); |
1267 | |
1268 | /** |
1269 | * Set the UCalendar associated with an UDateFormat. |
1270 | * A UDateFormat uses a UCalendar to convert a raw value to, for example, |
1271 | * the day of the week. |
1272 | * @param fmt The formatter to set. |
1273 | * @param calendarToSet A pointer to an UCalendar to be used by fmt. |
1274 | * @see udat_setCalendar |
1275 | * @stable ICU 2.0 |
1276 | */ |
1277 | U_CAPI void U_EXPORT2 |
1278 | udat_setCalendar( UDateFormat* fmt, |
1279 | const UCalendar* calendarToSet); |
1280 | |
1281 | /** |
1282 | * Get the UNumberFormat associated with an UDateFormat. |
1283 | * A UDateFormat uses a UNumberFormat to format numbers within a date, |
1284 | * for example the day number. |
1285 | * @param fmt The formatter to query. |
1286 | * @return A pointer to the UNumberFormat used by fmt to format numbers. |
1287 | * @see udat_setNumberFormat |
1288 | * @stable ICU 2.0 |
1289 | */ |
1290 | U_CAPI const UNumberFormat* U_EXPORT2 |
1291 | udat_getNumberFormat(const UDateFormat* fmt); |
1292 | |
1293 | /** |
1294 | * Get the UNumberFormat for specific field associated with an UDateFormat. |
1295 | * For example: 'y' for year and 'M' for month |
1296 | * @param fmt The formatter to query. |
1297 | * @param field the field to query |
1298 | * @return A pointer to the UNumberFormat used by fmt to format field numbers. |
1299 | * @see udat_setNumberFormatForField |
1300 | * @stable ICU 54 |
1301 | */ |
1302 | U_CAPI const UNumberFormat* U_EXPORT2 |
1303 | udat_getNumberFormatForField(const UDateFormat* fmt, UChar field); |
1304 | |
1305 | /** |
1306 | * Set the UNumberFormat for specific field associated with an UDateFormat. |
1307 | * It can be a single field like: "y"(year) or "M"(month) |
1308 | * It can be several field combined together: "yM"(year and month) |
1309 | * Note: |
1310 | * 1 symbol field is enough for multiple symbol field (so "y" will override "yy", "yyy") |
1311 | * If the field is not numeric, then override has no effect (like "MMM" will use abbreviation, not numerical field) |
1312 | * |
1313 | * @param fields the fields to set |
1314 | * @param fmt The formatter to set. |
1315 | * @param numberFormatToSet A pointer to the UNumberFormat to be used by fmt to format numbers. |
1316 | * @param status error code passed around (memory allocation or invalid fields) |
1317 | * @see udat_getNumberFormatForField |
1318 | * @stable ICU 54 |
1319 | */ |
1320 | U_CAPI void U_EXPORT2 |
1321 | udat_adoptNumberFormatForFields( UDateFormat* fmt, |
1322 | const UChar* fields, |
1323 | UNumberFormat* numberFormatToSet, |
1324 | UErrorCode* status); |
1325 | /** |
1326 | * Set the UNumberFormat associated with an UDateFormat. |
1327 | * A UDateFormat uses a UNumberFormat to format numbers within a date, |
1328 | * for example the day number. |
1329 | * This method also clears per field NumberFormat instances previously |
1330 | * set by {@see udat_setNumberFormatForField} |
1331 | * @param fmt The formatter to set. |
1332 | * @param numberFormatToSet A pointer to the UNumberFormat to be used by fmt to format numbers. |
1333 | * @see udat_getNumberFormat |
1334 | * @see udat_setNumberFormatForField |
1335 | * @stable ICU 2.0 |
1336 | */ |
1337 | U_CAPI void U_EXPORT2 |
1338 | udat_setNumberFormat( UDateFormat* fmt, |
1339 | const UNumberFormat* numberFormatToSet); |
1340 | /** |
1341 | * Adopt the UNumberFormat associated with an UDateFormat. |
1342 | * A UDateFormat uses a UNumberFormat to format numbers within a date, |
1343 | * for example the day number. |
1344 | * @param fmt The formatter to set. |
1345 | * @param numberFormatToAdopt A pointer to the UNumberFormat to be used by fmt to format numbers. |
1346 | * @see udat_getNumberFormat |
1347 | * @stable ICU 54 |
1348 | */ |
1349 | U_CAPI void U_EXPORT2 |
1350 | udat_adoptNumberFormat( UDateFormat* fmt, |
1351 | UNumberFormat* numberFormatToAdopt); |
1352 | /** |
1353 | * Get a locale for which date/time formatting patterns are available. |
1354 | * A UDateFormat in a locale returned by this function will perform the correct |
1355 | * formatting and parsing for the locale. |
1356 | * @param localeIndex The index of the desired locale. |
1357 | * @return A locale for which date/time formatting patterns are available, or 0 if none. |
1358 | * @see udat_countAvailable |
1359 | * @stable ICU 2.0 |
1360 | */ |
1361 | U_CAPI const char* U_EXPORT2 |
1362 | udat_getAvailable(int32_t localeIndex); |
1363 | |
1364 | /** |
1365 | * Determine how many locales have date/time formatting patterns available. |
1366 | * This function is most useful as determining the loop ending condition for |
1367 | * calls to {@link #udat_getAvailable }. |
1368 | * @return The number of locales for which date/time formatting patterns are available. |
1369 | * @see udat_getAvailable |
1370 | * @stable ICU 2.0 |
1371 | */ |
1372 | U_CAPI int32_t U_EXPORT2 |
1373 | udat_countAvailable(void); |
1374 | |
1375 | /** |
1376 | * Get the year relative to which all 2-digit years are interpreted. |
1377 | * For example, if the 2-digit start year is 2100, the year 99 will be |
1378 | * interpreted as 2199. |
1379 | * @param fmt The formatter to query. |
1380 | * @param status A pointer to an UErrorCode to receive any errors |
1381 | * @return The year relative to which all 2-digit years are interpreted. |
1382 | * @see udat_Set2DigitYearStart |
1383 | * @stable ICU 2.0 |
1384 | */ |
1385 | U_CAPI UDate U_EXPORT2 |
1386 | udat_get2DigitYearStart( const UDateFormat *fmt, |
1387 | UErrorCode *status); |
1388 | |
1389 | /** |
1390 | * Set the year relative to which all 2-digit years will be interpreted. |
1391 | * For example, if the 2-digit start year is 2100, the year 99 will be |
1392 | * interpreted as 2199. |
1393 | * @param fmt The formatter to set. |
1394 | * @param d The year relative to which all 2-digit years will be interpreted. |
1395 | * @param status A pointer to an UErrorCode to receive any errors |
1396 | * @see udat_Set2DigitYearStart |
1397 | * @stable ICU 2.0 |
1398 | */ |
1399 | U_CAPI void U_EXPORT2 |
1400 | udat_set2DigitYearStart( UDateFormat *fmt, |
1401 | UDate d, |
1402 | UErrorCode *status); |
1403 | |
1404 | /** |
1405 | * Extract the pattern from a UDateFormat. |
1406 | * The pattern will follow the pattern syntax rules. |
1407 | * @param fmt The formatter to query. |
1408 | * @param localized true if the pattern should be localized, false otherwise. |
1409 | * @param result A pointer to a buffer to receive the pattern. |
1410 | * @param resultLength The maximum size of result. |
1411 | * @param status A pointer to an UErrorCode to receive any errors |
1412 | * @return The total buffer size needed; if greater than resultLength, the output was truncated. |
1413 | * @see udat_applyPattern |
1414 | * @stable ICU 2.0 |
1415 | */ |
1416 | U_CAPI int32_t U_EXPORT2 |
1417 | udat_toPattern( const UDateFormat *fmt, |
1418 | UBool localized, |
1419 | UChar *result, |
1420 | int32_t resultLength, |
1421 | UErrorCode *status); |
1422 | |
1423 | /** |
1424 | * Set the pattern used by an UDateFormat. |
1425 | * The pattern should follow the pattern syntax rules. |
1426 | * @param format The formatter to set. |
1427 | * @param localized true if the pattern is localized, false otherwise. |
1428 | * @param pattern The new pattern |
1429 | * @param patternLength The length of pattern, or -1 if null-terminated. |
1430 | * @see udat_toPattern |
1431 | * @stable ICU 2.0 |
1432 | */ |
1433 | U_CAPI void U_EXPORT2 |
1434 | udat_applyPattern( UDateFormat *format, |
1435 | UBool localized, |
1436 | const UChar *pattern, |
1437 | int32_t patternLength); |
1438 | |
1439 | /** |
1440 | * The possible types of date format symbols |
1441 | * @stable ICU 2.6 |
1442 | */ |
1443 | typedef enum UDateFormatSymbolType { |
1444 | /** The era names, for example AD */ |
1445 | UDAT_ERAS, |
1446 | /** The month names, for example February */ |
1447 | UDAT_MONTHS, |
1448 | /** The short month names, for example Feb. */ |
1449 | UDAT_SHORT_MONTHS, |
1450 | /** The CLDR-style format "wide" weekday names, for example Monday */ |
1451 | UDAT_WEEKDAYS, |
1452 | /** |
1453 | * The CLDR-style format "abbreviated" (not "short") weekday names, for example "Mon." |
1454 | * For the CLDR-style format "short" weekday names, use UDAT_SHORTER_WEEKDAYS. |
1455 | */ |
1456 | UDAT_SHORT_WEEKDAYS, |
1457 | /** The AM/PM names, for example AM */ |
1458 | UDAT_AM_PMS, |
1459 | /** The localized characters */ |
1460 | UDAT_LOCALIZED_CHARS, |
1461 | /** The long era names, for example Anno Domini */ |
1462 | UDAT_ERA_NAMES, |
1463 | /** The narrow month names, for example F */ |
1464 | UDAT_NARROW_MONTHS, |
1465 | /** The CLDR-style format "narrow" weekday names, for example "M" */ |
1466 | UDAT_NARROW_WEEKDAYS, |
1467 | /** Standalone context versions of months */ |
1468 | UDAT_STANDALONE_MONTHS, |
1469 | UDAT_STANDALONE_SHORT_MONTHS, |
1470 | UDAT_STANDALONE_NARROW_MONTHS, |
1471 | /** The CLDR-style stand-alone "wide" weekday names */ |
1472 | UDAT_STANDALONE_WEEKDAYS, |
1473 | /** |
1474 | * The CLDR-style stand-alone "abbreviated" (not "short") weekday names. |
1475 | * For the CLDR-style stand-alone "short" weekday names, use UDAT_STANDALONE_SHORTER_WEEKDAYS. |
1476 | */ |
1477 | UDAT_STANDALONE_SHORT_WEEKDAYS, |
1478 | /** The CLDR-style stand-alone "narrow" weekday names */ |
1479 | UDAT_STANDALONE_NARROW_WEEKDAYS, |
1480 | /** The quarters, for example 1st Quarter */ |
1481 | UDAT_QUARTERS, |
1482 | /** The short quarter names, for example Q1 */ |
1483 | UDAT_SHORT_QUARTERS, |
1484 | /** Standalone context versions of quarters */ |
1485 | UDAT_STANDALONE_QUARTERS, |
1486 | UDAT_STANDALONE_SHORT_QUARTERS, |
1487 | /** |
1488 | * The CLDR-style short weekday names, e.g. "Su", Mo", etc. |
1489 | * These are named "SHORTER" to contrast with the constants using _SHORT_ |
1490 | * above, which actually get the CLDR-style *abbreviated* versions of the |
1491 | * corresponding names. |
1492 | * @stable ICU 51 |
1493 | */ |
1494 | UDAT_SHORTER_WEEKDAYS, |
1495 | /** |
1496 | * Standalone version of UDAT_SHORTER_WEEKDAYS. |
1497 | * @stable ICU 51 |
1498 | */ |
1499 | UDAT_STANDALONE_SHORTER_WEEKDAYS, |
1500 | /** |
1501 | * Cyclic year names (only supported for some calendars, and only for FORMAT usage; |
1502 | * udat_setSymbols not supported for UDAT_CYCLIC_YEARS_WIDE) |
1503 | * @stable ICU 54 |
1504 | */ |
1505 | UDAT_CYCLIC_YEARS_WIDE, |
1506 | /** |
1507 | * Cyclic year names (only supported for some calendars, and only for FORMAT usage) |
1508 | * @stable ICU 54 |
1509 | */ |
1510 | UDAT_CYCLIC_YEARS_ABBREVIATED, |
1511 | /** |
1512 | * Cyclic year names (only supported for some calendars, and only for FORMAT usage; |
1513 | * udat_setSymbols not supported for UDAT_CYCLIC_YEARS_NARROW) |
1514 | * @stable ICU 54 |
1515 | */ |
1516 | UDAT_CYCLIC_YEARS_NARROW, |
1517 | /** |
1518 | * Calendar zodiac names (only supported for some calendars, and only for FORMAT usage; |
1519 | * udat_setSymbols not supported for UDAT_ZODIAC_NAMES_WIDE) |
1520 | * @stable ICU 54 |
1521 | */ |
1522 | UDAT_ZODIAC_NAMES_WIDE, |
1523 | /** |
1524 | * Calendar zodiac names (only supported for some calendars, and only for FORMAT usage) |
1525 | * @stable ICU 54 |
1526 | */ |
1527 | UDAT_ZODIAC_NAMES_ABBREVIATED, |
1528 | /** |
1529 | * Calendar zodiac names (only supported for some calendars, and only for FORMAT usage; |
1530 | * udat_setSymbols not supported for UDAT_ZODIAC_NAMES_NARROW) |
1531 | * @stable ICU 54 |
1532 | */ |
1533 | UDAT_ZODIAC_NAMES_NARROW, |
1534 | |
1535 | #ifndef U_HIDE_DRAFT_API |
1536 | /** |
1537 | * The narrow quarter names, for example 1 |
1538 | * @draft ICU 70 |
1539 | */ |
1540 | UDAT_NARROW_QUARTERS, |
1541 | |
1542 | /** |
1543 | * The narrow standalone quarter names, for example 1 |
1544 | * @draft ICU 70 |
1545 | */ |
1546 | UDAT_STANDALONE_NARROW_QUARTERS |
1547 | #endif // U_HIDE_DRAFT_API |
1548 | } UDateFormatSymbolType; |
1549 | |
1550 | struct UDateFormatSymbols; |
1551 | /** Date format symbols. |
1552 | * For usage in C programs. |
1553 | * @stable ICU 2.6 |
1554 | */ |
1555 | typedef struct UDateFormatSymbols UDateFormatSymbols; |
1556 | |
1557 | /** |
1558 | * Get the symbols associated with an UDateFormat. |
1559 | * The symbols are what a UDateFormat uses to represent locale-specific data, |
1560 | * for example month or day names. |
1561 | * @param fmt The formatter to query. |
1562 | * @param type The type of symbols to get. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS, |
1563 | * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS |
1564 | * @param symbolIndex The desired symbol of type type. |
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 an UErrorCode to receive any errors |
1568 | * @return The total buffer size needed; if greater than resultLength, the output was truncated. |
1569 | * @see udat_countSymbols |
1570 | * @see udat_setSymbols |
1571 | * @stable ICU 2.0 |
1572 | */ |
1573 | U_CAPI int32_t U_EXPORT2 |
1574 | udat_getSymbols(const UDateFormat *fmt, |
1575 | UDateFormatSymbolType type, |
1576 | int32_t symbolIndex, |
1577 | UChar *result, |
1578 | int32_t resultLength, |
1579 | UErrorCode *status); |
1580 | |
1581 | /** |
1582 | * Count the number of particular symbols for an UDateFormat. |
1583 | * This function is most useful as for determining the loop termination condition |
1584 | * for calls to {@link #udat_getSymbols }. |
1585 | * @param fmt The formatter to query. |
1586 | * @param type The type of symbols to count. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS, |
1587 | * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS |
1588 | * @return The number of symbols of type type. |
1589 | * @see udat_getSymbols |
1590 | * @see udat_setSymbols |
1591 | * @stable ICU 2.0 |
1592 | */ |
1593 | U_CAPI int32_t U_EXPORT2 |
1594 | udat_countSymbols( const UDateFormat *fmt, |
1595 | UDateFormatSymbolType type); |
1596 | |
1597 | /** |
1598 | * Set the symbols associated with an UDateFormat. |
1599 | * The symbols are what a UDateFormat uses to represent locale-specific data, |
1600 | * for example month or day names. |
1601 | * @param format The formatter to set |
1602 | * @param type The type of symbols to set. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS, |
1603 | * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS |
1604 | * @param symbolIndex The index of the symbol to set of type type. |
1605 | * @param value The new value |
1606 | * @param valueLength The length of value, or -1 if null-terminated |
1607 | * @param status A pointer to an UErrorCode to receive any errors |
1608 | * @see udat_getSymbols |
1609 | * @see udat_countSymbols |
1610 | * @stable ICU 2.0 |
1611 | */ |
1612 | U_CAPI void U_EXPORT2 |
1613 | udat_setSymbols( UDateFormat *format, |
1614 | UDateFormatSymbolType type, |
1615 | int32_t symbolIndex, |
1616 | UChar *value, |
1617 | int32_t valueLength, |
1618 | UErrorCode *status); |
1619 | |
1620 | /** |
1621 | * Get the locale for this date format object. |
1622 | * You can choose between valid and actual locale. |
1623 | * @param fmt The formatter to get the locale from |
1624 | * @param type type of the locale we're looking for (valid or actual) |
1625 | * @param status error code for the operation |
1626 | * @return the locale name |
1627 | * @stable ICU 2.8 |
1628 | */ |
1629 | U_CAPI const char* U_EXPORT2 |
1630 | udat_getLocaleByType(const UDateFormat *fmt, |
1631 | ULocDataLocaleType type, |
1632 | UErrorCode* status); |
1633 | |
1634 | /** |
1635 | * Set a particular UDisplayContext value in the formatter, such as |
1636 | * UDISPCTX_CAPITALIZATION_FOR_STANDALONE. |
1637 | * @param fmt The formatter for which to set a UDisplayContext value. |
1638 | * @param value The UDisplayContext value to set. |
1639 | * @param status A pointer to an UErrorCode to receive any errors |
1640 | * @stable ICU 51 |
1641 | */ |
1642 | U_CAPI void U_EXPORT2 |
1643 | udat_setContext(UDateFormat* fmt, UDisplayContext value, UErrorCode* status); |
1644 | |
1645 | /** |
1646 | * Get the formatter's UDisplayContext value for the specified UDisplayContextType, |
1647 | * such as UDISPCTX_TYPE_CAPITALIZATION. |
1648 | * @param fmt The formatter to query. |
1649 | * @param type The UDisplayContextType whose value to return |
1650 | * @param status A pointer to an UErrorCode to receive any errors |
1651 | * @return The UDisplayContextValue for the specified type. |
1652 | * @stable ICU 53 |
1653 | */ |
1654 | U_CAPI UDisplayContext U_EXPORT2 |
1655 | udat_getContext(const UDateFormat* fmt, UDisplayContextType type, UErrorCode* status); |
1656 | |
1657 | #ifndef U_HIDE_INTERNAL_API |
1658 | /** |
1659 | * Extract the date pattern from a UDateFormat set for relative date formatting. |
1660 | * The pattern will follow the pattern syntax rules. |
1661 | * @param fmt The formatter to query. |
1662 | * @param result A pointer to a buffer to receive the pattern. |
1663 | * @param resultLength The maximum size of result. |
1664 | * @param status A pointer to a UErrorCode to receive any errors |
1665 | * @return The total buffer size needed; if greater than resultLength, the output was truncated. |
1666 | * @see udat_applyPatternRelative |
1667 | * @internal ICU 4.2 technology preview |
1668 | */ |
1669 | U_CAPI int32_t U_EXPORT2 |
1670 | udat_toPatternRelativeDate(const UDateFormat *fmt, |
1671 | UChar *result, |
1672 | int32_t resultLength, |
1673 | UErrorCode *status); |
1674 | |
1675 | /** |
1676 | * Extract the time pattern from a UDateFormat set for relative date formatting. |
1677 | * The pattern will follow the pattern syntax rules. |
1678 | * @param fmt The formatter to query. |
1679 | * @param result A pointer to a buffer to receive the pattern. |
1680 | * @param resultLength The maximum size of result. |
1681 | * @param status A pointer to a UErrorCode to receive any errors |
1682 | * @return The total buffer size needed; if greater than resultLength, the output was truncated. |
1683 | * @see udat_applyPatternRelative |
1684 | * @internal ICU 4.2 technology preview |
1685 | */ |
1686 | U_CAPI int32_t U_EXPORT2 |
1687 | udat_toPatternRelativeTime(const UDateFormat *fmt, |
1688 | UChar *result, |
1689 | int32_t resultLength, |
1690 | UErrorCode *status); |
1691 | |
1692 | /** |
1693 | * Set the date & time patterns used by a UDateFormat set for relative date formatting. |
1694 | * The patterns should follow the pattern syntax rules. |
1695 | * @param format The formatter to set. |
1696 | * @param datePattern The new date pattern |
1697 | * @param datePatternLength The length of datePattern, or -1 if null-terminated. |
1698 | * @param timePattern The new time pattern |
1699 | * @param timePatternLength The length of timePattern, or -1 if null-terminated. |
1700 | * @param status A pointer to a UErrorCode to receive any errors |
1701 | * @see udat_toPatternRelativeDate, udat_toPatternRelativeTime |
1702 | * @internal ICU 4.2 technology preview |
1703 | */ |
1704 | U_CAPI void U_EXPORT2 |
1705 | udat_applyPatternRelative(UDateFormat *format, |
1706 | const UChar *datePattern, |
1707 | int32_t datePatternLength, |
1708 | const UChar *timePattern, |
1709 | int32_t timePatternLength, |
1710 | UErrorCode *status); |
1711 | |
1712 | /** |
1713 | * @internal |
1714 | * @see udat_open |
1715 | */ |
1716 | typedef UDateFormat* (U_EXPORT2 *UDateFormatOpener) (UDateFormatStyle timeStyle, |
1717 | UDateFormatStyle dateStyle, |
1718 | const char *locale, |
1719 | const UChar *tzID, |
1720 | int32_t tzIDLength, |
1721 | const UChar *pattern, |
1722 | int32_t patternLength, |
1723 | UErrorCode *status); |
1724 | |
1725 | /** |
1726 | * Register a provider factory |
1727 | * @internal ICU 49 |
1728 | */ |
1729 | U_CAPI void U_EXPORT2 |
1730 | udat_registerOpener(UDateFormatOpener opener, UErrorCode *status); |
1731 | |
1732 | /** |
1733 | * Un-Register a provider factory |
1734 | * @internal ICU 49 |
1735 | */ |
1736 | U_CAPI UDateFormatOpener U_EXPORT2 |
1737 | udat_unregisterOpener(UDateFormatOpener opener, UErrorCode *status); |
1738 | #endif /* U_HIDE_INTERNAL_API */ |
1739 | |
1740 | |
1741 | #endif /* #if !UCONFIG_NO_FORMATTING */ |
1742 | |
1743 | #endif |
1744 | |