ICU 50.1.2  50.1.2
udat.h
Go to the documentation of this file.
1 /*
2  *******************************************************************************
3  * Copyright (C) 1996-2012, International Business Machines
4  * Corporation and others. All Rights Reserved.
5  *******************************************************************************
6 */
7 
8 #ifndef UDAT_H
9 #define UDAT_H
10 
11 #include "unicode/utypes.h"
12 
13 #if !UCONFIG_NO_FORMATTING
14 
15 #include "unicode/localpointer.h"
16 #include "unicode/ucal.h"
17 #include "unicode/unum.h"
18 #include "unicode/udisplaycontext.h"
140 typedef void* UDateFormat;
141 
145 typedef enum UDateFormatStyle {
156 
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 
170  UDAT_NONE = -1,
171 
178 
182 
183 // Skeletons for dates.
184 
189 #define UDAT_YEAR "y"
190 
194 #define UDAT_QUARTER "QQQQ"
195 
199 #define UDAT_ABBR_QUARTER "QQQ"
200 
204 #define UDAT_YEAR_QUARTER "yQQQQ"
205 
209 #define UDAT_YEAR_ABBR_QUARTER "yQQQ"
210 
214 #define UDAT_MONTH "MMMM"
215 
219 #define UDAT_ABBR_MONTH "MMM"
220 
224 #define UDAT_NUM_MONTH "M"
225 
229 #define UDAT_YEAR_MONTH "yMMMM"
230 
234 #define UDAT_YEAR_ABBR_MONTH "yMMM"
235 
239 #define UDAT_YEAR_NUM_MONTH "yM"
240 
244 #define UDAT_DAY "d"
245 
250 #define UDAT_YEAR_MONTH_DAY "yMMMMd"
251 
256 #define UDAT_YEAR_ABBR_MONTH_DAY "yMMMd"
257 
262 #define UDAT_YEAR_NUM_MONTH_DAY "yMd"
263 
267 #define UDAT_WEEKDAY "EEEE"
268 
272 #define UDAT_ABBR_WEEKDAY "E"
273 
278 #define UDAT_YEAR_MONTH_WEEKDAY_DAY "yMMMMEEEEd"
279 
284 #define UDAT_YEAR_ABBR_MONTH_WEEKDAY_DAY "yMMMEd"
285 
290 #define UDAT_YEAR_NUM_MONTH_WEEKDAY_DAY "yMEd"
291 
296 #define UDAT_MONTH_DAY "MMMMd"
297 
302 #define UDAT_ABBR_MONTH_DAY "MMMd"
303 
308 #define UDAT_NUM_MONTH_DAY "Md"
309 
314 #define UDAT_MONTH_WEEKDAY_DAY "MMMMEEEEd"
315 
320 #define UDAT_ABBR_MONTH_WEEKDAY_DAY "MMMEd"
321 
326 #define UDAT_NUM_MONTH_WEEKDAY_DAY "MEd"
327 
328 // Skeletons for times.
329 
334 #define UDAT_HOUR "j"
335 
339 #define UDAT_HOUR24 "H"
340 
344 #define UDAT_MINUTE "m"
345 
350 #define UDAT_HOUR_MINUTE "jm"
351 
356 #define UDAT_HOUR24_MINUTE "Hm"
357 
361 #define UDAT_SECOND "s"
362 
368 #define UDAT_HOUR_MINUTE_SECOND "jms"
369 
375 #define UDAT_HOUR24_MINUTE_SECOND "Hms"
376 
381 #define UDAT_MINUTE_SECOND "ms"
382 
383 // Skeletons for time zones.
384 
392 #define UDAT_LOCATION_TZ "VVVV"
393 
400 #define UDAT_GENERIC_TZ "vvvv"
401 
408 #define UDAT_ABBR_GENERIC_TZ "v"
409 
416 #define UDAT_SPECIFIC_TZ "zzzz"
417 
424 #define UDAT_ABBR_SPECIFIC_TZ "z"
425 
432 #define UDAT_ABBR_UTC_TZ "ZZZZ"
433 
434 // deprecated skeleton constants
435 
440 #define UDAT_STANDALONE_MONTH "LLLL"
441 
445 #define UDAT_ABBR_STANDALONE_MONTH "LLL"
446 
451 #define UDAT_HOUR_MINUTE_GENERIC_TZ "jmv"
452 
456 #define UDAT_HOUR_MINUTE_TZ "jmz"
457 
461 #define UDAT_HOUR_GENERIC_TZ "jv"
462 
466 #define UDAT_HOUR_TZ "jz"
467 
473 typedef enum UDateFormatField {
480 
487 
494 
501 
510 
519 
526 
533 
548 
555 
562 
569 
576 
583 
590 
599 
608 
616 
623 
630 
637 
644 
651 
659 
673 
681 
690 
699 
706 
715 
725 
727 
728 
739 
740 
769 U_STABLE UDateFormat* U_EXPORT2
770 udat_open(UDateFormatStyle timeStyle,
771  UDateFormatStyle dateStyle,
772  const char *locale,
773  const UChar *tzID,
774  int32_t tzIDLength,
775  const UChar *pattern,
776  int32_t patternLength,
777  UErrorCode *status);
778 
779 
786 U_STABLE void U_EXPORT2
787 udat_close(UDateFormat* format);
788 
789 #if U_SHOW_CPLUSPLUS_API
790 
792 
803 
805 
806 #endif
807 
816 U_STABLE UDateFormat* U_EXPORT2
817 udat_clone(const UDateFormat *fmt,
818  UErrorCode *status);
819 
838 U_STABLE int32_t U_EXPORT2
839 udat_format( const UDateFormat* format,
840  UDate dateToFormat,
841  UChar* result,
842  int32_t resultLength,
843  UFieldPosition* position,
844  UErrorCode* status);
845 
871 U_STABLE UDate U_EXPORT2
872 udat_parse(const UDateFormat* format,
873  const UChar* text,
874  int32_t textLength,
875  int32_t *parsePos,
876  UErrorCode *status);
877 
899 U_STABLE void U_EXPORT2
900 udat_parseCalendar(const UDateFormat* format,
901  UCalendar* calendar,
902  const UChar* text,
903  int32_t textLength,
904  int32_t *parsePos,
905  UErrorCode *status);
906 
916 U_STABLE UBool U_EXPORT2
917 udat_isLenient(const UDateFormat* fmt);
918 
928 U_STABLE void U_EXPORT2
930  UBool isLenient);
931 
941 U_STABLE const UCalendar* U_EXPORT2
942 udat_getCalendar(const UDateFormat* fmt);
943 
953 U_STABLE void U_EXPORT2
955  const UCalendar* calendarToSet);
956 
966 U_STABLE const UNumberFormat* U_EXPORT2
968 
978 U_STABLE void U_EXPORT2
980  const UNumberFormat* numberFormatToSet);
981 
991 U_STABLE const char* U_EXPORT2
992 udat_getAvailable(int32_t localeIndex);
993 
1002 U_STABLE int32_t U_EXPORT2
1003 udat_countAvailable(void);
1004 
1015 U_STABLE UDate U_EXPORT2
1017  UErrorCode *status);
1018 
1029 U_STABLE void U_EXPORT2
1031  UDate d,
1032  UErrorCode *status);
1033 
1046 U_STABLE int32_t U_EXPORT2
1047 udat_toPattern( const UDateFormat *fmt,
1048  UBool localized,
1049  UChar *result,
1050  int32_t resultLength,
1051  UErrorCode *status);
1052 
1063 U_STABLE void U_EXPORT2
1065  UBool localized,
1066  const UChar *pattern,
1067  int32_t patternLength);
1068 
1096  UDAT_STANDALONE_SHORT_MONTHS,
1097  UDAT_STANDALONE_NARROW_MONTHS,
1100  UDAT_STANDALONE_SHORT_WEEKDAYS,
1101  UDAT_STANDALONE_NARROW_WEEKDAYS,
1108  UDAT_STANDALONE_SHORT_QUARTERS
1109 
1111 
1112 struct UDateFormatSymbols;
1118 
1135 U_STABLE int32_t U_EXPORT2
1136 udat_getSymbols(const UDateFormat *fmt,
1137  UDateFormatSymbolType type,
1138  int32_t symbolIndex,
1139  UChar *result,
1140  int32_t resultLength,
1141  UErrorCode *status);
1142 
1155 U_STABLE int32_t U_EXPORT2
1156 udat_countSymbols( const UDateFormat *fmt,
1157  UDateFormatSymbolType type);
1158 
1174 U_STABLE void U_EXPORT2
1175 udat_setSymbols( UDateFormat *format,
1176  UDateFormatSymbolType type,
1177  int32_t symbolIndex,
1178  UChar *value,
1179  int32_t valueLength,
1180  UErrorCode *status);
1181 
1191 U_STABLE const char* U_EXPORT2
1193  ULocDataLocaleType type,
1194  UErrorCode* status);
1195 
1196 #ifndef U_HIDE_INTERNAL_API
1197 
1205 U_INTERNAL void U_EXPORT2
1206 udat_setContext(UDateFormat* fmt, UDisplayContext value, UErrorCode* status);
1207 
1217 U_INTERNAL UDisplayContext U_EXPORT2
1218 udat_getContext(UDateFormat* fmt, UDisplayContextType type, UErrorCode* status);
1219 
1220 #endif /* U_HIDE_INTERNAL_API */
1221 
1222 #ifndef U_HIDE_INTERNAL_API
1223 
1234 U_INTERNAL int32_t U_EXPORT2
1236  UChar *result,
1237  int32_t resultLength,
1238  UErrorCode *status);
1239 
1251 U_INTERNAL int32_t U_EXPORT2
1253  UChar *result,
1254  int32_t resultLength,
1255  UErrorCode *status);
1256 
1269 U_INTERNAL void U_EXPORT2
1271  const UChar *datePattern,
1272  int32_t datePatternLength,
1273  const UChar *timePattern,
1274  int32_t timePatternLength,
1275  UErrorCode *status);
1276 #endif /* U_HIDE_INTERNAL_API */
1277 
1282 typedef UDateFormat* (U_EXPORT2 *UDateFormatOpener) (UDateFormatStyle timeStyle,
1283  UDateFormatStyle dateStyle,
1284  const char *locale,
1285  const UChar *tzID,
1286  int32_t tzIDLength,
1287  const UChar *pattern,
1288  int32_t patternLength,
1289  UErrorCode *status);
1290 
1295 U_INTERNAL void U_EXPORT2
1297 
1302 U_INTERNAL UDateFormatOpener U_EXPORT2
1304 
1305 
1306 #endif /* #if !UCONFIG_NO_FORMATTING */
1307 
1308 #endif
int32_t udat_format(const UDateFormat *format, UDate dateToFormat, UChar *result, int32_t resultLength, UFieldPosition *position, UErrorCode *status)
Format a date using an UDateFormat.
void * UCalendar
A calendar.
Definition: ucal.h:153
FieldPosition and UFieldPosition selector for &#39;w&#39; field alignment, corresponding to the UCAL_WEEK_OF_...
Definition: udat.h:575
FieldPosition and UFieldPosition selector for &#39;e&#39; field alignment, corresponding to the UCAL_DOW_LOCA...
Definition: udat.h:629
Standalone context versions of months.
Definition: udat.h:1095
UCalendarDateFields
Possible fields in a UCalendar.
Definition: ucal.h:183
UDisplayContext udat_getContext(UDateFormat *fmt, UDisplayContextType type, UErrorCode *status)
Get the formatter&#39;s UDisplayContext value for the specified UDisplayContextType, such as UDISPCTX_TYP...
UBool udat_isLenient(const UDateFormat *fmt)
Determine if an UDateFormat will perform lenient parsing.
The localized characters.
Definition: udat.h:1087
FieldPosition and UFieldPosition selector for &#39;V&#39; field alignment, corresponding to the UCAL_ZONE_OFF...
Definition: udat.h:705
The narrow weekday names, for example N.
Definition: udat.h:1093
FieldPosition selector for &quot;Q&quot; field alignment, corresponding to quarters.
Definition: udat.h:689
C API: Calendar.
FieldPosition and UFieldPosition selector for &#39;M&#39; field alignment, corresponding to the UCAL_MONTH fi...
Definition: udat.h:493
FieldPosition and UFieldPosition selector for &#39;k&#39; field alignment, corresponding to the UCAL_HOUR_OF_...
Definition: udat.h:509
const char * udat_getLocaleByType(const UDateFormat *fmt, ULocDataLocaleType type, UErrorCode *status)
Get the locale for this date format object.
The long era names, for example Anno Domini.
Definition: udat.h:1089
void udat_applyPatternRelative(UDateFormat *format, const UChar *datePattern, int32_t datePatternLength, const UChar *timePattern, int32_t timePatternLength, UErrorCode *status)
Set the date &amp; time patterns used by a UDateFormat set for relative date formatting.
Short style.
Definition: udat.h:153
The quarters, for example 1st Quarter.
Definition: udat.h:1103
void udat_registerOpener(UDateFormatOpener opener, UErrorCode *status)
Register a provider factory.
double UDate
Date and Time data type.
Definition: utypes.h:201
No style.
Definition: udat.h:170
Standalone context versions of weekdays.
Definition: udat.h:1099
Long style.
Definition: udat.h:149
void udat_setCalendar(UDateFormat *fmt, const UCalendar *calendarToSet)
Set the UCalendar associated with an UDateFormat.
The short month names, for example Feb.
Definition: udat.h:1079
#define U_INTERNAL
This is used to declare a function as an internal ICU C API.
Definition: umachine.h:117
Use the pattern given in the parameter to udat_open.
Definition: udat.h:177
Default style.
Definition: udat.h:155
const UNumberFormat * udat_getNumberFormat(const UDateFormat *fmt)
Get the UNumberFormat associated with an UDateFormat.
void udat_setLenient(UDateFormat *fmt, UBool isLenient)
Specify whether an UDateFormat will perform lenient parsing.
FieldPosition and UFieldPosition selector for &#39;g&#39; field alignment, corresponding to the UCAL_JULIAN_D...
Definition: udat.h:643
const UCalendar * udat_getCalendar(const UDateFormat *fmt)
Get the UCalendar associated with an UDateFormat.
Bitfield for relative date.
Definition: udat.h:158
FieldPosition and UFieldPosition selector for &#39;D&#39; field alignment, corresponding to the UCAL_DAY_OF_Y...
Definition: udat.h:561
FieldPosition selector for the &quot;q&quot; field alignment, corresponding to stand-alone quarters.
Definition: udat.h:698
FieldPosition and UFieldPosition selector for &#39;u&#39; field alignment, corresponding to the UCAL_EXTENDED...
Definition: udat.h:636
void udat_setSymbols(UDateFormat *format, UDateFormatSymbolType type, int32_t symbolIndex, UChar *value, int32_t valueLength, UErrorCode *status)
Set the symbols associated with an UDateFormat.
void udat_setNumberFormat(UDateFormat *fmt, const UNumberFormat *numberFormatToSet)
Set the UNumberFormat associated with an UDateFormat.
void udat_setContext(UDateFormat *fmt, UDisplayContext value, UErrorCode *status)
Set a particular UDisplayContext value in the formatter, such as UDISPCTX_CAPITALIZATION_FOR_STANDALO...
FieldPosition selector for &#39;c&#39; field alignment, corresponding to the UCAL_DOW_LOCAL field...
Definition: udat.h:672
FieldPosition and UFieldPosition selector for &#39;d&#39; field alignment, corresponding to the UCAL_DATE fie...
Definition: udat.h:500
void udat_close(UDateFormat *format)
Close a UDateFormat.
Full style.
Definition: udat.h:147
FieldPosition and UFieldPosition selector for &#39;Y&#39; field alignment, corresponding to the UCAL_YEAR_WOY...
Definition: udat.h:622
void udat_set2DigitYearStart(UDateFormat *fmt, UDate d, UErrorCode *status)
Set the year relative to which all 2-digit years will be interpreted.
#define U_NAMESPACE_BEGIN
This is used to begin a declaration of a public ICU C++ API.
Definition: uversion.h:129
FieldPosition and UFieldPosition selector for &#39;F&#39; field alignment, corresponding to the UCAL_DAY_OF_W...
Definition: udat.h:568
UDateFormatSymbolType
The possible types of date format symbols.
Definition: udat.h:1073
The month names, for example February.
Definition: udat.h:1077
#define U_DEFINE_LOCAL_OPEN_POINTER(LocalPointerClassName, Type, closeFunction)
&quot;Smart pointer&quot; definition macro, deletes objects via the closeFunction.
Definition: localpointer.h:290
void * UNumberFormat
A number formatter.
Definition: unum.h:130
A struct representing a range of text containing a specific field.
Definition: umisc.h:32
FieldPosition and UFieldPosition selector for &#39;A&#39; field alignment, corresponding to the UCAL_MILLISEC...
Definition: udat.h:650
C++ API: &quot;Smart pointers&quot; for use with and in ICU4C C++ code.
void * UDateFormat
A date formatter.
Definition: udat.h:140
int32_t udat_toPatternRelativeDate(const UDateFormat *fmt, UChar *result, int32_t resultLength, UErrorCode *status)
Extract the date pattern from a UDateFormat set for relative date formatting.
FieldPosition and UFieldPosition selector for &#39;v&#39; field alignment, corresponding to the UCAL_ZONE_OFF...
Definition: udat.h:665
The era names, for example AD.
Definition: udat.h:1075
FieldPosition and UFieldPosition selector for &#39;W&#39; field alignment, corresponding to the UCAL_WEEK_OF_...
Definition: udat.h:582
The weekday names, for example Monday.
Definition: udat.h:1081
UCalendarDateFields udat_toCalendarDateField(UDateFormatField field)
Maps from a UDateFormatField to the corresponding UCalendarDateFields.
struct UDateFormatSymbols UDateFormatSymbols
Date format symbols.
Definition: udat.h:1117
UDateFormatStyle
The possible date/time format styles.
Definition: udat.h:145
UDate udat_parse(const UDateFormat *format, const UChar *text, int32_t textLength, int32_t *parsePos, UErrorCode *status)
Parse a string into an date/time using a UDateFormat.
UDateFormat * udat_open(UDateFormatStyle timeStyle, UDateFormatStyle dateStyle, const char *locale, const UChar *tzID, int32_t tzIDLength, const UChar *pattern, int32_t patternLength, UErrorCode *status)
Open a new UDateFormat for formatting and parsing dates and times.
void udat_applyPattern(UDateFormat *format, UBool localized, const UChar *pattern, int32_t patternLength)
Set the pattern used by an UDateFormat.
FieldPosition and UFieldPosition selector for &#39;E&#39; field alignment, corresponding to the UCAL_DAY_OF_W...
Definition: udat.h:554
int32_t udat_toPattern(const UDateFormat *fmt, UBool localized, UChar *result, int32_t resultLength, UErrorCode *status)
Extract the pattern from a UDateFormat.
FieldPosition and UFieldPosition selector for &#39;a&#39; field alignment, corresponding to the UCAL_AM_PM fi...
Definition: udat.h:589
&quot;Smart pointer&quot; class, closes a UDateFormat via udat_close().
The short quarter names, for example Q1.
Definition: udat.h:1105
FieldPosition and UFieldPosition selector for &#39;K&#39; field alignment, corresponding to the UCAL_HOUR fie...
Definition: udat.h:607
const char * udat_getAvailable(int32_t localeIndex)
Get a locale for which date/time formatting patterns are available.
int32_t udat_getSymbols(const UDateFormat *fmt, UDateFormatSymbolType type, int32_t symbolIndex, UChar *result, int32_t resultLength, UErrorCode *status)
Get the symbols associated with an UDateFormat.
uint16_t UChar
Define UChar to be UCHAR_TYPE, if that is #defined (for example, to char16_t), or wchar_t if that is ...
Definition: umachine.h:278
#define U_NAMESPACE_END
This is used to end a declaration of a public ICU C++ API.
Definition: uversion.h:130
Standalone context versions of quarters.
Definition: udat.h:1107
UDateFormatField
FieldPosition and UFieldPosition selectors for format fields defined by DateFormat and UDateFormat...
Definition: udat.h:473
FieldPosition and UFieldPosition selector for &#39;G&#39; field alignment, corresponding to the UCAL_ERA fiel...
Definition: udat.h:479
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:476
UDateFormat * udat_clone(const UDateFormat *fmt, UErrorCode *status)
Open a copy of a UDateFormat.
ULocDataLocaleType
Constants for *_getLocale() Allow user to select whether she wants information on requested...
Definition: uloc.h:336
FieldPosition and UFieldPosition selector for &#39;m&#39; field alignment, corresponding to the UCAL_MINUTE f...
Definition: udat.h:525
int32_t udat_countSymbols(const UDateFormat *fmt, UDateFormatSymbolType type)
Count the number of particular symbols for an UDateFormat.
The narrow month names, for example F.
Definition: udat.h:1091
FieldPosition and UFieldPosition selector for &#39;s&#39; field alignment, corresponding to the UCAL_SECOND f...
Definition: udat.h:532
Basic definitions for ICU, for both C and C++ APIs.
The short weekday names, for example Mon.
Definition: udat.h:1083
FieldPosition and UFieldPosition selector for &#39;z&#39; field alignment, corresponding to the UCAL_ZONE_OFF...
Definition: udat.h:615
FieldPosition and UFieldPosition selector for &#39;y&#39; field alignment, corresponding to the UCAL_YEAR fie...
Definition: udat.h:486
FieldPosition selector for &#39;L&#39; field alignment, corresponding to the UCAL_MONTH field.
Definition: udat.h:680
The AM/PM names, for example AM.
Definition: udat.h:1085
Number of FieldPosition and UFieldPosition selectors for DateFormat and UDateFormat.
Definition: udat.h:724
int32_t udat_toPatternRelativeTime(const UDateFormat *fmt, UChar *result, int32_t resultLength, UErrorCode *status)
Extract the time pattern from a UDateFormat set for relative date formatting.
FieldPosition and UFieldPosition selector for &#39;Z&#39; field alignment, corresponding to the UCAL_ZONE_OFF...
Definition: udat.h:658
UDate udat_get2DigitYearStart(const UDateFormat *fmt, UErrorCode *status)
Get the year relative to which all 2-digit years are interpreted.
int32_t udat_countAvailable(void)
Determine how many locales have date/time formatting patterns available.
FieldPosition and UFieldPosition selector for &#39;H&#39; field alignment, corresponding to the UCAL_HOUR_OF_...
Definition: udat.h:518
FieldPosition and UFieldPosition selector for &#39;S&#39; field alignment, corresponding to the UCAL_MILLISEC...
Definition: udat.h:547
FieldPosition and UFieldPosition selector for &#39;h&#39; field alignment, corresponding to the UCAL_HOUR fie...
Definition: udat.h:598
UDateFormatOpener udat_unregisterOpener(UDateFormatOpener opener, UErrorCode *status)
Un-Register a provider factory.
UDateFormat *(* UDateFormatOpener)(UDateFormatStyle timeStyle, UDateFormatStyle dateStyle, const char *locale, const UChar *tzID, int32_t tzIDLength, const UChar *pattern, int32_t patternLength, UErrorCode *status)
Definition: udat.h:1282
FieldPosition selector for &quot;U&quot; field alignment, corresponding to cyclic year names.
Definition: udat.h:714
void udat_parseCalendar(const UDateFormat *format, UCalendar *calendar, const UChar *text, int32_t textLength, int32_t *parsePos, UErrorCode *status)
Parse a string into an date/time using a UDateFormat.
#define U_STABLE
This is used to declare a function as a stable public ICU C API.
Definition: umachine.h:109
int8_t UBool
The ICU boolean type.
Definition: umachine.h:200
C API: NumberFormat.
Medium style.
Definition: udat.h:151