udat.h 61 KB

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