udatpg.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. *******************************************************************************
  5. *
  6. * Copyright (C) 2007-2015, International Business Machines
  7. * Corporation and others. All Rights Reserved.
  8. *
  9. *******************************************************************************
  10. * file name: udatpg.h
  11. * encoding: UTF-8
  12. * tab size: 8 (not used)
  13. * indentation:4
  14. *
  15. * created on: 2007jul30
  16. * created by: Markus W. Scherer
  17. */
  18. #ifndef __UDATPG_H__
  19. #define __UDATPG_H__
  20. #include "unicode/utypes.h"
  21. #include "unicode/udat.h"
  22. #include "unicode/uenum.h"
  23. #if U_SHOW_CPLUSPLUS_API
  24. #include "unicode/localpointer.h"
  25. #endif // U_SHOW_CPLUSPLUS_API
  26. /**
  27. * \file
  28. * \brief C API: Wrapper for icu::DateTimePatternGenerator (unicode/dtptngen.h).
  29. *
  30. * UDateTimePatternGenerator provides flexible generation of date format patterns,
  31. * like "yy-MM-dd". The user can build up the generator by adding successive
  32. * patterns. Once that is done, a query can be made using a "skeleton", which is
  33. * a pattern which just includes the desired fields and lengths. The generator
  34. * will return the "best fit" pattern corresponding to that skeleton.
  35. * <p>The main method people will use is udatpg_getBestPattern, since normally
  36. * UDateTimePatternGenerator is pre-built with data from a particular locale.
  37. * However, generators can be built directly from other data as well.
  38. * <p><i>Issue: may be useful to also have a function that returns the list of
  39. * fields in a pattern, in order, since we have that internally.
  40. * That would be useful for getting the UI order of field elements.</i>
  41. */
  42. /**
  43. * Opaque type for a date/time pattern generator object.
  44. * @stable ICU 3.8
  45. */
  46. typedef void *UDateTimePatternGenerator;
  47. /**
  48. * Field number constants for udatpg_getAppendItemFormats() and similar functions.
  49. * These constants are separate from UDateFormatField despite semantic overlap
  50. * because some fields are merged for the date/time pattern generator.
  51. * @stable ICU 3.8
  52. */
  53. typedef enum UDateTimePatternField {
  54. /** @stable ICU 3.8 */
  55. UDATPG_ERA_FIELD,
  56. /** @stable ICU 3.8 */
  57. UDATPG_YEAR_FIELD,
  58. /** @stable ICU 3.8 */
  59. UDATPG_QUARTER_FIELD,
  60. /** @stable ICU 3.8 */
  61. UDATPG_MONTH_FIELD,
  62. /** @stable ICU 3.8 */
  63. UDATPG_WEEK_OF_YEAR_FIELD,
  64. /** @stable ICU 3.8 */
  65. UDATPG_WEEK_OF_MONTH_FIELD,
  66. /** @stable ICU 3.8 */
  67. UDATPG_WEEKDAY_FIELD,
  68. /** @stable ICU 3.8 */
  69. UDATPG_DAY_OF_YEAR_FIELD,
  70. /** @stable ICU 3.8 */
  71. UDATPG_DAY_OF_WEEK_IN_MONTH_FIELD,
  72. /** @stable ICU 3.8 */
  73. UDATPG_DAY_FIELD,
  74. /** @stable ICU 3.8 */
  75. UDATPG_DAYPERIOD_FIELD,
  76. /** @stable ICU 3.8 */
  77. UDATPG_HOUR_FIELD,
  78. /** @stable ICU 3.8 */
  79. UDATPG_MINUTE_FIELD,
  80. /** @stable ICU 3.8 */
  81. UDATPG_SECOND_FIELD,
  82. /** @stable ICU 3.8 */
  83. UDATPG_FRACTIONAL_SECOND_FIELD,
  84. /** @stable ICU 3.8 */
  85. UDATPG_ZONE_FIELD,
  86. /* Do not conditionalize the following with #ifndef U_HIDE_DEPRECATED_API,
  87. * it is needed for layout of DateTimePatternGenerator object. */
  88. #ifndef U_FORCE_HIDE_DEPRECATED_API
  89. /**
  90. * One more than the highest normal UDateTimePatternField value.
  91. * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
  92. */
  93. UDATPG_FIELD_COUNT
  94. #endif // U_FORCE_HIDE_DEPRECATED_API
  95. } UDateTimePatternField;
  96. /**
  97. * Field display name width constants for udatpg_getFieldDisplayName().
  98. * @stable ICU 61
  99. */
  100. typedef enum UDateTimePGDisplayWidth {
  101. /** @stable ICU 61 */
  102. UDATPG_WIDE,
  103. /** @stable ICU 61 */
  104. UDATPG_ABBREVIATED,
  105. /** @stable ICU 61 */
  106. UDATPG_NARROW
  107. } UDateTimePGDisplayWidth;
  108. /**
  109. * Masks to control forcing the length of specified fields in the returned
  110. * pattern to match those in the skeleton (when this would not happen
  111. * otherwise). These may be combined to force the length of multiple fields.
  112. * Used with udatpg_getBestPatternWithOptions, udatpg_replaceFieldTypesWithOptions.
  113. * @stable ICU 4.4
  114. */
  115. typedef enum UDateTimePatternMatchOptions {
  116. /** @stable ICU 4.4 */
  117. UDATPG_MATCH_NO_OPTIONS = 0,
  118. /** @stable ICU 4.4 */
  119. UDATPG_MATCH_HOUR_FIELD_LENGTH = 1 << UDATPG_HOUR_FIELD,
  120. #ifndef U_HIDE_INTERNAL_API
  121. /** @internal ICU 4.4 */
  122. UDATPG_MATCH_MINUTE_FIELD_LENGTH = 1 << UDATPG_MINUTE_FIELD,
  123. /** @internal ICU 4.4 */
  124. UDATPG_MATCH_SECOND_FIELD_LENGTH = 1 << UDATPG_SECOND_FIELD,
  125. #endif /* U_HIDE_INTERNAL_API */
  126. /** @stable ICU 4.4 */
  127. UDATPG_MATCH_ALL_FIELDS_LENGTH = (1 << UDATPG_FIELD_COUNT) - 1
  128. } UDateTimePatternMatchOptions;
  129. /**
  130. * Status return values from udatpg_addPattern().
  131. * @stable ICU 3.8
  132. */
  133. typedef enum UDateTimePatternConflict {
  134. /** @stable ICU 3.8 */
  135. UDATPG_NO_CONFLICT,
  136. /** @stable ICU 3.8 */
  137. UDATPG_BASE_CONFLICT,
  138. /** @stable ICU 3.8 */
  139. UDATPG_CONFLICT,
  140. #ifndef U_HIDE_DEPRECATED_API
  141. /**
  142. * One more than the highest normal UDateTimePatternConflict value.
  143. * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
  144. */
  145. UDATPG_CONFLICT_COUNT
  146. #endif // U_HIDE_DEPRECATED_API
  147. } UDateTimePatternConflict;
  148. /**
  149. * Open a generator according to a given locale.
  150. * @param locale
  151. * @param pErrorCode a pointer to the UErrorCode which must not indicate a
  152. * failure before the function call.
  153. * @return a pointer to UDateTimePatternGenerator.
  154. * @stable ICU 3.8
  155. */
  156. U_CAPI UDateTimePatternGenerator * U_EXPORT2
  157. udatpg_open(const char *locale, UErrorCode *pErrorCode);
  158. /**
  159. * Open an empty generator, to be constructed with udatpg_addPattern(...) etc.
  160. * @param pErrorCode a pointer to the UErrorCode which must not indicate a
  161. * failure before the function call.
  162. * @return a pointer to UDateTimePatternGenerator.
  163. * @stable ICU 3.8
  164. */
  165. U_CAPI UDateTimePatternGenerator * U_EXPORT2
  166. udatpg_openEmpty(UErrorCode *pErrorCode);
  167. /**
  168. * Close a generator.
  169. * @param dtpg a pointer to UDateTimePatternGenerator.
  170. * @stable ICU 3.8
  171. */
  172. U_CAPI void U_EXPORT2
  173. udatpg_close(UDateTimePatternGenerator *dtpg);
  174. #if U_SHOW_CPLUSPLUS_API
  175. U_NAMESPACE_BEGIN
  176. /**
  177. * \class LocalUDateTimePatternGeneratorPointer
  178. * "Smart pointer" class, closes a UDateTimePatternGenerator via udatpg_close().
  179. * For most methods see the LocalPointerBase base class.
  180. *
  181. * @see LocalPointerBase
  182. * @see LocalPointer
  183. * @stable ICU 4.4
  184. */
  185. U_DEFINE_LOCAL_OPEN_POINTER(LocalUDateTimePatternGeneratorPointer, UDateTimePatternGenerator, udatpg_close);
  186. U_NAMESPACE_END
  187. #endif
  188. /**
  189. * Create a copy pf a generator.
  190. * @param dtpg a pointer to UDateTimePatternGenerator to be copied.
  191. * @param pErrorCode a pointer to the UErrorCode which must not indicate a
  192. * failure before the function call.
  193. * @return a pointer to a new UDateTimePatternGenerator.
  194. * @stable ICU 3.8
  195. */
  196. U_CAPI UDateTimePatternGenerator * U_EXPORT2
  197. udatpg_clone(const UDateTimePatternGenerator *dtpg, UErrorCode *pErrorCode);
  198. /**
  199. * Get the best pattern matching the input skeleton. It is guaranteed to
  200. * have all of the fields in the skeleton.
  201. *
  202. * Note that this function uses a non-const UDateTimePatternGenerator:
  203. * It uses a stateful pattern parser which is set up for each generator object,
  204. * rather than creating one for each function call.
  205. * Consecutive calls to this function do not affect each other,
  206. * but this function cannot be used concurrently on a single generator object.
  207. *
  208. * @param dtpg a pointer to UDateTimePatternGenerator.
  209. * @param skeleton
  210. * The skeleton is a pattern containing only the variable fields.
  211. * For example, "MMMdd" and "mmhh" are skeletons.
  212. * @param length the length of skeleton
  213. * @param bestPattern
  214. * The best pattern found from the given skeleton.
  215. * @param capacity the capacity of bestPattern.
  216. * @param pErrorCode a pointer to the UErrorCode which must not indicate a
  217. * failure before the function call.
  218. * @return the length of bestPattern.
  219. * @stable ICU 3.8
  220. */
  221. U_CAPI int32_t U_EXPORT2
  222. udatpg_getBestPattern(UDateTimePatternGenerator *dtpg,
  223. const UChar *skeleton, int32_t length,
  224. UChar *bestPattern, int32_t capacity,
  225. UErrorCode *pErrorCode);
  226. /**
  227. * Get the best pattern matching the input skeleton. It is guaranteed to
  228. * have all of the fields in the skeleton.
  229. *
  230. * Note that this function uses a non-const UDateTimePatternGenerator:
  231. * It uses a stateful pattern parser which is set up for each generator object,
  232. * rather than creating one for each function call.
  233. * Consecutive calls to this function do not affect each other,
  234. * but this function cannot be used concurrently on a single generator object.
  235. *
  236. * @param dtpg a pointer to UDateTimePatternGenerator.
  237. * @param skeleton
  238. * The skeleton is a pattern containing only the variable fields.
  239. * For example, "MMMdd" and "mmhh" are skeletons.
  240. * @param length the length of skeleton
  241. * @param options
  242. * Options for forcing the length of specified fields in the
  243. * returned pattern to match those in the skeleton (when this
  244. * would not happen otherwise). For default behavior, use
  245. * UDATPG_MATCH_NO_OPTIONS.
  246. * @param bestPattern
  247. * The best pattern found from the given skeleton.
  248. * @param capacity
  249. * the capacity of bestPattern.
  250. * @param pErrorCode
  251. * a pointer to the UErrorCode which must not indicate a
  252. * failure before the function call.
  253. * @return the length of bestPattern.
  254. * @stable ICU 4.4
  255. */
  256. U_CAPI int32_t U_EXPORT2
  257. udatpg_getBestPatternWithOptions(UDateTimePatternGenerator *dtpg,
  258. const UChar *skeleton, int32_t length,
  259. UDateTimePatternMatchOptions options,
  260. UChar *bestPattern, int32_t capacity,
  261. UErrorCode *pErrorCode);
  262. /**
  263. * Get a unique skeleton from a given pattern. For example,
  264. * both "MMM-dd" and "dd/MMM" produce the skeleton "MMMdd".
  265. *
  266. * Note that this function uses a non-const UDateTimePatternGenerator:
  267. * It uses a stateful pattern parser which is set up for each generator object,
  268. * rather than creating one for each function call.
  269. * Consecutive calls to this function do not affect each other,
  270. * but this function cannot be used concurrently on a single generator object.
  271. *
  272. * @param unusedDtpg a pointer to UDateTimePatternGenerator.
  273. * This parameter is no longer used. Callers may pass NULL.
  274. * @param pattern input pattern, such as "dd/MMM".
  275. * @param length the length of pattern.
  276. * @param skeleton such as "MMMdd"
  277. * @param capacity the capacity of skeleton.
  278. * @param pErrorCode a pointer to the UErrorCode which must not indicate a
  279. * failure before the function call.
  280. * @return the length of skeleton.
  281. * @stable ICU 3.8
  282. */
  283. U_CAPI int32_t U_EXPORT2
  284. udatpg_getSkeleton(UDateTimePatternGenerator *unusedDtpg,
  285. const UChar *pattern, int32_t length,
  286. UChar *skeleton, int32_t capacity,
  287. UErrorCode *pErrorCode);
  288. /**
  289. * Get a unique base skeleton from a given pattern. This is the same
  290. * as the skeleton, except that differences in length are minimized so
  291. * as to only preserve the difference between string and numeric form. So
  292. * for example, both "MMM-dd" and "d/MMM" produce the skeleton "MMMd"
  293. * (notice the single d).
  294. *
  295. * Note that this function uses a non-const UDateTimePatternGenerator:
  296. * It uses a stateful pattern parser which is set up for each generator object,
  297. * rather than creating one for each function call.
  298. * Consecutive calls to this function do not affect each other,
  299. * but this function cannot be used concurrently on a single generator object.
  300. *
  301. * @param unusedDtpg a pointer to UDateTimePatternGenerator.
  302. * This parameter is no longer used. Callers may pass NULL.
  303. * @param pattern input pattern, such as "dd/MMM".
  304. * @param length the length of pattern.
  305. * @param baseSkeleton such as "Md"
  306. * @param capacity the capacity of base skeleton.
  307. * @param pErrorCode a pointer to the UErrorCode which must not indicate a
  308. * failure before the function call.
  309. * @return the length of baseSkeleton.
  310. * @stable ICU 3.8
  311. */
  312. U_CAPI int32_t U_EXPORT2
  313. udatpg_getBaseSkeleton(UDateTimePatternGenerator *unusedDtpg,
  314. const UChar *pattern, int32_t length,
  315. UChar *baseSkeleton, int32_t capacity,
  316. UErrorCode *pErrorCode);
  317. /**
  318. * Adds a pattern to the generator. If the pattern has the same skeleton as
  319. * an existing pattern, and the override parameter is set, then the previous
  320. * value is overridden. Otherwise, the previous value is retained. In either
  321. * case, the conflicting status is set and previous vale is stored in
  322. * conflicting pattern.
  323. * <p>
  324. * Note that single-field patterns (like "MMM") are automatically added, and
  325. * don't need to be added explicitly!
  326. *
  327. * @param dtpg a pointer to UDateTimePatternGenerator.
  328. * @param pattern input pattern, such as "dd/MMM"
  329. * @param patternLength the length of pattern.
  330. * @param override When existing values are to be overridden use true,
  331. * otherwise use false.
  332. * @param conflictingPattern Previous pattern with the same skeleton.
  333. * @param capacity the capacity of conflictingPattern.
  334. * @param pLength a pointer to the length of conflictingPattern.
  335. * @param pErrorCode a pointer to the UErrorCode which must not indicate a
  336. * failure before the function call.
  337. * @return conflicting status. The value could be UDATPG_NO_CONFLICT,
  338. * UDATPG_BASE_CONFLICT or UDATPG_CONFLICT.
  339. * @stable ICU 3.8
  340. */
  341. U_CAPI UDateTimePatternConflict U_EXPORT2
  342. udatpg_addPattern(UDateTimePatternGenerator *dtpg,
  343. const UChar *pattern, int32_t patternLength,
  344. UBool override,
  345. UChar *conflictingPattern, int32_t capacity, int32_t *pLength,
  346. UErrorCode *pErrorCode);
  347. /**
  348. * An AppendItem format is a pattern used to append a field if there is no
  349. * good match. For example, suppose that the input skeleton is "GyyyyMMMd",
  350. * and there is no matching pattern internally, but there is a pattern
  351. * matching "yyyyMMMd", say "d-MM-yyyy". Then that pattern is used, plus the
  352. * G. The way these two are conjoined is by using the AppendItemFormat for G
  353. * (era). So if that value is, say "{0}, {1}" then the final resulting
  354. * pattern is "d-MM-yyyy, G".
  355. * <p>
  356. * There are actually three available variables: {0} is the pattern so far,
  357. * {1} is the element we are adding, and {2} is the name of the element.
  358. * <p>
  359. * This reflects the way that the CLDR data is organized.
  360. *
  361. * @param dtpg a pointer to UDateTimePatternGenerator.
  362. * @param field UDateTimePatternField, such as UDATPG_ERA_FIELD
  363. * @param value pattern, such as "{0}, {1}"
  364. * @param length the length of value.
  365. * @stable ICU 3.8
  366. */
  367. U_CAPI void U_EXPORT2
  368. udatpg_setAppendItemFormat(UDateTimePatternGenerator *dtpg,
  369. UDateTimePatternField field,
  370. const UChar *value, int32_t length);
  371. /**
  372. * Getter corresponding to setAppendItemFormat. Values below 0 or at or
  373. * above UDATPG_FIELD_COUNT are illegal arguments.
  374. *
  375. * @param dtpg A pointer to UDateTimePatternGenerator.
  376. * @param field UDateTimePatternField, such as UDATPG_ERA_FIELD
  377. * @param pLength A pointer that will receive the length of appendItemFormat.
  378. * @return appendItemFormat for field.
  379. * @stable ICU 3.8
  380. */
  381. U_CAPI const UChar * U_EXPORT2
  382. udatpg_getAppendItemFormat(const UDateTimePatternGenerator *dtpg,
  383. UDateTimePatternField field,
  384. int32_t *pLength);
  385. /**
  386. * Set the name of field, eg "era" in English for ERA. These are only
  387. * used if the corresponding AppendItemFormat is used, and if it contains a
  388. * {2} variable.
  389. * <p>
  390. * This reflects the way that the CLDR data is organized.
  391. *
  392. * @param dtpg a pointer to UDateTimePatternGenerator.
  393. * @param field UDateTimePatternField
  394. * @param value name for the field.
  395. * @param length the length of value.
  396. * @stable ICU 3.8
  397. */
  398. U_CAPI void U_EXPORT2
  399. udatpg_setAppendItemName(UDateTimePatternGenerator *dtpg,
  400. UDateTimePatternField field,
  401. const UChar *value, int32_t length);
  402. /**
  403. * Getter corresponding to setAppendItemNames. Values below 0 or at or above
  404. * UDATPG_FIELD_COUNT are illegal arguments. Note: The more general function
  405. * for getting date/time field display names is udatpg_getFieldDisplayName.
  406. *
  407. * @param dtpg a pointer to UDateTimePatternGenerator.
  408. * @param field UDateTimePatternField, such as UDATPG_ERA_FIELD
  409. * @param pLength A pointer that will receive the length of the name for field.
  410. * @return name for field
  411. * @see udatpg_getFieldDisplayName
  412. * @stable ICU 3.8
  413. */
  414. U_CAPI const UChar * U_EXPORT2
  415. udatpg_getAppendItemName(const UDateTimePatternGenerator *dtpg,
  416. UDateTimePatternField field,
  417. int32_t *pLength);
  418. /**
  419. * The general interface to get a display name for a particular date/time field,
  420. * in one of several possible display widths.
  421. *
  422. * @param dtpg
  423. * A pointer to the UDateTimePatternGenerator object with the localized
  424. * display names.
  425. * @param field
  426. * The desired UDateTimePatternField, such as UDATPG_ERA_FIELD.
  427. * @param width
  428. * The desired UDateTimePGDisplayWidth, such as UDATPG_ABBREVIATED.
  429. * @param fieldName
  430. * A pointer to a buffer to receive the NULL-terminated display name. If the name
  431. * fits into fieldName but cannot be NULL-terminated (length == capacity) then
  432. * the error code is set to U_STRING_NOT_TERMINATED_WARNING. If the name doesn't
  433. * fit into fieldName then the error code is set to U_BUFFER_OVERFLOW_ERROR.
  434. * @param capacity
  435. * The size of fieldName (in UChars).
  436. * @param pErrorCode
  437. * A pointer to a UErrorCode to receive any errors
  438. * @return
  439. * The full length of the name; if greater than capacity, fieldName contains a
  440. * truncated result.
  441. * @stable ICU 61
  442. */
  443. U_CAPI int32_t U_EXPORT2
  444. udatpg_getFieldDisplayName(const UDateTimePatternGenerator *dtpg,
  445. UDateTimePatternField field,
  446. UDateTimePGDisplayWidth width,
  447. UChar *fieldName, int32_t capacity,
  448. UErrorCode *pErrorCode);
  449. /**
  450. * The DateTimeFormat is a message format pattern used to compose date and
  451. * time patterns. The default pattern in the root locale is "{1} {0}", where
  452. * {1} will be replaced by the date pattern and {0} will be replaced by the
  453. * time pattern; however, other locales may specify patterns such as
  454. * "{1}, {0}" or "{1} 'at' {0}", etc.
  455. * <p>
  456. * This is used when the input skeleton contains both date and time fields,
  457. * but there is not a close match among the added patterns. For example,
  458. * suppose that this object was created by adding "dd-MMM" and "hh:mm", and
  459. * its DateTimeFormat is the default "{1} {0}". Then if the input skeleton
  460. * is "MMMdhmm", there is not an exact match, so the input skeleton is
  461. * broken up into two components "MMMd" and "hmm". There are close matches
  462. * for those two skeletons, so the result is put together with this pattern,
  463. * resulting in "d-MMM h:mm".
  464. *
  465. * There are four DateTimeFormats in a UDateTimePatternGenerator object,
  466. * corresponding to date styles UDAT_FULL..UDAT_SHORT. This method sets
  467. * all of them to the specified pattern. To set them individually, see
  468. * udatpg_setDateTimeFormatForStyle.
  469. *
  470. * @param dtpg a pointer to UDateTimePatternGenerator.
  471. * @param dtFormat
  472. * message format pattern, here {1} will be replaced by the date
  473. * pattern and {0} will be replaced by the time pattern.
  474. * @param length the length of dtFormat.
  475. * @stable ICU 3.8
  476. */
  477. U_CAPI void U_EXPORT2
  478. udatpg_setDateTimeFormat(const UDateTimePatternGenerator *dtpg,
  479. const UChar *dtFormat, int32_t length);
  480. /**
  481. * Getter corresponding to setDateTimeFormat.
  482. *
  483. * There are four DateTimeFormats in a UDateTimePatternGenerator object,
  484. * corresponding to date styles UDAT_FULL..UDAT_SHORT. This method gets
  485. * the style for UDAT_MEDIUM (the default). To get them individually, see
  486. * udatpg_getDateTimeFormatForStyle.
  487. *
  488. * @param dtpg a pointer to UDateTimePatternGenerator.
  489. * @param pLength A pointer that will receive the length of the format
  490. * @return dateTimeFormat.
  491. * @stable ICU 3.8
  492. */
  493. U_CAPI const UChar * U_EXPORT2
  494. udatpg_getDateTimeFormat(const UDateTimePatternGenerator *dtpg,
  495. int32_t *pLength);
  496. #if !UCONFIG_NO_FORMATTING
  497. /**
  498. * dateTimeFormats are message patterns used to compose combinations of date
  499. * and time patterns. There are four length styles, corresponding to the
  500. * inferred style of the date pattern; these are UDateFormatStyle values:
  501. * - UDAT_FULL (for date pattern with weekday and long month), else
  502. * - UDAT_LONG (for a date pattern with long month), else
  503. * - UDAT_MEDIUM (for a date pattern with abbreviated month), else
  504. * - UDAT_SHORT (for any other date pattern).
  505. * For details on dateTimeFormats, see
  506. * https://www.unicode.org/reports/tr35/tr35-dates.html#dateTimeFormats.
  507. * The default pattern in the root locale for all styles is "{1} {0}".
  508. *
  509. * @param udtpg
  510. * a pointer to the UDateTimePatternGenerator
  511. * @param style
  512. * one of UDAT_FULL..UDAT_SHORT. Error if out of range.
  513. * @param dateTimeFormat
  514. * the new dateTimeFormat to set for the the specified style
  515. * @param length
  516. * the length of dateTimeFormat, or -1 if unknown and pattern
  517. * is null-terminated
  518. * @param pErrorCode
  519. * a pointer to the UErrorCode (in/out parameter); if no failure
  520. * status is already set, it will be set according to result of the
  521. * function (e.g. U_ILLEGAL_ARGUMENT_ERROR for style out of range).
  522. * @stable ICU 71
  523. */
  524. U_CAPI void U_EXPORT2
  525. udatpg_setDateTimeFormatForStyle(UDateTimePatternGenerator *udtpg,
  526. UDateFormatStyle style,
  527. const UChar *dateTimeFormat, int32_t length,
  528. UErrorCode *pErrorCode);
  529. /**
  530. * Getter corresponding to udatpg_setDateTimeFormatForStyle.
  531. *
  532. * @param udtpg
  533. * a pointer to the UDateTimePatternGenerator
  534. * @param style
  535. * one of UDAT_FULL..UDAT_SHORT. Error if out of range.
  536. * @param pLength
  537. * a pointer that will receive the length of the format. May be NULL
  538. * if length is not desired.
  539. * @param pErrorCode
  540. * a pointer to the UErrorCode (in/out parameter); if no failure
  541. * status is already set, it will be set according to result of the
  542. * function (e.g. U_ILLEGAL_ARGUMENT_ERROR for style out of range).
  543. * @return
  544. * pointer to the current dateTimeFormat (0 terminated) for the specified
  545. * style, or empty string in case of error. The pointer and its contents
  546. * may no longer be valid if udatpg_setDateTimeFormat is called, or
  547. * udatpg_setDateTimeFormatForStyle for the same style is called, or the
  548. * UDateTimePatternGenerator object is closed.
  549. * @stable ICU 71
  550. */
  551. U_CAPI const UChar* U_EXPORT2
  552. udatpg_getDateTimeFormatForStyle(const UDateTimePatternGenerator *udtpg,
  553. UDateFormatStyle style, int32_t *pLength,
  554. UErrorCode *pErrorCode);
  555. #endif /* #if !UCONFIG_NO_FORMATTING */
  556. /**
  557. * The decimal value is used in formatting fractions of seconds. If the
  558. * skeleton contains fractional seconds, then this is used with the
  559. * fractional seconds. For example, suppose that the input pattern is
  560. * "hhmmssSSSS", and the best matching pattern internally is "H:mm:ss", and
  561. * the decimal string is ",". Then the resulting pattern is modified to be
  562. * "H:mm:ss,SSSS"
  563. *
  564. * @param dtpg a pointer to UDateTimePatternGenerator.
  565. * @param decimal
  566. * @param length the length of decimal.
  567. * @stable ICU 3.8
  568. */
  569. U_CAPI void U_EXPORT2
  570. udatpg_setDecimal(UDateTimePatternGenerator *dtpg,
  571. const UChar *decimal, int32_t length);
  572. /**
  573. * Getter corresponding to setDecimal.
  574. *
  575. * @param dtpg a pointer to UDateTimePatternGenerator.
  576. * @param pLength A pointer that will receive the length of the decimal string.
  577. * @return corresponding to the decimal point.
  578. * @stable ICU 3.8
  579. */
  580. U_CAPI const UChar * U_EXPORT2
  581. udatpg_getDecimal(const UDateTimePatternGenerator *dtpg,
  582. int32_t *pLength);
  583. /**
  584. * Adjusts the field types (width and subtype) of a pattern to match what is
  585. * in a skeleton. That is, if you supply a pattern like "d-M H:m", and a
  586. * skeleton of "MMMMddhhmm", then the input pattern is adjusted to be
  587. * "dd-MMMM hh:mm". This is used internally to get the best match for the
  588. * input skeleton, but can also be used externally.
  589. *
  590. * Note that this function uses a non-const UDateTimePatternGenerator:
  591. * It uses a stateful pattern parser which is set up for each generator object,
  592. * rather than creating one for each function call.
  593. * Consecutive calls to this function do not affect each other,
  594. * but this function cannot be used concurrently on a single generator object.
  595. *
  596. * @param dtpg a pointer to UDateTimePatternGenerator.
  597. * @param pattern Input pattern
  598. * @param patternLength the length of input pattern.
  599. * @param skeleton
  600. * @param skeletonLength the length of input skeleton.
  601. * @param dest pattern adjusted to match the skeleton fields widths and subtypes.
  602. * @param destCapacity the capacity of dest.
  603. * @param pErrorCode a pointer to the UErrorCode which must not indicate a
  604. * failure before the function call.
  605. * @return the length of dest.
  606. * @stable ICU 3.8
  607. */
  608. U_CAPI int32_t U_EXPORT2
  609. udatpg_replaceFieldTypes(UDateTimePatternGenerator *dtpg,
  610. const UChar *pattern, int32_t patternLength,
  611. const UChar *skeleton, int32_t skeletonLength,
  612. UChar *dest, int32_t destCapacity,
  613. UErrorCode *pErrorCode);
  614. /**
  615. * Adjusts the field types (width and subtype) of a pattern to match what is
  616. * in a skeleton. That is, if you supply a pattern like "d-M H:m", and a
  617. * skeleton of "MMMMddhhmm", then the input pattern is adjusted to be
  618. * "dd-MMMM hh:mm". This is used internally to get the best match for the
  619. * input skeleton, but can also be used externally.
  620. *
  621. * Note that this function uses a non-const UDateTimePatternGenerator:
  622. * It uses a stateful pattern parser which is set up for each generator object,
  623. * rather than creating one for each function call.
  624. * Consecutive calls to this function do not affect each other,
  625. * but this function cannot be used concurrently on a single generator object.
  626. *
  627. * @param dtpg a pointer to UDateTimePatternGenerator.
  628. * @param pattern Input pattern
  629. * @param patternLength the length of input pattern.
  630. * @param skeleton
  631. * @param skeletonLength the length of input skeleton.
  632. * @param options
  633. * Options controlling whether the length of specified fields in the
  634. * pattern are adjusted to match those in the skeleton (when this
  635. * would not happen otherwise). For default behavior, use
  636. * UDATPG_MATCH_NO_OPTIONS.
  637. * @param dest pattern adjusted to match the skeleton fields widths and subtypes.
  638. * @param destCapacity the capacity of dest.
  639. * @param pErrorCode a pointer to the UErrorCode which must not indicate a
  640. * failure before the function call.
  641. * @return the length of dest.
  642. * @stable ICU 4.4
  643. */
  644. U_CAPI int32_t U_EXPORT2
  645. udatpg_replaceFieldTypesWithOptions(UDateTimePatternGenerator *dtpg,
  646. const UChar *pattern, int32_t patternLength,
  647. const UChar *skeleton, int32_t skeletonLength,
  648. UDateTimePatternMatchOptions options,
  649. UChar *dest, int32_t destCapacity,
  650. UErrorCode *pErrorCode);
  651. /**
  652. * Return a UEnumeration list of all the skeletons in canonical form.
  653. * Call udatpg_getPatternForSkeleton() to get the corresponding pattern.
  654. *
  655. * @param dtpg a pointer to UDateTimePatternGenerator.
  656. * @param pErrorCode a pointer to the UErrorCode which must not indicate a
  657. * failure before the function call
  658. * @return a UEnumeration list of all the skeletons
  659. * The caller must close the object.
  660. * @stable ICU 3.8
  661. */
  662. U_CAPI UEnumeration * U_EXPORT2
  663. udatpg_openSkeletons(const UDateTimePatternGenerator *dtpg, UErrorCode *pErrorCode);
  664. /**
  665. * Return a UEnumeration list of all the base skeletons in canonical form.
  666. *
  667. * @param dtpg a pointer to UDateTimePatternGenerator.
  668. * @param pErrorCode a pointer to the UErrorCode which must not indicate a
  669. * failure before the function call.
  670. * @return a UEnumeration list of all the base skeletons
  671. * The caller must close the object.
  672. * @stable ICU 3.8
  673. */
  674. U_CAPI UEnumeration * U_EXPORT2
  675. udatpg_openBaseSkeletons(const UDateTimePatternGenerator *dtpg, UErrorCode *pErrorCode);
  676. /**
  677. * Get the pattern corresponding to a given skeleton.
  678. *
  679. * @param dtpg a pointer to UDateTimePatternGenerator.
  680. * @param skeleton
  681. * @param skeletonLength pointer to the length of skeleton.
  682. * @param pLength pointer to the length of return pattern.
  683. * @return pattern corresponding to a given skeleton.
  684. * @stable ICU 3.8
  685. */
  686. U_CAPI const UChar * U_EXPORT2
  687. udatpg_getPatternForSkeleton(const UDateTimePatternGenerator *dtpg,
  688. const UChar *skeleton, int32_t skeletonLength,
  689. int32_t *pLength);
  690. #if !UCONFIG_NO_FORMATTING
  691. /**
  692. * Return the default hour cycle for a locale. Uses the locale that the
  693. * UDateTimePatternGenerator was initially created with.
  694. *
  695. * Cannot be used on an empty UDateTimePatternGenerator instance.
  696. *
  697. * @param dtpg a pointer to UDateTimePatternGenerator.
  698. * @param pErrorCode a pointer to the UErrorCode which must not indicate a
  699. * failure before the function call. Set to U_UNSUPPORTED_ERROR
  700. * if used on an empty instance.
  701. * @return the default hour cycle.
  702. * @stable ICU 67
  703. */
  704. U_CAPI UDateFormatHourCycle U_EXPORT2
  705. udatpg_getDefaultHourCycle(const UDateTimePatternGenerator *dtpg, UErrorCode* pErrorCode);
  706. #endif /* #if !UCONFIG_NO_FORMATTING */
  707. #endif