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