udat.h 60 KB

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