udat.h 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660
  1. /*
  2. *******************************************************************************
  3. * Copyright (C) 1996-2016, 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 selector for 'b' field alignment.
  708. * Displays midnight and noon for 12am and 12pm, respectively, if available;
  709. * otherwise fall back to AM / PM.
  710. * @draft ICU 57
  711. */
  712. UDAT_AM_PM_MIDNIGHT_NOON_FIELD = 35,
  713. /* FieldPosition selector for 'B' field alignment.
  714. * Displays flexible day periods, such as "in the morning", if available.
  715. * @draft ICU 57
  716. */
  717. UDAT_FLEXIBLE_DAY_PERIOD_FIELD = 36,
  718. #endif /* U_HIDE_DRAFT_API */
  719. #ifndef U_HIDE_INTERNAL_API
  720. /**
  721. * FieldPosition and UFieldPosition selector for time separator,
  722. * no corresponding UCAL_ field. No pattern character is currently
  723. * defined for this.
  724. * @internal
  725. */
  726. UDAT_TIME_SEPARATOR_FIELD = 37,
  727. #endif /* U_HIDE_INTERNAL_API */
  728. /**
  729. * Number of FieldPosition and UFieldPosition selectors for
  730. * DateFormat and UDateFormat.
  731. * Valid selectors range from 0 to UDAT_FIELD_COUNT-1.
  732. * This value is subject to change if new fields are defined
  733. * in the future.
  734. * @stable ICU 3.0
  735. */
  736. UDAT_FIELD_COUNT = 38
  737. } UDateFormatField;
  738. #ifndef U_HIDE_INTERNAL_API
  739. /**
  740. * Is a pattern character defined for UDAT_TIME_SEPARATOR_FIELD?
  741. * In ICU 55 it was COLON, but that was withdrawn in ICU 56.
  742. * @internal ICU 56
  743. */
  744. #define UDAT_HAS_PATTERN_CHAR_FOR_TIME_SEPARATOR 0
  745. #endif /* U_HIDE_INTERNAL_API */
  746. /**
  747. * Maps from a UDateFormatField to the corresponding UCalendarDateFields.
  748. * Note: since the mapping is many-to-one, there is no inverse mapping.
  749. * @param field the UDateFormatField.
  750. * @return the UCalendarDateField. This will be UCAL_FIELD_COUNT in case
  751. * of error (e.g., the input field is UDAT_FIELD_COUNT).
  752. * @stable ICU 4.4
  753. */
  754. U_STABLE UCalendarDateFields U_EXPORT2
  755. udat_toCalendarDateField(UDateFormatField field);
  756. /**
  757. * Open a new UDateFormat for formatting and parsing dates and times.
  758. * A UDateFormat may be used to format dates in calls to {@link #udat_format },
  759. * and to parse dates in calls to {@link #udat_parse }.
  760. * @param timeStyle The style used to format times; one of UDAT_FULL, UDAT_LONG,
  761. * UDAT_MEDIUM, UDAT_SHORT, UDAT_DEFAULT, or UDAT_NONE (relative time styles
  762. * are not currently supported).
  763. * When the pattern parameter is used, pass in UDAT_PATTERN for both timeStyle and dateStyle.
  764. * @param dateStyle The style used to format dates; one of UDAT_FULL, UDAT_LONG,
  765. * UDAT_MEDIUM, UDAT_SHORT, UDAT_DEFAULT, UDAT_FULL_RELATIVE, UDAT_LONG_RELATIVE,
  766. * UDAT_MEDIUM_RELATIVE, UDAT_SHORT_RELATIVE, or UDAT_NONE.
  767. * When the pattern parameter is used, pass in UDAT_PATTERN for both timeStyle and dateStyle.
  768. * As currently implemented,
  769. * relative date formatting only affects a limited range of calendar days before or
  770. * after the current date, based on the CLDR &lt;field type="day"&gt;/&lt;relative&gt; data: For
  771. * example, in English, "Yesterday", "Today", and "Tomorrow". Outside of this range,
  772. * dates are formatted using the corresponding non-relative style.
  773. * @param locale The locale specifying the formatting conventions
  774. * @param tzID A timezone ID specifying the timezone to use. If 0, use
  775. * the default timezone.
  776. * @param tzIDLength The length of tzID, or -1 if null-terminated.
  777. * @param pattern A pattern specifying the format to use.
  778. * @param patternLength The number of characters in the pattern, or -1 if null-terminated.
  779. * @param status A pointer to an UErrorCode to receive any errors
  780. * @return A pointer to a UDateFormat to use for formatting dates and times, or 0 if
  781. * an error occurred.
  782. * @stable ICU 2.0
  783. */
  784. U_STABLE UDateFormat* U_EXPORT2
  785. udat_open(UDateFormatStyle timeStyle,
  786. UDateFormatStyle dateStyle,
  787. const char *locale,
  788. const UChar *tzID,
  789. int32_t tzIDLength,
  790. const UChar *pattern,
  791. int32_t patternLength,
  792. UErrorCode *status);
  793. /**
  794. * Close a UDateFormat.
  795. * Once closed, a UDateFormat may no longer be used.
  796. * @param format The formatter to close.
  797. * @stable ICU 2.0
  798. */
  799. U_STABLE void U_EXPORT2
  800. udat_close(UDateFormat* format);
  801. /**
  802. * DateFormat boolean attributes
  803. *
  804. * @stable ICU 53
  805. */
  806. typedef enum UDateFormatBooleanAttribute {
  807. /**
  808. * indicates whether whitespace is allowed. Includes trailing dot tolerance.
  809. * @stable ICU 53
  810. */
  811. UDAT_PARSE_ALLOW_WHITESPACE = 0,
  812. /**
  813. * indicates tolerance of numeric data when String data may be assumed. eg: UDAT_YEAR_NAME_FIELD,
  814. * UDAT_STANDALONE_MONTH_FIELD, UDAT_DAY_OF_WEEK_FIELD
  815. * @stable ICU 53
  816. */
  817. UDAT_PARSE_ALLOW_NUMERIC = 1,
  818. #ifndef U_HIDE_DRAFT_API
  819. /**
  820. * indicates tolerance of a partial literal match
  821. * e.g. accepting "--mon-02-march-2011" for a pattern of "'--: 'EEE-WW-MMMM-yyyy"
  822. * @draft ICU 56
  823. */
  824. UDAT_PARSE_PARTIAL_LITERAL_MATCH = 2,
  825. /**
  826. * indicates tolerance of pattern mismatch between input data and specified format pattern.
  827. * e.g. accepting "September" for a month pattern of MMM ("Sep")
  828. * @draft ICU 56
  829. */
  830. UDAT_PARSE_MULTIPLE_PATTERNS_FOR_MATCH = 3,
  831. #endif /* U_HIDE_DRAFT_API */
  832. /**
  833. * count boolean date format constants
  834. * @stable ICU 53
  835. */
  836. UDAT_BOOLEAN_ATTRIBUTE_COUNT = 4
  837. } UDateFormatBooleanAttribute;
  838. /**
  839. * Get a boolean attribute associated with a UDateFormat.
  840. * An example would be a true value for a key of UDAT_PARSE_ALLOW_WHITESPACE indicating allowing whitespace leniency.
  841. * If the formatter does not understand the attribute, -1 is returned.
  842. * @param fmt The formatter to query.
  843. * @param attr The attribute to query; e.g. UDAT_PARSE_ALLOW_WHITESPACE.
  844. * @param status A pointer to an UErrorCode to receive any errors
  845. * @return The value of attr.
  846. * @stable ICU 53
  847. */
  848. U_STABLE UBool U_EXPORT2
  849. udat_getBooleanAttribute(const UDateFormat* fmt, UDateFormatBooleanAttribute attr, UErrorCode* status);
  850. /**
  851. * Set a boolean attribute associated with a UDateFormat.
  852. * An example of a boolean attribute is parse leniency control. If the formatter does not understand
  853. * the attribute, the call is ignored.
  854. * @param fmt The formatter to set.
  855. * @param attr The attribute to set; one of UDAT_PARSE_ALLOW_WHITESPACE or UDAT_PARSE_ALLOW_NUMERIC
  856. * @param newValue The new value of attr.
  857. * @param status A pointer to an UErrorCode to receive any errors
  858. * @stable ICU 53
  859. */
  860. U_STABLE void U_EXPORT2
  861. udat_setBooleanAttribute(UDateFormat *fmt, UDateFormatBooleanAttribute attr, UBool newValue, UErrorCode* status);
  862. #if U_SHOW_CPLUSPLUS_API
  863. U_NAMESPACE_BEGIN
  864. /**
  865. * \class LocalUDateFormatPointer
  866. * "Smart pointer" class, closes a UDateFormat via udat_close().
  867. * For most methods see the LocalPointerBase base class.
  868. *
  869. * @see LocalPointerBase
  870. * @see LocalPointer
  871. * @stable ICU 4.4
  872. */
  873. U_DEFINE_LOCAL_OPEN_POINTER(LocalUDateFormatPointer, UDateFormat, udat_close);
  874. U_NAMESPACE_END
  875. #endif
  876. /**
  877. * Open a copy of a UDateFormat.
  878. * This function performs a deep copy.
  879. * @param fmt The format to copy
  880. * @param status A pointer to an UErrorCode to receive any errors.
  881. * @return A pointer to a UDateFormat identical to fmt.
  882. * @stable ICU 2.0
  883. */
  884. U_STABLE UDateFormat* U_EXPORT2
  885. udat_clone(const UDateFormat *fmt,
  886. UErrorCode *status);
  887. /**
  888. * Format a date using a UDateFormat.
  889. * The date will be formatted using the conventions specified in {@link #udat_open }
  890. * @param format The formatter to use
  891. * @param dateToFormat The date to format
  892. * @param result A pointer to a buffer to receive the formatted number.
  893. * @param resultLength The maximum size of result.
  894. * @param position A pointer to a UFieldPosition. On input, position->field
  895. * is read. On output, position->beginIndex and position->endIndex indicate
  896. * the beginning and ending indices of field number position->field, if such
  897. * a field exists. This parameter may be NULL, in which case no field
  898. * position data is returned.
  899. * @param status A pointer to an UErrorCode to receive any errors
  900. * @return The total buffer size needed; if greater than resultLength, the output was truncated.
  901. * @see udat_parse
  902. * @see UFieldPosition
  903. * @stable ICU 2.0
  904. */
  905. U_STABLE int32_t U_EXPORT2
  906. udat_format( const UDateFormat* format,
  907. UDate dateToFormat,
  908. UChar* result,
  909. int32_t resultLength,
  910. UFieldPosition* position,
  911. UErrorCode* status);
  912. /**
  913. * Format a date using an UDateFormat.
  914. * The date will be formatted using the conventions specified in {@link #udat_open }
  915. * @param format The formatter to use
  916. * @param calendar The calendar to format. The calendar instance might be
  917. * mutated if fields are not yet fully calculated, though
  918. * the function won't change the logical date and time held
  919. * by the instance.
  920. * @param result A pointer to a buffer to receive the formatted number.
  921. * @param capacity The maximum size of result.
  922. * @param position A pointer to a UFieldPosition. On input, position->field
  923. * is read. On output, position->beginIndex and position->endIndex indicate
  924. * the beginning and ending indices of field number position->field, if such
  925. * a field exists. This parameter may be NULL, in which case no field
  926. * position data is returned.
  927. * @param status A pointer to an UErrorCode to receive any errors
  928. * @return The total buffer size needed; if greater than resultLength, the output was truncated.
  929. * @see udat_format
  930. * @see udat_parseCalendar
  931. * @see UFieldPosition
  932. * @stable ICU 55
  933. */
  934. U_STABLE int32_t U_EXPORT2
  935. udat_formatCalendar( const UDateFormat* format,
  936. UCalendar* calendar,
  937. UChar* result,
  938. int32_t capacity,
  939. UFieldPosition* position,
  940. UErrorCode* status);
  941. /**
  942. * Format a date using a UDateFormat.
  943. * The date will be formatted using the conventions specified in {@link #udat_open}
  944. * @param format
  945. * The formatter to use
  946. * @param dateToFormat
  947. * The date to format
  948. * @param result
  949. * A pointer to a buffer to receive the formatted number.
  950. * @param resultLength
  951. * The maximum size of result.
  952. * @param fpositer
  953. * A pointer to a UFieldPositionIterator created by {@link #ufieldpositer_open}
  954. * (may be NULL if field position information is not needed). Any
  955. * iteration information already present in the UFieldPositionIterator
  956. * will be deleted, and the iterator will be reset to apply to the
  957. * fields in the formatted string created by this function call; the
  958. * field values provided by {@link #ufieldpositer_next} will be from the
  959. * UDateFormatField enum.
  960. * @param status
  961. * A pointer to a UErrorCode to receive any errors
  962. * @return
  963. * The total buffer size needed; if greater than resultLength, the output was truncated.
  964. * @see udat_parse
  965. * @see UFieldPositionIterator
  966. * @stable ICU 55
  967. */
  968. U_STABLE int32_t U_EXPORT2
  969. udat_formatForFields( const UDateFormat* format,
  970. UDate dateToFormat,
  971. UChar* result,
  972. int32_t resultLength,
  973. UFieldPositionIterator* fpositer,
  974. UErrorCode* status);
  975. /**
  976. * Format a date using a UDateFormat.
  977. * The date will be formatted using the conventions specified in {@link #udat_open }
  978. * @param format
  979. * The formatter to use
  980. * @param calendar
  981. * The calendar to format. The calendar instance might be mutated if fields
  982. * are not yet fully calculated, though the function won't change the logical
  983. * date and time held by the instance.
  984. * @param result
  985. * A pointer to a buffer to receive the formatted number.
  986. * @param capacity
  987. * The maximum size of result.
  988. * @param fpositer
  989. * A pointer to a UFieldPositionIterator created by {@link #ufieldpositer_open}
  990. * (may be NULL if field position information is not needed). Any
  991. * iteration information already present in the UFieldPositionIterator
  992. * will be deleted, and the iterator will be reset to apply to the
  993. * fields in the formatted string created by this function call; the
  994. * field values provided by {@link #ufieldpositer_next} will be from the
  995. * UDateFormatField enum.
  996. * @param status
  997. * A pointer to a UErrorCode to receive any errors
  998. * @return
  999. * The total buffer size needed; if greater than resultLength, the output was truncated.
  1000. * @see udat_format
  1001. * @see udat_parseCalendar
  1002. * @see UFieldPositionIterator
  1003. * @stable ICU 55
  1004. */
  1005. U_STABLE int32_t U_EXPORT2
  1006. udat_formatCalendarForFields( const UDateFormat* format,
  1007. UCalendar* calendar,
  1008. UChar* result,
  1009. int32_t capacity,
  1010. UFieldPositionIterator* fpositer,
  1011. UErrorCode* status);
  1012. /**
  1013. * Parse a string into an date/time using a UDateFormat.
  1014. * The date will be parsed using the conventions specified in {@link #udat_open }.
  1015. * <P>
  1016. * Note that the normal date formats associated with some calendars - such
  1017. * as the Chinese lunar calendar - do not specify enough fields to enable
  1018. * dates to be parsed unambiguously. In the case of the Chinese lunar
  1019. * calendar, while the year within the current 60-year cycle is specified,
  1020. * the number of such cycles since the start date of the calendar (in the
  1021. * UCAL_ERA field of the UCalendar object) is not normally part of the format,
  1022. * and parsing may assume the wrong era. For cases such as this it is
  1023. * recommended that clients parse using udat_parseCalendar with the UCalendar
  1024. * passed in set to the current date, or to a date within the era/cycle that
  1025. * should be assumed if absent in the format.
  1026. *
  1027. * @param format The formatter to use.
  1028. * @param text The text to parse.
  1029. * @param textLength The length of text, or -1 if null-terminated.
  1030. * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which
  1031. * to begin parsing. If not 0, on output the offset at which parsing ended.
  1032. * @param status A pointer to an UErrorCode to receive any errors
  1033. * @return The value of the parsed date/time
  1034. * @see udat_format
  1035. * @stable ICU 2.0
  1036. */
  1037. U_STABLE UDate U_EXPORT2
  1038. udat_parse(const UDateFormat* format,
  1039. const UChar* text,
  1040. int32_t textLength,
  1041. int32_t *parsePos,
  1042. UErrorCode *status);
  1043. /**
  1044. * Parse a string into an date/time using a UDateFormat.
  1045. * The date will be parsed using the conventions specified in {@link #udat_open }.
  1046. * @param format The formatter to use.
  1047. * @param calendar A calendar set on input to the date and time to be used for
  1048. * missing values in the date/time string being parsed, and set
  1049. * on output to the parsed date/time. When the calendar type is
  1050. * different from the internal calendar held by the UDateFormat
  1051. * instance, the internal calendar will be cloned to a work
  1052. * calendar set to the same milliseconds and time zone as this
  1053. * calendar parameter, field values will be parsed based on the
  1054. * work calendar, then the result (milliseconds and time zone)
  1055. * will be set in this calendar.
  1056. * @param text The text to parse.
  1057. * @param textLength The length of text, or -1 if null-terminated.
  1058. * @param parsePos If not 0, on input a pointer to an integer specifying the offset at which
  1059. * to begin parsing. If not 0, on output the offset at which parsing ended.
  1060. * @param status A pointer to an UErrorCode to receive any errors
  1061. * @see udat_format
  1062. * @stable ICU 2.0
  1063. */
  1064. U_STABLE void U_EXPORT2
  1065. udat_parseCalendar(const UDateFormat* format,
  1066. UCalendar* calendar,
  1067. const UChar* text,
  1068. int32_t textLength,
  1069. int32_t *parsePos,
  1070. UErrorCode *status);
  1071. /**
  1072. * Determine if an UDateFormat will perform lenient parsing.
  1073. * With lenient parsing, the parser may use heuristics to interpret inputs that do not
  1074. * precisely match the pattern. With strict parsing, inputs must match the pattern.
  1075. * @param fmt The formatter to query
  1076. * @return TRUE if fmt is set to perform lenient parsing, FALSE otherwise.
  1077. * @see udat_setLenient
  1078. * @stable ICU 2.0
  1079. */
  1080. U_STABLE UBool U_EXPORT2
  1081. udat_isLenient(const UDateFormat* fmt);
  1082. /**
  1083. * Specify whether an UDateFormat will perform lenient parsing.
  1084. * With lenient parsing, the parser may use heuristics to interpret inputs that do not
  1085. * precisely match the pattern. With strict parsing, inputs must match the pattern.
  1086. * @param fmt The formatter to set
  1087. * @param isLenient TRUE if fmt should perform lenient parsing, FALSE otherwise.
  1088. * @see dat_isLenient
  1089. * @stable ICU 2.0
  1090. */
  1091. U_STABLE void U_EXPORT2
  1092. udat_setLenient( UDateFormat* fmt,
  1093. UBool isLenient);
  1094. /**
  1095. * Get the UCalendar associated with an UDateFormat.
  1096. * A UDateFormat uses a UCalendar to convert a raw value to, for example,
  1097. * the day of the week.
  1098. * @param fmt The formatter to query.
  1099. * @return A pointer to the UCalendar used by fmt.
  1100. * @see udat_setCalendar
  1101. * @stable ICU 2.0
  1102. */
  1103. U_STABLE const UCalendar* U_EXPORT2
  1104. udat_getCalendar(const UDateFormat* fmt);
  1105. /**
  1106. * Set the UCalendar associated with an UDateFormat.
  1107. * A UDateFormat uses a UCalendar to convert a raw value to, for example,
  1108. * the day of the week.
  1109. * @param fmt The formatter to set.
  1110. * @param calendarToSet A pointer to an UCalendar to be used by fmt.
  1111. * @see udat_setCalendar
  1112. * @stable ICU 2.0
  1113. */
  1114. U_STABLE void U_EXPORT2
  1115. udat_setCalendar( UDateFormat* fmt,
  1116. const UCalendar* calendarToSet);
  1117. /**
  1118. * Get the UNumberFormat associated with an UDateFormat.
  1119. * A UDateFormat uses a UNumberFormat to format numbers within a date,
  1120. * for example the day number.
  1121. * @param fmt The formatter to query.
  1122. * @return A pointer to the UNumberFormat used by fmt to format numbers.
  1123. * @see udat_setNumberFormat
  1124. * @stable ICU 2.0
  1125. */
  1126. U_STABLE const UNumberFormat* U_EXPORT2
  1127. udat_getNumberFormat(const UDateFormat* fmt);
  1128. /**
  1129. * Get the UNumberFormat for specific field associated with an UDateFormat.
  1130. * For example: 'y' for year and 'M' for month
  1131. * @param fmt The formatter to query.
  1132. * @param field the field to query
  1133. * @return A pointer to the UNumberFormat used by fmt to format field numbers.
  1134. * @see udat_setNumberFormatForField
  1135. * @stable ICU 54
  1136. */
  1137. U_STABLE const UNumberFormat* U_EXPORT2
  1138. udat_getNumberFormatForField(const UDateFormat* fmt, UChar field);
  1139. /**
  1140. * Set the UNumberFormat for specific field associated with an UDateFormat.
  1141. * It can be a single field like: "y"(year) or "M"(month)
  1142. * It can be several field combined together: "yM"(year and month)
  1143. * Note:
  1144. * 1 symbol field is enough for multiple symbol field (so "y" will override "yy", "yyy")
  1145. * If the field is not numeric, then override has no effect (like "MMM" will use abbreviation, not numerical field)
  1146. *
  1147. * @param fields the fields to set
  1148. * @param fmt The formatter to set.
  1149. * @param numberFormatToSet A pointer to the UNumberFormat to be used by fmt to format numbers.
  1150. * @param status error code passed around (memory allocation or invalid fields)
  1151. * @see udat_getNumberFormatForField
  1152. * @stable ICU 54
  1153. */
  1154. U_STABLE void U_EXPORT2
  1155. udat_adoptNumberFormatForFields( UDateFormat* fmt,
  1156. const UChar* fields,
  1157. UNumberFormat* numberFormatToSet,
  1158. UErrorCode* status);
  1159. /**
  1160. * Set the UNumberFormat associated with an UDateFormat.
  1161. * A UDateFormat uses a UNumberFormat to format numbers within a date,
  1162. * for example the day number.
  1163. * This method also clears per field NumberFormat instances previously
  1164. * set by {@see udat_setNumberFormatForField}
  1165. * @param fmt The formatter to set.
  1166. * @param numberFormatToSet A pointer to the UNumberFormat to be used by fmt to format numbers.
  1167. * @see udat_getNumberFormat
  1168. * @see udat_setNumberFormatForField
  1169. * @stable ICU 2.0
  1170. */
  1171. U_STABLE void U_EXPORT2
  1172. udat_setNumberFormat( UDateFormat* fmt,
  1173. const UNumberFormat* numberFormatToSet);
  1174. /**
  1175. * Adopt the UNumberFormat associated with an UDateFormat.
  1176. * A UDateFormat uses a UNumberFormat to format numbers within a date,
  1177. * for example the day number.
  1178. * @param fmt The formatter to set.
  1179. * @param numberFormatToAdopt A pointer to the UNumberFormat to be used by fmt to format numbers.
  1180. * @see udat_getNumberFormat
  1181. * @stable ICU 54
  1182. */
  1183. U_STABLE void U_EXPORT2
  1184. udat_adoptNumberFormat( UDateFormat* fmt,
  1185. UNumberFormat* numberFormatToAdopt);
  1186. /**
  1187. * Get a locale for which date/time formatting patterns are available.
  1188. * A UDateFormat in a locale returned by this function will perform the correct
  1189. * formatting and parsing for the locale.
  1190. * @param localeIndex The index of the desired locale.
  1191. * @return A locale for which date/time formatting patterns are available, or 0 if none.
  1192. * @see udat_countAvailable
  1193. * @stable ICU 2.0
  1194. */
  1195. U_STABLE const char* U_EXPORT2
  1196. udat_getAvailable(int32_t localeIndex);
  1197. /**
  1198. * Determine how many locales have date/time formatting patterns available.
  1199. * This function is most useful as determining the loop ending condition for
  1200. * calls to {@link #udat_getAvailable }.
  1201. * @return The number of locales for which date/time formatting patterns are available.
  1202. * @see udat_getAvailable
  1203. * @stable ICU 2.0
  1204. */
  1205. U_STABLE int32_t U_EXPORT2
  1206. udat_countAvailable(void);
  1207. /**
  1208. * Get the year relative to which all 2-digit years are interpreted.
  1209. * For example, if the 2-digit start year is 2100, the year 99 will be
  1210. * interpreted as 2199.
  1211. * @param fmt The formatter to query.
  1212. * @param status A pointer to an UErrorCode to receive any errors
  1213. * @return The year relative to which all 2-digit years are interpreted.
  1214. * @see udat_Set2DigitYearStart
  1215. * @stable ICU 2.0
  1216. */
  1217. U_STABLE UDate U_EXPORT2
  1218. udat_get2DigitYearStart( const UDateFormat *fmt,
  1219. UErrorCode *status);
  1220. /**
  1221. * Set the year relative to which all 2-digit years will be interpreted.
  1222. * For example, if the 2-digit start year is 2100, the year 99 will be
  1223. * interpreted as 2199.
  1224. * @param fmt The formatter to set.
  1225. * @param d The year relative to which all 2-digit years will be interpreted.
  1226. * @param status A pointer to an UErrorCode to receive any errors
  1227. * @see udat_Set2DigitYearStart
  1228. * @stable ICU 2.0
  1229. */
  1230. U_STABLE void U_EXPORT2
  1231. udat_set2DigitYearStart( UDateFormat *fmt,
  1232. UDate d,
  1233. UErrorCode *status);
  1234. /**
  1235. * Extract the pattern from a UDateFormat.
  1236. * The pattern will follow the pattern syntax rules.
  1237. * @param fmt The formatter to query.
  1238. * @param localized TRUE if the pattern should be localized, FALSE otherwise.
  1239. * @param result A pointer to a buffer to receive the pattern.
  1240. * @param resultLength The maximum size of result.
  1241. * @param status A pointer to an UErrorCode to receive any errors
  1242. * @return The total buffer size needed; if greater than resultLength, the output was truncated.
  1243. * @see udat_applyPattern
  1244. * @stable ICU 2.0
  1245. */
  1246. U_STABLE int32_t U_EXPORT2
  1247. udat_toPattern( const UDateFormat *fmt,
  1248. UBool localized,
  1249. UChar *result,
  1250. int32_t resultLength,
  1251. UErrorCode *status);
  1252. /**
  1253. * Set the pattern used by an UDateFormat.
  1254. * The pattern should follow the pattern syntax rules.
  1255. * @param format The formatter to set.
  1256. * @param localized TRUE if the pattern is localized, FALSE otherwise.
  1257. * @param pattern The new pattern
  1258. * @param patternLength The length of pattern, or -1 if null-terminated.
  1259. * @see udat_toPattern
  1260. * @stable ICU 2.0
  1261. */
  1262. U_STABLE void U_EXPORT2
  1263. udat_applyPattern( UDateFormat *format,
  1264. UBool localized,
  1265. const UChar *pattern,
  1266. int32_t patternLength);
  1267. /**
  1268. * The possible types of date format symbols
  1269. * @stable ICU 2.6
  1270. */
  1271. typedef enum UDateFormatSymbolType {
  1272. /** The era names, for example AD */
  1273. UDAT_ERAS,
  1274. /** The month names, for example February */
  1275. UDAT_MONTHS,
  1276. /** The short month names, for example Feb. */
  1277. UDAT_SHORT_MONTHS,
  1278. /** The CLDR-style format "wide" weekday names, for example Monday */
  1279. UDAT_WEEKDAYS,
  1280. /**
  1281. * The CLDR-style format "abbreviated" (not "short") weekday names, for example "Mon."
  1282. * For the CLDR-style format "short" weekday names, use UDAT_SHORTER_WEEKDAYS.
  1283. */
  1284. UDAT_SHORT_WEEKDAYS,
  1285. /** The AM/PM names, for example AM */
  1286. UDAT_AM_PMS,
  1287. /** The localized characters */
  1288. UDAT_LOCALIZED_CHARS,
  1289. /** The long era names, for example Anno Domini */
  1290. UDAT_ERA_NAMES,
  1291. /** The narrow month names, for example F */
  1292. UDAT_NARROW_MONTHS,
  1293. /** The CLDR-style format "narrow" weekday names, for example "M" */
  1294. UDAT_NARROW_WEEKDAYS,
  1295. /** Standalone context versions of months */
  1296. UDAT_STANDALONE_MONTHS,
  1297. UDAT_STANDALONE_SHORT_MONTHS,
  1298. UDAT_STANDALONE_NARROW_MONTHS,
  1299. /** The CLDR-style stand-alone "wide" weekday names */
  1300. UDAT_STANDALONE_WEEKDAYS,
  1301. /**
  1302. * The CLDR-style stand-alone "abbreviated" (not "short") weekday names.
  1303. * For the CLDR-style stand-alone "short" weekday names, use UDAT_STANDALONE_SHORTER_WEEKDAYS.
  1304. */
  1305. UDAT_STANDALONE_SHORT_WEEKDAYS,
  1306. /** The CLDR-style stand-alone "narrow" weekday names */
  1307. UDAT_STANDALONE_NARROW_WEEKDAYS,
  1308. /** The quarters, for example 1st Quarter */
  1309. UDAT_QUARTERS,
  1310. /** The short quarter names, for example Q1 */
  1311. UDAT_SHORT_QUARTERS,
  1312. /** Standalone context versions of quarters */
  1313. UDAT_STANDALONE_QUARTERS,
  1314. UDAT_STANDALONE_SHORT_QUARTERS,
  1315. /**
  1316. * The CLDR-style short weekday names, e.g. "Su", Mo", etc.
  1317. * These are named "SHORTER" to contrast with the constants using _SHORT_
  1318. * above, which actually get the CLDR-style *abbreviated* versions of the
  1319. * corresponding names.
  1320. * @stable ICU 51
  1321. */
  1322. UDAT_SHORTER_WEEKDAYS,
  1323. /**
  1324. * Standalone version of UDAT_SHORTER_WEEKDAYS.
  1325. * @stable ICU 51
  1326. */
  1327. UDAT_STANDALONE_SHORTER_WEEKDAYS,
  1328. /**
  1329. * Cyclic year names (only supported for some calendars, and only for FORMAT usage;
  1330. * udat_setSymbols not supported for UDAT_CYCLIC_YEARS_WIDE)
  1331. * @stable ICU 54
  1332. */
  1333. UDAT_CYCLIC_YEARS_WIDE,
  1334. /**
  1335. * Cyclic year names (only supported for some calendars, and only for FORMAT usage)
  1336. * @stable ICU 54
  1337. */
  1338. UDAT_CYCLIC_YEARS_ABBREVIATED,
  1339. /**
  1340. * Cyclic year names (only supported for some calendars, and only for FORMAT usage;
  1341. * udat_setSymbols not supported for UDAT_CYCLIC_YEARS_NARROW)
  1342. * @stable ICU 54
  1343. */
  1344. UDAT_CYCLIC_YEARS_NARROW,
  1345. /**
  1346. * Calendar zodiac names (only supported for some calendars, and only for FORMAT usage;
  1347. * udat_setSymbols not supported for UDAT_ZODIAC_NAMES_WIDE)
  1348. * @stable ICU 54
  1349. */
  1350. UDAT_ZODIAC_NAMES_WIDE,
  1351. /**
  1352. * Calendar zodiac names (only supported for some calendars, and only for FORMAT usage)
  1353. * @stable ICU 54
  1354. */
  1355. UDAT_ZODIAC_NAMES_ABBREVIATED,
  1356. /**
  1357. * Calendar zodiac names (only supported for some calendars, and only for FORMAT usage;
  1358. * udat_setSymbols not supported for UDAT_ZODIAC_NAMES_NARROW)
  1359. * @stable ICU 54
  1360. */
  1361. UDAT_ZODIAC_NAMES_NARROW
  1362. } UDateFormatSymbolType;
  1363. struct UDateFormatSymbols;
  1364. /** Date format symbols.
  1365. * For usage in C programs.
  1366. * @stable ICU 2.6
  1367. */
  1368. typedef struct UDateFormatSymbols UDateFormatSymbols;
  1369. /**
  1370. * Get the symbols associated with an UDateFormat.
  1371. * The symbols are what a UDateFormat uses to represent locale-specific data,
  1372. * for example month or day names.
  1373. * @param fmt The formatter to query.
  1374. * @param type The type of symbols to get. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS,
  1375. * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS
  1376. * @param symbolIndex The desired symbol of type type.
  1377. * @param result A pointer to a buffer to receive the pattern.
  1378. * @param resultLength The maximum size of result.
  1379. * @param status A pointer to an UErrorCode to receive any errors
  1380. * @return The total buffer size needed; if greater than resultLength, the output was truncated.
  1381. * @see udat_countSymbols
  1382. * @see udat_setSymbols
  1383. * @stable ICU 2.0
  1384. */
  1385. U_STABLE int32_t U_EXPORT2
  1386. udat_getSymbols(const UDateFormat *fmt,
  1387. UDateFormatSymbolType type,
  1388. int32_t symbolIndex,
  1389. UChar *result,
  1390. int32_t resultLength,
  1391. UErrorCode *status);
  1392. /**
  1393. * Count the number of particular symbols for an UDateFormat.
  1394. * This function is most useful as for detemining the loop termination condition
  1395. * for calls to {@link #udat_getSymbols }.
  1396. * @param fmt The formatter to query.
  1397. * @param type The type of symbols to count. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS,
  1398. * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS
  1399. * @return The number of symbols of type type.
  1400. * @see udat_getSymbols
  1401. * @see udat_setSymbols
  1402. * @stable ICU 2.0
  1403. */
  1404. U_STABLE int32_t U_EXPORT2
  1405. udat_countSymbols( const UDateFormat *fmt,
  1406. UDateFormatSymbolType type);
  1407. /**
  1408. * Set the symbols associated with an UDateFormat.
  1409. * The symbols are what a UDateFormat uses to represent locale-specific data,
  1410. * for example month or day names.
  1411. * @param format The formatter to set
  1412. * @param type The type of symbols to set. One of UDAT_ERAS, UDAT_MONTHS, UDAT_SHORT_MONTHS,
  1413. * UDAT_WEEKDAYS, UDAT_SHORT_WEEKDAYS, UDAT_AM_PMS, or UDAT_LOCALIZED_CHARS
  1414. * @param symbolIndex The index of the symbol to set of type type.
  1415. * @param value The new value
  1416. * @param valueLength The length of value, or -1 if null-terminated
  1417. * @param status A pointer to an UErrorCode to receive any errors
  1418. * @see udat_getSymbols
  1419. * @see udat_countSymbols
  1420. * @stable ICU 2.0
  1421. */
  1422. U_STABLE void U_EXPORT2
  1423. udat_setSymbols( UDateFormat *format,
  1424. UDateFormatSymbolType type,
  1425. int32_t symbolIndex,
  1426. UChar *value,
  1427. int32_t valueLength,
  1428. UErrorCode *status);
  1429. /**
  1430. * Get the locale for this date format object.
  1431. * You can choose between valid and actual locale.
  1432. * @param fmt The formatter to get the locale from
  1433. * @param type type of the locale we're looking for (valid or actual)
  1434. * @param status error code for the operation
  1435. * @return the locale name
  1436. * @stable ICU 2.8
  1437. */
  1438. U_STABLE const char* U_EXPORT2
  1439. udat_getLocaleByType(const UDateFormat *fmt,
  1440. ULocDataLocaleType type,
  1441. UErrorCode* status);
  1442. /**
  1443. * Set a particular UDisplayContext value in the formatter, such as
  1444. * UDISPCTX_CAPITALIZATION_FOR_STANDALONE.
  1445. * @param fmt The formatter for which to set a UDisplayContext value.
  1446. * @param value The UDisplayContext value to set.
  1447. * @param status A pointer to an UErrorCode to receive any errors
  1448. * @stable ICU 51
  1449. */
  1450. U_DRAFT void U_EXPORT2
  1451. udat_setContext(UDateFormat* fmt, UDisplayContext value, UErrorCode* status);
  1452. /**
  1453. * Get the formatter's UDisplayContext value for the specified UDisplayContextType,
  1454. * such as UDISPCTX_TYPE_CAPITALIZATION.
  1455. * @param fmt The formatter to query.
  1456. * @param type The UDisplayContextType whose value to return
  1457. * @param status A pointer to an UErrorCode to receive any errors
  1458. * @return The UDisplayContextValue for the specified type.
  1459. * @stable ICU 53
  1460. */
  1461. U_STABLE UDisplayContext U_EXPORT2
  1462. udat_getContext(const UDateFormat* fmt, UDisplayContextType type, UErrorCode* status);
  1463. #ifndef U_HIDE_INTERNAL_API
  1464. /**
  1465. * Extract the date pattern from a UDateFormat set for relative date formatting.
  1466. * The pattern will follow the pattern syntax rules.
  1467. * @param fmt The formatter to query.
  1468. * @param result A pointer to a buffer to receive the pattern.
  1469. * @param resultLength The maximum size of result.
  1470. * @param status A pointer to a UErrorCode to receive any errors
  1471. * @return The total buffer size needed; if greater than resultLength, the output was truncated.
  1472. * @see udat_applyPatternRelative
  1473. * @internal ICU 4.2 technology preview
  1474. */
  1475. U_INTERNAL int32_t U_EXPORT2
  1476. udat_toPatternRelativeDate(const UDateFormat *fmt,
  1477. UChar *result,
  1478. int32_t resultLength,
  1479. UErrorCode *status);
  1480. /**
  1481. * Extract the time pattern from a UDateFormat set for relative date formatting.
  1482. * The pattern will follow the pattern syntax rules.
  1483. * @param fmt The formatter to query.
  1484. * @param result A pointer to a buffer to receive the pattern.
  1485. * @param resultLength The maximum size of result.
  1486. * @param status A pointer to a UErrorCode to receive any errors
  1487. * @return The total buffer size needed; if greater than resultLength, the output was truncated.
  1488. * @see udat_applyPatternRelative
  1489. * @internal ICU 4.2 technology preview
  1490. */
  1491. U_INTERNAL int32_t U_EXPORT2
  1492. udat_toPatternRelativeTime(const UDateFormat *fmt,
  1493. UChar *result,
  1494. int32_t resultLength,
  1495. UErrorCode *status);
  1496. /**
  1497. * Set the date & time patterns used by a UDateFormat set for relative date formatting.
  1498. * The patterns should follow the pattern syntax rules.
  1499. * @param format The formatter to set.
  1500. * @param datePattern The new date pattern
  1501. * @param datePatternLength The length of datePattern, or -1 if null-terminated.
  1502. * @param timePattern The new time pattern
  1503. * @param timePatternLength The length of timePattern, or -1 if null-terminated.
  1504. * @param status A pointer to a UErrorCode to receive any errors
  1505. * @see udat_toPatternRelativeDate, udat_toPatternRelativeTime
  1506. * @internal ICU 4.2 technology preview
  1507. */
  1508. U_INTERNAL void U_EXPORT2
  1509. udat_applyPatternRelative(UDateFormat *format,
  1510. const UChar *datePattern,
  1511. int32_t datePatternLength,
  1512. const UChar *timePattern,
  1513. int32_t timePatternLength,
  1514. UErrorCode *status);
  1515. /**
  1516. * @internal
  1517. * @see udat_open
  1518. */
  1519. typedef UDateFormat* (U_EXPORT2 *UDateFormatOpener) (UDateFormatStyle timeStyle,
  1520. UDateFormatStyle dateStyle,
  1521. const char *locale,
  1522. const UChar *tzID,
  1523. int32_t tzIDLength,
  1524. const UChar *pattern,
  1525. int32_t patternLength,
  1526. UErrorCode *status);
  1527. /**
  1528. * Register a provider factory
  1529. * @internal ICU 49
  1530. */
  1531. U_INTERNAL void U_EXPORT2
  1532. udat_registerOpener(UDateFormatOpener opener, UErrorCode *status);
  1533. /**
  1534. * Un-Register a provider factory
  1535. * @internal ICU 49
  1536. */
  1537. U_INTERNAL UDateFormatOpener U_EXPORT2
  1538. udat_unregisterOpener(UDateFormatOpener opener, UErrorCode *status);
  1539. #endif /* U_HIDE_INTERNAL_API */
  1540. #endif /* #if !UCONFIG_NO_FORMATTING */
  1541. #endif