udat.h 59 KB

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