udat.h 62 KB

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