ucal.h 64 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770
  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-2015, International Business Machines Corporation and
  6. * others. All Rights Reserved.
  7. *******************************************************************************
  8. */
  9. #ifndef UCAL_H
  10. #define UCAL_H
  11. #include "unicode/utypes.h"
  12. #include "unicode/uenum.h"
  13. #include "unicode/uloc.h"
  14. #if U_SHOW_CPLUSPLUS_API
  15. #include "unicode/localpointer.h"
  16. #endif // U_SHOW_CPLUSPLUS_API
  17. #if !UCONFIG_NO_FORMATTING
  18. /**
  19. * \file
  20. * \brief C API: Calendar
  21. *
  22. * <h2>Calendar C API</h2>
  23. *
  24. * UCalendar C API is used for converting between a <code>UDate</code> object
  25. * and a set of integer fields such as <code>UCAL_YEAR</code>, <code>UCAL_MONTH</code>,
  26. * <code>UCAL_DAY</code>, <code>UCAL_HOUR</code>, and so on.
  27. * (A <code>UDate</code> object represents a specific instant in
  28. * time with millisecond precision. See UDate
  29. * for information about the <code>UDate</code> .)
  30. *
  31. * <p>
  32. * Types of <code>UCalendar</code> interpret a <code>UDate</code>
  33. * according to the rules of a specific calendar system. The C API
  34. * provides the enum UCalendarType with UCAL_TRADITIONAL and
  35. * UCAL_GREGORIAN.
  36. * <p>
  37. * Like other locale-sensitive C API, calendar API provides a
  38. * function, <code>ucal_open()</code>, which returns a pointer to
  39. * <code>UCalendar</code> whose time fields have been initialized
  40. * with the current date and time. We need to specify the type of
  41. * calendar to be opened and the timezoneId.
  42. * \htmlonly<blockquote>\endhtmlonly
  43. * <pre>
  44. * \code
  45. * UCalendar *caldef;
  46. * UChar *tzId;
  47. * UErrorCode status;
  48. * tzId=(UChar*)malloc(sizeof(UChar) * (strlen("PST") +1) );
  49. * u_uastrcpy(tzId, "PST");
  50. * caldef=ucal_open(tzID, u_strlen(tzID), NULL, UCAL_TRADITIONAL, &status);
  51. * \endcode
  52. * </pre>
  53. * \htmlonly</blockquote>\endhtmlonly
  54. *
  55. * <p>
  56. * A <code>UCalendar</code> object can produce all the time field values
  57. * needed to implement the date-time formatting for a particular language
  58. * and calendar style (for example, Japanese-Gregorian, Japanese-Traditional).
  59. *
  60. * <p>
  61. * When computing a <code>UDate</code> from time fields, two special circumstances
  62. * may arise: there may be insufficient information to compute the
  63. * <code>UDate</code> (such as only year and month but no day in the month),
  64. * or there may be inconsistent information (such as "Tuesday, July 15, 1996"
  65. * -- July 15, 1996 is actually a Monday).
  66. *
  67. * <p>
  68. * <strong>Insufficient information.</strong> The calendar will use default
  69. * information to specify the missing fields. This may vary by calendar; for
  70. * the Gregorian calendar, the default for a field is the same as that of the
  71. * start of the epoch: i.e., UCAL_YEAR = 1970, UCAL_MONTH = JANUARY, UCAL_DATE = 1, etc.
  72. *
  73. * <p>
  74. * <strong>Inconsistent information.</strong> If fields conflict, the calendar
  75. * will give preference to fields set more recently. For example, when
  76. * determining the day, the calendar will look for one of the following
  77. * combinations of fields. The most recent combination, as determined by the
  78. * most recently set single field, will be used.
  79. *
  80. * \htmlonly<blockquote>\endhtmlonly
  81. * <pre>
  82. * \code
  83. * UCAL_MONTH + UCAL_DAY_OF_MONTH
  84. * UCAL_MONTH + UCAL_WEEK_OF_MONTH + UCAL_DAY_OF_WEEK
  85. * UCAL_MONTH + UCAL_DAY_OF_WEEK_IN_MONTH + UCAL_DAY_OF_WEEK
  86. * UCAL_DAY_OF_YEAR
  87. * UCAL_DAY_OF_WEEK + UCAL_WEEK_OF_YEAR
  88. * \endcode
  89. * </pre>
  90. * \htmlonly</blockquote>\endhtmlonly
  91. *
  92. * For the time of day:
  93. *
  94. * \htmlonly<blockquote>\endhtmlonly
  95. * <pre>
  96. * \code
  97. * UCAL_HOUR_OF_DAY
  98. * UCAL_AM_PM + UCAL_HOUR
  99. * \endcode
  100. * </pre>
  101. * \htmlonly</blockquote>\endhtmlonly
  102. *
  103. * <p>
  104. * <strong>Note:</strong> for some non-Gregorian calendars, different
  105. * fields may be necessary for complete disambiguation. For example, a full
  106. * specification of the historical Arabic astronomical calendar requires year,
  107. * month, day-of-month <em>and</em> day-of-week in some cases.
  108. *
  109. * <p>
  110. * <strong>Note:</strong> There are certain possible ambiguities in
  111. * interpretation of certain singular times, which are resolved in the
  112. * following ways:
  113. * <ol>
  114. * <li> 24:00:00 "belongs" to the following day. That is,
  115. * 23:59 on Dec 31, 1969 &lt; 24:00 on Jan 1, 1970 &lt; 24:01:00 on Jan 1, 1970
  116. *
  117. * <li> Although historically not precise, midnight also belongs to "am",
  118. * and noon belongs to "pm", so on the same day,
  119. * 12:00 am (midnight) &lt; 12:01 am, and 12:00 pm (noon) &lt; 12:01 pm
  120. * </ol>
  121. *
  122. * <p>
  123. * The date or time format strings are not part of the definition of a
  124. * calendar, as those must be modifiable or overridable by the user at
  125. * runtime. Use {@link icu::DateFormat}
  126. * to format dates.
  127. *
  128. * <p>
  129. * <code>Calendar</code> provides an API for field "rolling", where fields
  130. * can be incremented or decremented, but wrap around. For example, rolling the
  131. * month up in the date <code>December 12, <b>1996</b></code> results in
  132. * <code>January 12, <b>1996</b></code>.
  133. *
  134. * <p>
  135. * <code>Calendar</code> also provides a date arithmetic function for
  136. * adding the specified (signed) amount of time to a particular time field.
  137. * For example, subtracting 5 days from the date <code>September 12, 1996</code>
  138. * results in <code>September 7, 1996</code>.
  139. *
  140. * <p>
  141. * The Japanese calendar uses a combination of era name and year number.
  142. * When an emperor of Japan abdicates and a new emperor ascends the throne,
  143. * a new era is declared and year number is reset to 1. Even if the date of
  144. * abdication is scheduled ahead of time, the new era name might not be
  145. * announced until just before the date. In such case, ICU4C may include
  146. * a start date of future era without actual era name, but not enabled
  147. * by default. ICU4C users who want to test the behavior of the future era
  148. * can enable the tentative era by:
  149. * <ul>
  150. * <li>Environment variable <code>ICU_ENABLE_TENTATIVE_ERA=true</code>.</li>
  151. * </ul>
  152. *
  153. * @stable ICU 2.0
  154. */
  155. /**
  156. * The time zone ID reserved for unknown time zone.
  157. * It behaves like the GMT/UTC time zone but has the special ID "Etc/Unknown".
  158. * @stable ICU 4.8
  159. */
  160. #define UCAL_UNKNOWN_ZONE_ID "Etc/Unknown"
  161. /** A calendar.
  162. * For usage in C programs.
  163. * @stable ICU 2.0
  164. */
  165. typedef void* UCalendar;
  166. /** Possible types of UCalendars
  167. * @stable ICU 2.0
  168. */
  169. enum UCalendarType {
  170. /**
  171. * Despite the name, UCAL_TRADITIONAL designates the locale's default calendar,
  172. * which may be the Gregorian calendar or some other calendar.
  173. * @stable ICU 2.0
  174. */
  175. UCAL_TRADITIONAL,
  176. /**
  177. * A better name for UCAL_TRADITIONAL.
  178. * @stable ICU 4.2
  179. */
  180. UCAL_DEFAULT = UCAL_TRADITIONAL,
  181. /**
  182. * Unambiguously designates the Gregorian calendar for the locale.
  183. * @stable ICU 2.0
  184. */
  185. UCAL_GREGORIAN
  186. };
  187. /** @stable ICU 2.0 */
  188. typedef enum UCalendarType UCalendarType;
  189. /** Possible fields in a UCalendar
  190. * @stable ICU 2.0
  191. */
  192. enum UCalendarDateFields {
  193. /**
  194. * Field number indicating the era, e.g., AD or BC in the Gregorian (Julian) calendar.
  195. * This is a calendar-specific value.
  196. * @stable ICU 2.6
  197. */
  198. UCAL_ERA,
  199. /**
  200. * Field number indicating the year. This is a calendar-specific value.
  201. * @stable ICU 2.6
  202. */
  203. UCAL_YEAR,
  204. /**
  205. * Field number indicating the month. This is a calendar-specific value.
  206. * The first month of the year is
  207. * <code>JANUARY</code>; the last depends on the number of months in a year.
  208. * @see #UCAL_JANUARY
  209. * @see #UCAL_FEBRUARY
  210. * @see #UCAL_MARCH
  211. * @see #UCAL_APRIL
  212. * @see #UCAL_MAY
  213. * @see #UCAL_JUNE
  214. * @see #UCAL_JULY
  215. * @see #UCAL_AUGUST
  216. * @see #UCAL_SEPTEMBER
  217. * @see #UCAL_OCTOBER
  218. * @see #UCAL_NOVEMBER
  219. * @see #UCAL_DECEMBER
  220. * @see #UCAL_UNDECIMBER
  221. * @stable ICU 2.6
  222. */
  223. UCAL_MONTH,
  224. /**
  225. * Field number indicating the
  226. * week number within the current year. The first week of the year, as
  227. * defined by <code>UCAL_FIRST_DAY_OF_WEEK</code> and <code>UCAL_MINIMAL_DAYS_IN_FIRST_WEEK</code>
  228. * attributes, has value 1. Subclasses define
  229. * the value of <code>UCAL_WEEK_OF_YEAR</code> for days before the first week of
  230. * the year.
  231. * @see ucal_getAttribute
  232. * @see ucal_setAttribute
  233. * @stable ICU 2.6
  234. */
  235. UCAL_WEEK_OF_YEAR,
  236. /**
  237. * Field number indicating the
  238. * week number within the current month. The first week of the month, as
  239. * defined by <code>UCAL_FIRST_DAY_OF_WEEK</code> and <code>UCAL_MINIMAL_DAYS_IN_FIRST_WEEK</code>
  240. * attributes, has value 1. Subclasses define
  241. * the value of <code>WEEK_OF_MONTH</code> for days before the first week of
  242. * the month.
  243. * @see ucal_getAttribute
  244. * @see ucal_setAttribute
  245. * @see #UCAL_FIRST_DAY_OF_WEEK
  246. * @see #UCAL_MINIMAL_DAYS_IN_FIRST_WEEK
  247. * @stable ICU 2.6
  248. */
  249. UCAL_WEEK_OF_MONTH,
  250. /**
  251. * Field number indicating the
  252. * day of the month. This is a synonym for <code>DAY_OF_MONTH</code>.
  253. * The first day of the month has value 1.
  254. * @see #UCAL_DAY_OF_MONTH
  255. * @stable ICU 2.6
  256. */
  257. UCAL_DATE,
  258. /**
  259. * Field number indicating the day
  260. * number within the current year. The first day of the year has value 1.
  261. * @stable ICU 2.6
  262. */
  263. UCAL_DAY_OF_YEAR,
  264. /**
  265. * Field number indicating the day
  266. * of the week. This field takes values <code>SUNDAY</code>,
  267. * <code>MONDAY</code>, <code>TUESDAY</code>, <code>WEDNESDAY</code>,
  268. * <code>THURSDAY</code>, <code>FRIDAY</code>, and <code>SATURDAY</code>.
  269. * @see #UCAL_SUNDAY
  270. * @see #UCAL_MONDAY
  271. * @see #UCAL_TUESDAY
  272. * @see #UCAL_WEDNESDAY
  273. * @see #UCAL_THURSDAY
  274. * @see #UCAL_FRIDAY
  275. * @see #UCAL_SATURDAY
  276. * @stable ICU 2.6
  277. */
  278. UCAL_DAY_OF_WEEK,
  279. /**
  280. * Field number indicating the
  281. * ordinal number of the day of the week within the current month. Together
  282. * with the <code>DAY_OF_WEEK</code> field, this uniquely specifies a day
  283. * within a month. Unlike <code>WEEK_OF_MONTH</code> and
  284. * <code>WEEK_OF_YEAR</code>, this field's value does <em>not</em> depend on
  285. * <code>getFirstDayOfWeek()</code> or
  286. * <code>getMinimalDaysInFirstWeek()</code>. <code>DAY_OF_MONTH 1</code>
  287. * through <code>7</code> always correspond to <code>DAY_OF_WEEK_IN_MONTH
  288. * 1</code>; <code>8</code> through <code>15</code> correspond to
  289. * <code>DAY_OF_WEEK_IN_MONTH 2</code>, and so on.
  290. * <code>DAY_OF_WEEK_IN_MONTH 0</code> indicates the week before
  291. * <code>DAY_OF_WEEK_IN_MONTH 1</code>. Negative values count back from the
  292. * end of the month, so the last Sunday of a month is specified as
  293. * <code>DAY_OF_WEEK = SUNDAY, DAY_OF_WEEK_IN_MONTH = -1</code>. Because
  294. * negative values count backward they will usually be aligned differently
  295. * within the month than positive values. For example, if a month has 31
  296. * days, <code>DAY_OF_WEEK_IN_MONTH -1</code> will overlap
  297. * <code>DAY_OF_WEEK_IN_MONTH 5</code> and the end of <code>4</code>.
  298. * @see #UCAL_DAY_OF_WEEK
  299. * @see #UCAL_WEEK_OF_MONTH
  300. * @stable ICU 2.6
  301. */
  302. UCAL_DAY_OF_WEEK_IN_MONTH,
  303. /**
  304. * Field number indicating
  305. * whether the <code>HOUR</code> is before or after noon.
  306. * E.g., at 10:04:15.250 PM the <code>AM_PM</code> is <code>PM</code>.
  307. * @see #UCAL_AM
  308. * @see #UCAL_PM
  309. * @see #UCAL_HOUR
  310. * @stable ICU 2.6
  311. */
  312. UCAL_AM_PM,
  313. /**
  314. * Field number indicating the
  315. * hour of the morning or afternoon. <code>HOUR</code> is used for the 12-hour
  316. * clock.
  317. * E.g., at 10:04:15.250 PM the <code>HOUR</code> is 10.
  318. * @see #UCAL_AM_PM
  319. * @see #UCAL_HOUR_OF_DAY
  320. * @stable ICU 2.6
  321. */
  322. UCAL_HOUR,
  323. /**
  324. * Field number indicating the
  325. * hour of the day. <code>HOUR_OF_DAY</code> is used for the 24-hour clock.
  326. * E.g., at 10:04:15.250 PM the <code>HOUR_OF_DAY</code> is 22.
  327. * @see #UCAL_HOUR
  328. * @stable ICU 2.6
  329. */
  330. UCAL_HOUR_OF_DAY,
  331. /**
  332. * Field number indicating the
  333. * minute within the hour.
  334. * E.g., at 10:04:15.250 PM the <code>UCAL_MINUTE</code> is 4.
  335. * @stable ICU 2.6
  336. */
  337. UCAL_MINUTE,
  338. /**
  339. * Field number indicating the
  340. * second within the minute.
  341. * E.g., at 10:04:15.250 PM the <code>UCAL_SECOND</code> is 15.
  342. * @stable ICU 2.6
  343. */
  344. UCAL_SECOND,
  345. /**
  346. * Field number indicating the
  347. * millisecond within the second.
  348. * E.g., at 10:04:15.250 PM the <code>UCAL_MILLISECOND</code> is 250.
  349. * @stable ICU 2.6
  350. */
  351. UCAL_MILLISECOND,
  352. /**
  353. * Field number indicating the
  354. * raw offset from GMT in milliseconds.
  355. * @stable ICU 2.6
  356. */
  357. UCAL_ZONE_OFFSET,
  358. /**
  359. * Field number indicating the
  360. * daylight savings offset in milliseconds.
  361. * @stable ICU 2.6
  362. */
  363. UCAL_DST_OFFSET,
  364. /**
  365. * Field number
  366. * indicating the extended year corresponding to the
  367. * <code>UCAL_WEEK_OF_YEAR</code> field. This may be one greater or less
  368. * than the value of <code>UCAL_EXTENDED_YEAR</code>.
  369. * @stable ICU 2.6
  370. */
  371. UCAL_YEAR_WOY,
  372. /**
  373. * Field number
  374. * indicating the localized day of week. This will be a value from 1
  375. * to 7 inclusive, with 1 being the localized first day of the week.
  376. * @stable ICU 2.6
  377. */
  378. UCAL_DOW_LOCAL,
  379. /**
  380. * Year of this calendar system, encompassing all supra-year fields. For example,
  381. * in Gregorian/Julian calendars, positive Extended Year values indicate years AD,
  382. * 1 BC = 0 extended, 2 BC = -1 extended, and so on.
  383. * @stable ICU 2.8
  384. */
  385. UCAL_EXTENDED_YEAR,
  386. /**
  387. * Field number
  388. * indicating the modified Julian day number. This is different from
  389. * the conventional Julian day number in two regards. First, it
  390. * demarcates days at local zone midnight, rather than noon GMT.
  391. * Second, it is a local number; that is, it depends on the local time
  392. * zone. It can be thought of as a single number that encompasses all
  393. * the date-related fields.
  394. * @stable ICU 2.8
  395. */
  396. UCAL_JULIAN_DAY,
  397. /**
  398. * Ranges from 0 to 23:59:59.999 (regardless of DST). This field behaves <em>exactly</em>
  399. * like a composite of all time-related fields, not including the zone fields. As such,
  400. * it also reflects discontinuities of those fields on DST transition days. On a day
  401. * of DST onset, it will jump forward. On a day of DST cessation, it will jump
  402. * backward. This reflects the fact that it must be combined with the DST_OFFSET field
  403. * to obtain a unique local time value.
  404. * @stable ICU 2.8
  405. */
  406. UCAL_MILLISECONDS_IN_DAY,
  407. /**
  408. * Whether or not the current month is a leap month (0 or 1). See the Chinese calendar for
  409. * an example of this.
  410. */
  411. UCAL_IS_LEAP_MONTH,
  412. /**
  413. * Field number indicating the month. This is a calendar-specific value.
  414. * Differ from UCAL_MONTH, this value is continuous and unique within a
  415. * year and range from 0 to 11 or 0 to 12 depending on how many months in a
  416. * year, the calendar system has leap month or not, and in leap year or not.
  417. * It is the ordinal position of that month in the corresponding year of
  418. * the calendar. For Chinese, Dangi, and Hebrew calendar, the range is
  419. * 0 to 11 in non-leap years and 0 to 12 in leap years. For Coptic and Ethiopian
  420. * calendar, the range is always 0 to 12. For other calendars supported by
  421. * ICU now, the range is 0 to 11. When the number of months in a year of the
  422. * identified calendar is variable, a different UCAL_ORDINAL_MONTH value can
  423. * be used for dates that are part of the same named month in different years.
  424. * For example, in the Hebrew calendar, "1 Nisan 5781" is associated with
  425. * UCAL_ORDINAL_MONTH value 6 while "1 Nisan 5782" is associated with
  426. * UCAL_ORDINAL_MONTH value 7 because 5782 is a leap year and Nisan follows
  427. * the insertion of Adar I. In Chinese calendar, "Year 4664 Month 6 Day 2"
  428. * is associated with UCAL_ORDINAL_MONTH value 5 while "Year 4665 Month 6 Day 2"
  429. * is associated with UCAL_ORDINAL_MONTH value 6 because 4665 is a leap year
  430. * and there is an extra "Leap Month 5" which associated with UCAL_ORDINAL_MONTH
  431. * value 5 before "Month 6" of year 4664.
  432. *
  433. * @stable ICU 73
  434. */
  435. UCAL_ORDINAL_MONTH,
  436. /* Do not conditionalize the following with #ifndef U_HIDE_DEPRECATED_API,
  437. * it is needed for layout of Calendar, DateFormat, and other objects */
  438. #ifndef U_FORCE_HIDE_DEPRECATED_API
  439. /**
  440. * One more than the highest normal UCalendarDateFields value.
  441. * @deprecated ICU 58 The numeric value may change over time, see ICU ticket #12420.
  442. */
  443. UCAL_FIELD_COUNT = UCAL_ORDINAL_MONTH + 1,
  444. #endif // U_FORCE_HIDE_DEPRECATED_API
  445. /**
  446. * Field number indicating the
  447. * day of the month. This is a synonym for <code>UCAL_DATE</code>.
  448. * The first day of the month has value 1.
  449. * @see #UCAL_DATE
  450. * Synonym for UCAL_DATE
  451. * @stable ICU 2.8
  452. **/
  453. UCAL_DAY_OF_MONTH=UCAL_DATE
  454. };
  455. /** @stable ICU 2.0 */
  456. typedef enum UCalendarDateFields UCalendarDateFields;
  457. /**
  458. * Useful constant for days of week. Note: Calendar day-of-week is 1-based. Clients
  459. * who create locale resources for the field of first-day-of-week should be aware of
  460. * this. For instance, in US locale, first-day-of-week is set to 1, i.e., UCAL_SUNDAY.
  461. */
  462. /** Possible days of the week in a UCalendar
  463. * @stable ICU 2.0
  464. */
  465. enum UCalendarDaysOfWeek {
  466. /** Sunday */
  467. UCAL_SUNDAY = 1,
  468. /** Monday */
  469. UCAL_MONDAY,
  470. /** Tuesday */
  471. UCAL_TUESDAY,
  472. /** Wednesday */
  473. UCAL_WEDNESDAY,
  474. /** Thursday */
  475. UCAL_THURSDAY,
  476. /** Friday */
  477. UCAL_FRIDAY,
  478. /** Saturday */
  479. UCAL_SATURDAY
  480. };
  481. /** @stable ICU 2.0 */
  482. typedef enum UCalendarDaysOfWeek UCalendarDaysOfWeek;
  483. /** Possible months in a UCalendar. Note: Calendar month is 0-based.
  484. * @stable ICU 2.0
  485. */
  486. enum UCalendarMonths {
  487. /** January */
  488. UCAL_JANUARY,
  489. /** February */
  490. UCAL_FEBRUARY,
  491. /** March */
  492. UCAL_MARCH,
  493. /** April */
  494. UCAL_APRIL,
  495. /** May */
  496. UCAL_MAY,
  497. /** June */
  498. UCAL_JUNE,
  499. /** July */
  500. UCAL_JULY,
  501. /** August */
  502. UCAL_AUGUST,
  503. /** September */
  504. UCAL_SEPTEMBER,
  505. /** October */
  506. UCAL_OCTOBER,
  507. /** November */
  508. UCAL_NOVEMBER,
  509. /** December */
  510. UCAL_DECEMBER,
  511. /** Value of the <code>UCAL_MONTH</code> field indicating the
  512. * thirteenth month of the year. Although the Gregorian calendar
  513. * does not use this value, lunar calendars do.
  514. */
  515. UCAL_UNDECIMBER
  516. };
  517. /** @stable ICU 2.0 */
  518. typedef enum UCalendarMonths UCalendarMonths;
  519. /** Possible AM/PM values in a UCalendar
  520. * @stable ICU 2.0
  521. */
  522. enum UCalendarAMPMs {
  523. /** AM */
  524. UCAL_AM,
  525. /** PM */
  526. UCAL_PM
  527. };
  528. /** @stable ICU 2.0 */
  529. typedef enum UCalendarAMPMs UCalendarAMPMs;
  530. /**
  531. * System time zone type constants used by filtering zones
  532. * in ucal_openTimeZoneIDEnumeration.
  533. * @see ucal_openTimeZoneIDEnumeration
  534. * @stable ICU 4.8
  535. */
  536. enum USystemTimeZoneType {
  537. /**
  538. * Any system zones.
  539. * @stable ICU 4.8
  540. */
  541. UCAL_ZONE_TYPE_ANY,
  542. /**
  543. * Canonical system zones.
  544. * @stable ICU 4.8
  545. */
  546. UCAL_ZONE_TYPE_CANONICAL,
  547. /**
  548. * Canonical system zones associated with actual locations.
  549. * @stable ICU 4.8
  550. */
  551. UCAL_ZONE_TYPE_CANONICAL_LOCATION
  552. };
  553. /** @stable ICU 4.8 */
  554. typedef enum USystemTimeZoneType USystemTimeZoneType;
  555. /**
  556. * Create an enumeration over system time zone IDs with the given
  557. * filter conditions.
  558. * @param zoneType The system time zone type.
  559. * @param region The ISO 3166 two-letter country code or UN M.49
  560. * three-digit area code. When NULL, no filtering
  561. * done by region.
  562. * @param rawOffset An offset from GMT in milliseconds, ignoring the
  563. * effect of daylight savings time, if any. When NULL,
  564. * no filtering done by zone offset.
  565. * @param ec A pointer to an UErrorCode to receive any errors
  566. * @return an enumeration object that the caller must dispose of
  567. * using enum_close(), or NULL upon failure. In case of failure,
  568. * *ec will indicate the error.
  569. * @stable ICU 4.8
  570. */
  571. U_CAPI UEnumeration* U_EXPORT2
  572. ucal_openTimeZoneIDEnumeration(USystemTimeZoneType zoneType, const char* region,
  573. const int32_t* rawOffset, UErrorCode* ec);
  574. /**
  575. * Create an enumeration over all time zones.
  576. *
  577. * @param ec input/output error code
  578. *
  579. * @return an enumeration object that the caller must dispose of using
  580. * uenum_close(), or NULL upon failure. In case of failure *ec will
  581. * indicate the error.
  582. *
  583. * @stable ICU 2.6
  584. */
  585. U_CAPI UEnumeration* U_EXPORT2
  586. ucal_openTimeZones(UErrorCode* ec);
  587. /**
  588. * Create an enumeration over all time zones associated with the given
  589. * country. Some zones are affiliated with no country (e.g., "UTC");
  590. * these may also be retrieved, as a group.
  591. *
  592. * @param country the ISO 3166 two-letter country code, or NULL to
  593. * retrieve zones not affiliated with any country
  594. *
  595. * @param ec input/output error code
  596. *
  597. * @return an enumeration object that the caller must dispose of using
  598. * uenum_close(), or NULL upon failure. In case of failure *ec will
  599. * indicate the error.
  600. *
  601. * @stable ICU 2.6
  602. */
  603. U_CAPI UEnumeration* U_EXPORT2
  604. ucal_openCountryTimeZones(const char* country, UErrorCode* ec);
  605. /**
  606. * Return the default time zone. The default is determined initially
  607. * by querying the host operating system. If the host system detection
  608. * routines fail, or if they specify a TimeZone or TimeZone offset
  609. * which is not recognized, then the special TimeZone "Etc/Unknown"
  610. * is returned.
  611. *
  612. * The default may be changed with `ucal_setDefaultTimeZone()` or with
  613. * the C++ TimeZone API, `TimeZone::adoptDefault(TimeZone*)`.
  614. *
  615. * @param result A buffer to receive the result, or NULL
  616. *
  617. * @param resultCapacity The capacity of the result buffer
  618. *
  619. * @param ec input/output error code
  620. *
  621. * @return The result string length, not including the terminating
  622. * null
  623. *
  624. * @see #UCAL_UNKNOWN_ZONE_ID
  625. *
  626. * @stable ICU 2.6
  627. */
  628. U_CAPI int32_t U_EXPORT2
  629. ucal_getDefaultTimeZone(UChar* result, int32_t resultCapacity, UErrorCode* ec);
  630. /**
  631. * Set the default time zone.
  632. *
  633. * @param zoneID null-terminated time zone ID
  634. *
  635. * @param ec input/output error code
  636. *
  637. * @stable ICU 2.6
  638. */
  639. U_CAPI void U_EXPORT2
  640. ucal_setDefaultTimeZone(const UChar* zoneID, UErrorCode* ec);
  641. /**
  642. * Return the current host time zone. The host time zone is detected from
  643. * the current host system configuration by querying the host operating
  644. * system. If the host system detection routines fail, or if they specify
  645. * a TimeZone or TimeZone offset which is not recognized, then the special
  646. * TimeZone "Etc/Unknown" is returned.
  647. *
  648. * Note that host time zone and the ICU default time zone can be different.
  649. *
  650. * The ICU default time zone does not change once initialized unless modified
  651. * by calling `ucal_setDefaultTimeZone()` or with the C++ TimeZone API,
  652. * `TimeZone::adoptDefault(TimeZone*)`.
  653. *
  654. * If the host operating system configuration has changed since ICU has
  655. * initialized then the returned value can be different than the ICU default
  656. * time zone, even if the default has not changed.
  657. *
  658. * <p>This function is not thread safe.</p>
  659. *
  660. * @param result A buffer to receive the result, or NULL
  661. * @param resultCapacity The capacity of the result buffer
  662. * @param ec input/output error code
  663. * @return The result string length, not including the terminating
  664. * null
  665. *
  666. * @see #UCAL_UNKNOWN_ZONE_ID
  667. *
  668. * @stable ICU 65
  669. */
  670. U_CAPI int32_t U_EXPORT2
  671. ucal_getHostTimeZone(UChar *result, int32_t resultCapacity, UErrorCode *ec);
  672. /**
  673. * Return the amount of time in milliseconds that the clock is
  674. * advanced during daylight savings time for the given time zone, or
  675. * zero if the time zone does not observe daylight savings time.
  676. *
  677. * @param zoneID null-terminated time zone ID
  678. *
  679. * @param ec input/output error code
  680. *
  681. * @return the number of milliseconds the time is advanced with
  682. * respect to standard time when the daylight savings rules are in
  683. * effect. This is always a non-negative number, most commonly either
  684. * 3,600,000 (one hour) or zero.
  685. *
  686. * @stable ICU 2.6
  687. */
  688. U_CAPI int32_t U_EXPORT2
  689. ucal_getDSTSavings(const UChar* zoneID, UErrorCode* ec);
  690. /**
  691. * Get the current date and time.
  692. * The value returned is represented as milliseconds from the epoch.
  693. * @return The current date and time.
  694. * @stable ICU 2.0
  695. */
  696. U_CAPI UDate U_EXPORT2
  697. ucal_getNow(void);
  698. /**
  699. * Open a UCalendar.
  700. * A UCalendar may be used to convert a millisecond value to a year,
  701. * month, and day.
  702. * <p>
  703. * Note: When unknown TimeZone ID is specified or if the TimeZone ID specified is "Etc/Unknown",
  704. * the UCalendar returned by the function is initialized with GMT zone with TimeZone ID
  705. * <code>UCAL_UNKNOWN_ZONE_ID</code> ("Etc/Unknown") without any errors/warnings. If you want
  706. * to check if a TimeZone ID is valid prior to this function, use <code>ucal_getCanonicalTimeZoneID</code>.
  707. *
  708. * @param zoneID The desired TimeZone ID. If 0, use the default time zone.
  709. * @param len The length of zoneID, or -1 if null-terminated.
  710. * @param locale The desired locale
  711. * @param type The type of UCalendar to open. This can be UCAL_GREGORIAN to open the Gregorian
  712. * calendar for the locale, or UCAL_DEFAULT to open the default calendar for the locale (the
  713. * default calendar may also be Gregorian). To open a specific non-Gregorian calendar for the
  714. * locale, use uloc_setKeywordValue to set the value of the calendar keyword for the locale
  715. * and then pass the locale to ucal_open with UCAL_DEFAULT as the type.
  716. * @param status A pointer to an UErrorCode to receive any errors
  717. * @return A pointer to a UCalendar, or 0 if an error occurred.
  718. * @see #UCAL_UNKNOWN_ZONE_ID
  719. * @stable ICU 2.0
  720. */
  721. U_CAPI UCalendar* U_EXPORT2
  722. ucal_open(const UChar* zoneID,
  723. int32_t len,
  724. const char* locale,
  725. UCalendarType type,
  726. UErrorCode* status);
  727. /**
  728. * Close a UCalendar.
  729. * Once closed, a UCalendar may no longer be used.
  730. * @param cal The UCalendar to close.
  731. * @stable ICU 2.0
  732. */
  733. U_CAPI void U_EXPORT2
  734. ucal_close(UCalendar *cal);
  735. #if U_SHOW_CPLUSPLUS_API
  736. U_NAMESPACE_BEGIN
  737. /**
  738. * \class LocalUCalendarPointer
  739. * "Smart pointer" class, closes a UCalendar via ucal_close().
  740. * For most methods see the LocalPointerBase base class.
  741. *
  742. * @see LocalPointerBase
  743. * @see LocalPointer
  744. * @stable ICU 4.4
  745. */
  746. U_DEFINE_LOCAL_OPEN_POINTER(LocalUCalendarPointer, UCalendar, ucal_close);
  747. U_NAMESPACE_END
  748. #endif
  749. /**
  750. * Open a copy of a UCalendar.
  751. * This function performs a deep copy.
  752. * @param cal The calendar to copy
  753. * @param status A pointer to an UErrorCode to receive any errors.
  754. * @return A pointer to a UCalendar identical to cal.
  755. * @stable ICU 4.0
  756. */
  757. U_CAPI UCalendar* U_EXPORT2
  758. ucal_clone(const UCalendar* cal,
  759. UErrorCode* status);
  760. /**
  761. * Set the TimeZone used by a UCalendar.
  762. * A UCalendar uses a timezone for converting from Greenwich time to local time.
  763. * @param cal The UCalendar to set.
  764. * @param zoneID The desired TimeZone ID. If 0, use the default time zone.
  765. * @param len The length of zoneID, or -1 if null-terminated.
  766. * @param status A pointer to an UErrorCode to receive any errors.
  767. * @stable ICU 2.0
  768. */
  769. U_CAPI void U_EXPORT2
  770. ucal_setTimeZone(UCalendar* cal,
  771. const UChar* zoneID,
  772. int32_t len,
  773. UErrorCode* status);
  774. /**
  775. * Get the ID of the UCalendar's time zone.
  776. *
  777. * @param cal The UCalendar to query.
  778. * @param result Receives the UCalendar's time zone ID.
  779. * @param resultLength The maximum size of result.
  780. * @param status Receives the status.
  781. * @return The total buffer size needed; if greater than resultLength, the output was truncated.
  782. * @stable ICU 51
  783. */
  784. U_CAPI int32_t U_EXPORT2
  785. ucal_getTimeZoneID(const UCalendar *cal,
  786. UChar *result,
  787. int32_t resultLength,
  788. UErrorCode *status);
  789. /**
  790. * Possible formats for a UCalendar's display name
  791. * @stable ICU 2.0
  792. */
  793. enum UCalendarDisplayNameType {
  794. /** Standard display name */
  795. UCAL_STANDARD,
  796. /** Short standard display name */
  797. UCAL_SHORT_STANDARD,
  798. /** Daylight savings display name */
  799. UCAL_DST,
  800. /** Short daylight savings display name */
  801. UCAL_SHORT_DST
  802. };
  803. /** @stable ICU 2.0 */
  804. typedef enum UCalendarDisplayNameType UCalendarDisplayNameType;
  805. /**
  806. * Get the display name for a UCalendar's TimeZone.
  807. * A display name is suitable for presentation to a user.
  808. * @param cal The UCalendar to query.
  809. * @param type The desired display name format; one of UCAL_STANDARD, UCAL_SHORT_STANDARD,
  810. * UCAL_DST, UCAL_SHORT_DST
  811. * @param locale The desired locale for the display name.
  812. * @param result A pointer to a buffer to receive the formatted number.
  813. * @param resultLength The maximum size of result.
  814. * @param status A pointer to an UErrorCode to receive any errors
  815. * @return The total buffer size needed; if greater than resultLength, the output was truncated.
  816. * @stable ICU 2.0
  817. */
  818. U_CAPI int32_t U_EXPORT2
  819. ucal_getTimeZoneDisplayName(const UCalendar* cal,
  820. UCalendarDisplayNameType type,
  821. const char* locale,
  822. UChar* result,
  823. int32_t resultLength,
  824. UErrorCode* status);
  825. /**
  826. * Determine if a UCalendar is currently in daylight savings time.
  827. * Daylight savings time is not used in all parts of the world.
  828. * @param cal The UCalendar to query.
  829. * @param status A pointer to an UErrorCode to receive any errors
  830. * @return true if cal is currently in daylight savings time, false otherwise
  831. * @stable ICU 2.0
  832. */
  833. U_CAPI UBool U_EXPORT2
  834. ucal_inDaylightTime(const UCalendar* cal,
  835. UErrorCode* status );
  836. /**
  837. * Sets the GregorianCalendar change date. This is the point when the switch from
  838. * Julian dates to Gregorian dates occurred. Default is 00:00:00 local time, October
  839. * 15, 1582. Previous to this time and date will be Julian dates.
  840. *
  841. * This function works only for Gregorian calendars. If the UCalendar is not
  842. * an instance of a Gregorian calendar, then a U_UNSUPPORTED_ERROR
  843. * error code is set.
  844. *
  845. * @param cal The calendar object.
  846. * @param date The given Gregorian cutover date.
  847. * @param pErrorCode Pointer to a standard ICU error code. Its input value must
  848. * pass the U_SUCCESS() test, or else the function returns
  849. * immediately. Check for U_FAILURE() on output or use with
  850. * function chaining. (See User Guide for details.)
  851. *
  852. * @see GregorianCalendar::setGregorianChange
  853. * @see ucal_getGregorianChange
  854. * @stable ICU 3.6
  855. */
  856. U_CAPI void U_EXPORT2
  857. ucal_setGregorianChange(UCalendar *cal, UDate date, UErrorCode *pErrorCode);
  858. /**
  859. * Gets the Gregorian Calendar change date. This is the point when the switch from
  860. * Julian dates to Gregorian dates occurred. Default is 00:00:00 local time, October
  861. * 15, 1582. Previous to this time and date will be Julian dates.
  862. *
  863. * This function works only for Gregorian calendars. If the UCalendar is not
  864. * an instance of a Gregorian calendar, then a U_UNSUPPORTED_ERROR
  865. * error code is set.
  866. *
  867. * @param cal The calendar object.
  868. * @param pErrorCode Pointer to a standard ICU error code. Its input value must
  869. * pass the U_SUCCESS() test, or else the function returns
  870. * immediately. Check for U_FAILURE() on output or use with
  871. * function chaining. (See User Guide for details.)
  872. * @return The Gregorian cutover time for this calendar.
  873. *
  874. * @see GregorianCalendar::getGregorianChange
  875. * @see ucal_setGregorianChange
  876. * @stable ICU 3.6
  877. */
  878. U_CAPI UDate U_EXPORT2
  879. ucal_getGregorianChange(const UCalendar *cal, UErrorCode *pErrorCode);
  880. /**
  881. * Types of UCalendar attributes
  882. * @stable ICU 2.0
  883. */
  884. enum UCalendarAttribute {
  885. /**
  886. * Lenient parsing
  887. * @stable ICU 2.0
  888. */
  889. UCAL_LENIENT,
  890. /**
  891. * First day of week
  892. * @stable ICU 2.0
  893. */
  894. UCAL_FIRST_DAY_OF_WEEK,
  895. /**
  896. * Minimum number of days in first week
  897. * @stable ICU 2.0
  898. */
  899. UCAL_MINIMAL_DAYS_IN_FIRST_WEEK,
  900. /**
  901. * The behavior for handling wall time repeating multiple times
  902. * at negative time zone offset transitions
  903. * @stable ICU 49
  904. */
  905. UCAL_REPEATED_WALL_TIME,
  906. /**
  907. * The behavior for handling skipped wall time at positive time
  908. * zone offset transitions.
  909. * @stable ICU 49
  910. */
  911. UCAL_SKIPPED_WALL_TIME
  912. };
  913. /** @stable ICU 2.0 */
  914. typedef enum UCalendarAttribute UCalendarAttribute;
  915. /**
  916. * Options for handling ambiguous wall time at time zone
  917. * offset transitions.
  918. * @stable ICU 49
  919. */
  920. enum UCalendarWallTimeOption {
  921. /**
  922. * An ambiguous wall time to be interpreted as the latest.
  923. * This option is valid for UCAL_REPEATED_WALL_TIME and
  924. * UCAL_SKIPPED_WALL_TIME.
  925. * @stable ICU 49
  926. */
  927. UCAL_WALLTIME_LAST,
  928. /**
  929. * An ambiguous wall time to be interpreted as the earliest.
  930. * This option is valid for UCAL_REPEATED_WALL_TIME and
  931. * UCAL_SKIPPED_WALL_TIME.
  932. * @stable ICU 49
  933. */
  934. UCAL_WALLTIME_FIRST,
  935. /**
  936. * An ambiguous wall time to be interpreted as the next valid
  937. * wall time. This option is valid for UCAL_SKIPPED_WALL_TIME.
  938. * @stable ICU 49
  939. */
  940. UCAL_WALLTIME_NEXT_VALID
  941. };
  942. /** @stable ICU 49 */
  943. typedef enum UCalendarWallTimeOption UCalendarWallTimeOption;
  944. /**
  945. * Get a numeric attribute associated with a UCalendar.
  946. * Numeric attributes include the first day of the week, or the minimal numbers
  947. * of days in the first week of the month.
  948. * @param cal The UCalendar to query.
  949. * @param attr The desired attribute; one of UCAL_LENIENT, UCAL_FIRST_DAY_OF_WEEK,
  950. * UCAL_MINIMAL_DAYS_IN_FIRST_WEEK, UCAL_REPEATED_WALL_TIME or UCAL_SKIPPED_WALL_TIME
  951. * @return The value of attr.
  952. * @see ucal_setAttribute
  953. * @stable ICU 2.0
  954. */
  955. U_CAPI int32_t U_EXPORT2
  956. ucal_getAttribute(const UCalendar* cal,
  957. UCalendarAttribute attr);
  958. /**
  959. * Set a numeric attribute associated with a UCalendar.
  960. * Numeric attributes include the first day of the week, or the minimal numbers
  961. * of days in the first week of the month.
  962. * @param cal The UCalendar to set.
  963. * @param attr The desired attribute; one of UCAL_LENIENT, UCAL_FIRST_DAY_OF_WEEK,
  964. * UCAL_MINIMAL_DAYS_IN_FIRST_WEEK, UCAL_REPEATED_WALL_TIME or UCAL_SKIPPED_WALL_TIME
  965. * @param newValue The new value of attr.
  966. * @see ucal_getAttribute
  967. * @stable ICU 2.0
  968. */
  969. U_CAPI void U_EXPORT2
  970. ucal_setAttribute(UCalendar* cal,
  971. UCalendarAttribute attr,
  972. int32_t newValue);
  973. /**
  974. * Get a locale for which calendars are available.
  975. * A UCalendar in a locale returned by this function will contain the correct
  976. * day and month names for the locale.
  977. * @param localeIndex The index of the desired locale.
  978. * @return A locale for which calendars are available, or 0 if none.
  979. * @see ucal_countAvailable
  980. * @stable ICU 2.0
  981. */
  982. U_CAPI const char* U_EXPORT2
  983. ucal_getAvailable(int32_t localeIndex);
  984. /**
  985. * Determine how many locales have calendars available.
  986. * This function is most useful as determining the loop ending condition for
  987. * calls to \ref ucal_getAvailable.
  988. * @return The number of locales for which calendars are available.
  989. * @see ucal_getAvailable
  990. * @stable ICU 2.0
  991. */
  992. U_CAPI int32_t U_EXPORT2
  993. ucal_countAvailable(void);
  994. /**
  995. * Get a UCalendar's current time in millis.
  996. * The time is represented as milliseconds from the epoch.
  997. * @param cal The UCalendar to query.
  998. * @param status A pointer to an UErrorCode to receive any errors
  999. * @return The calendar's current time in millis.
  1000. * @see ucal_setMillis
  1001. * @see ucal_setDate
  1002. * @see ucal_setDateTime
  1003. * @stable ICU 2.0
  1004. */
  1005. U_CAPI UDate U_EXPORT2
  1006. ucal_getMillis(const UCalendar* cal,
  1007. UErrorCode* status);
  1008. /**
  1009. * Set a UCalendar's current time in millis.
  1010. * The time is represented as milliseconds from the epoch.
  1011. * @param cal The UCalendar to set.
  1012. * @param dateTime The desired date and time.
  1013. * @param status A pointer to an UErrorCode to receive any errors
  1014. * @see ucal_getMillis
  1015. * @see ucal_setDate
  1016. * @see ucal_setDateTime
  1017. * @stable ICU 2.0
  1018. */
  1019. U_CAPI void U_EXPORT2
  1020. ucal_setMillis(UCalendar* cal,
  1021. UDate dateTime,
  1022. UErrorCode* status );
  1023. /**
  1024. * Set a UCalendar's current date.
  1025. * The date is represented as a series of 32-bit integers.
  1026. * @param cal The UCalendar to set.
  1027. * @param year The desired year.
  1028. * @param month The desired month; one of UCAL_JANUARY, UCAL_FEBRUARY, UCAL_MARCH, UCAL_APRIL, UCAL_MAY,
  1029. * UCAL_JUNE, UCAL_JULY, UCAL_AUGUST, UCAL_SEPTEMBER, UCAL_OCTOBER, UCAL_NOVEMBER, UCAL_DECEMBER, UCAL_UNDECIMBER
  1030. * @param date The desired day of the month.
  1031. * @param status A pointer to an UErrorCode to receive any errors
  1032. * @see ucal_getMillis
  1033. * @see ucal_setMillis
  1034. * @see ucal_setDateTime
  1035. * @stable ICU 2.0
  1036. */
  1037. U_CAPI void U_EXPORT2
  1038. ucal_setDate(UCalendar* cal,
  1039. int32_t year,
  1040. int32_t month,
  1041. int32_t date,
  1042. UErrorCode* status);
  1043. /**
  1044. * Set a UCalendar's current date.
  1045. * The date is represented as a series of 32-bit integers.
  1046. * @param cal The UCalendar to set.
  1047. * @param year The desired year.
  1048. * @param month The desired month; one of UCAL_JANUARY, UCAL_FEBRUARY, UCAL_MARCH, UCAL_APRIL, UCAL_MAY,
  1049. * UCAL_JUNE, UCAL_JULY, UCAL_AUGUST, UCAL_SEPTEMBER, UCAL_OCTOBER, UCAL_NOVEMBER, UCAL_DECEMBER, UCAL_UNDECIMBER
  1050. * @param date The desired day of the month.
  1051. * @param hour The desired hour of day.
  1052. * @param minute The desired minute.
  1053. * @param second The desirec second.
  1054. * @param status A pointer to an UErrorCode to receive any errors
  1055. * @see ucal_getMillis
  1056. * @see ucal_setMillis
  1057. * @see ucal_setDate
  1058. * @stable ICU 2.0
  1059. */
  1060. U_CAPI void U_EXPORT2
  1061. ucal_setDateTime(UCalendar* cal,
  1062. int32_t year,
  1063. int32_t month,
  1064. int32_t date,
  1065. int32_t hour,
  1066. int32_t minute,
  1067. int32_t second,
  1068. UErrorCode* status);
  1069. /**
  1070. * Returns true if two UCalendars are equivalent. Equivalent
  1071. * UCalendars will behave identically, but they may be set to
  1072. * different times.
  1073. * @param cal1 The first of the UCalendars to compare.
  1074. * @param cal2 The second of the UCalendars to compare.
  1075. * @return true if cal1 and cal2 are equivalent, false otherwise.
  1076. * @stable ICU 2.0
  1077. */
  1078. U_CAPI UBool U_EXPORT2
  1079. ucal_equivalentTo(const UCalendar* cal1,
  1080. const UCalendar* cal2);
  1081. /**
  1082. * Add a specified signed amount to a particular field in a UCalendar.
  1083. * This can modify more significant fields in the calendar.
  1084. * Adding a positive value always means moving forward in time, so for the Gregorian calendar,
  1085. * starting with 100 BC and adding +1 to year results in 99 BC (even though this actually reduces
  1086. * the numeric value of the field itself).
  1087. * @param cal The UCalendar to which to add.
  1088. * @param field The field to which to add the signed value; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH,
  1089. * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK,
  1090. * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND,
  1091. * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET.
  1092. * @param amount The signed amount to add to field. If the amount causes the value
  1093. * to exceed to maximum or minimum values for that field, other fields are modified
  1094. * to preserve the magnitude of the change.
  1095. * @param status A pointer to an UErrorCode to receive any errors
  1096. * @see ucal_roll
  1097. * @stable ICU 2.0
  1098. */
  1099. U_CAPI void U_EXPORT2
  1100. ucal_add(UCalendar* cal,
  1101. UCalendarDateFields field,
  1102. int32_t amount,
  1103. UErrorCode* status);
  1104. /**
  1105. * Add a specified signed amount to a particular field in a UCalendar.
  1106. * This will not modify more significant fields in the calendar.
  1107. * Rolling by a positive value always means moving forward in time (unless the limit of the
  1108. * field is reached, in which case it may pin or wrap), so for Gregorian calendar,
  1109. * starting with 100 BC and rolling the year by +1 results in 99 BC.
  1110. * When eras have a definite beginning and end (as in the Chinese calendar, or as in most eras in the
  1111. * Japanese calendar) then rolling the year past either limit of the era will cause the year to wrap around.
  1112. * When eras only have a limit at one end, then attempting to roll the year past that limit will result in
  1113. * pinning the year at that limit. Note that for most calendars in which era 0 years move forward in time
  1114. * (such as Buddhist, Hebrew, or Islamic), it is possible for add or roll to result in negative years for
  1115. * era 0 (that is the only way to represent years before the calendar epoch).
  1116. * @param cal The UCalendar to which to add.
  1117. * @param field The field to which to add the signed value; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH,
  1118. * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK,
  1119. * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND,
  1120. * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET.
  1121. * @param amount The signed amount to add to field. If the amount causes the value
  1122. * to exceed to maximum or minimum values for that field, the field is pinned to a permissible
  1123. * value.
  1124. * @param status A pointer to an UErrorCode to receive any errors
  1125. * @see ucal_add
  1126. * @stable ICU 2.0
  1127. */
  1128. U_CAPI void U_EXPORT2
  1129. ucal_roll(UCalendar* cal,
  1130. UCalendarDateFields field,
  1131. int32_t amount,
  1132. UErrorCode* status);
  1133. /**
  1134. * Get the current value of a field from a UCalendar.
  1135. * All fields are represented as 32-bit integers.
  1136. * @param cal The UCalendar to query.
  1137. * @param field The desired field; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH,
  1138. * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK,
  1139. * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND,
  1140. * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET.
  1141. * @param status A pointer to an UErrorCode to receive any errors
  1142. * @return The value of the desired field.
  1143. * @see ucal_set
  1144. * @see ucal_isSet
  1145. * @see ucal_clearField
  1146. * @see ucal_clear
  1147. * @stable ICU 2.0
  1148. */
  1149. U_CAPI int32_t U_EXPORT2
  1150. ucal_get(const UCalendar* cal,
  1151. UCalendarDateFields field,
  1152. UErrorCode* status );
  1153. /**
  1154. * Set the value of a field in a UCalendar.
  1155. * All fields are represented as 32-bit integers.
  1156. * @param cal The UCalendar to set.
  1157. * @param field The field to set; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH,
  1158. * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK,
  1159. * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND,
  1160. * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET.
  1161. * @param value The desired value of field.
  1162. * @see ucal_get
  1163. * @see ucal_isSet
  1164. * @see ucal_clearField
  1165. * @see ucal_clear
  1166. * @stable ICU 2.0
  1167. */
  1168. U_CAPI void U_EXPORT2
  1169. ucal_set(UCalendar* cal,
  1170. UCalendarDateFields field,
  1171. int32_t value);
  1172. /**
  1173. * Determine if a field in a UCalendar is set.
  1174. * All fields are represented as 32-bit integers.
  1175. * @param cal The UCalendar to query.
  1176. * @param field The desired field; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH,
  1177. * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK,
  1178. * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND,
  1179. * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET.
  1180. * @return true if field is set, false otherwise.
  1181. * @see ucal_get
  1182. * @see ucal_set
  1183. * @see ucal_clearField
  1184. * @see ucal_clear
  1185. * @stable ICU 2.0
  1186. */
  1187. U_CAPI UBool U_EXPORT2
  1188. ucal_isSet(const UCalendar* cal,
  1189. UCalendarDateFields field);
  1190. /**
  1191. * Clear a field in a UCalendar.
  1192. * All fields are represented as 32-bit integers.
  1193. * @param cal The UCalendar containing the field to clear.
  1194. * @param field The field to clear; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH,
  1195. * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK,
  1196. * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND,
  1197. * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET.
  1198. * @see ucal_get
  1199. * @see ucal_set
  1200. * @see ucal_isSet
  1201. * @see ucal_clear
  1202. * @stable ICU 2.0
  1203. */
  1204. U_CAPI void U_EXPORT2
  1205. ucal_clearField(UCalendar* cal,
  1206. UCalendarDateFields field);
  1207. /**
  1208. * Clear all fields in a UCalendar.
  1209. * All fields are represented as 32-bit integers.
  1210. * @param calendar The UCalendar to clear.
  1211. * @see ucal_get
  1212. * @see ucal_set
  1213. * @see ucal_isSet
  1214. * @see ucal_clearField
  1215. * @stable ICU 2.0
  1216. */
  1217. U_CAPI void U_EXPORT2
  1218. ucal_clear(UCalendar* calendar);
  1219. /**
  1220. * Possible limit values for a UCalendar
  1221. * @stable ICU 2.0
  1222. */
  1223. enum UCalendarLimitType {
  1224. /** Minimum value */
  1225. UCAL_MINIMUM,
  1226. /** Maximum value */
  1227. UCAL_MAXIMUM,
  1228. /** Greatest minimum value */
  1229. UCAL_GREATEST_MINIMUM,
  1230. /** Least maximum value */
  1231. UCAL_LEAST_MAXIMUM,
  1232. /** Actual minimum value */
  1233. UCAL_ACTUAL_MINIMUM,
  1234. /** Actual maximum value */
  1235. UCAL_ACTUAL_MAXIMUM
  1236. };
  1237. /** @stable ICU 2.0 */
  1238. typedef enum UCalendarLimitType UCalendarLimitType;
  1239. /**
  1240. * Determine a limit for a field in a UCalendar.
  1241. * A limit is a maximum or minimum value for a field.
  1242. * @param cal The UCalendar to query.
  1243. * @param field The desired field; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH,
  1244. * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK,
  1245. * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND,
  1246. * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET.
  1247. * @param type The desired critical point; one of UCAL_MINIMUM, UCAL_MAXIMUM, UCAL_GREATEST_MINIMUM,
  1248. * UCAL_LEAST_MAXIMUM, UCAL_ACTUAL_MINIMUM, UCAL_ACTUAL_MAXIMUM
  1249. * @param status A pointer to an UErrorCode to receive any errors.
  1250. * @return The requested value.
  1251. * @stable ICU 2.0
  1252. */
  1253. U_CAPI int32_t U_EXPORT2
  1254. ucal_getLimit(const UCalendar* cal,
  1255. UCalendarDateFields field,
  1256. UCalendarLimitType type,
  1257. UErrorCode* status);
  1258. /** Get the locale for this calendar object. You can choose between valid and actual locale.
  1259. * @param cal The calendar object
  1260. * @param type type of the locale we're looking for (valid or actual)
  1261. * @param status error code for the operation
  1262. * @return the locale name
  1263. * @stable ICU 2.8
  1264. */
  1265. U_CAPI const char * U_EXPORT2
  1266. ucal_getLocaleByType(const UCalendar *cal, ULocDataLocaleType type, UErrorCode* status);
  1267. /**
  1268. * Returns the timezone data version currently used by ICU.
  1269. * @param status error code for the operation
  1270. * @return the version string, such as "2007f"
  1271. * @stable ICU 3.8
  1272. */
  1273. U_CAPI const char * U_EXPORT2
  1274. ucal_getTZDataVersion(UErrorCode* status);
  1275. /**
  1276. * Returns the canonical system timezone ID or the normalized
  1277. * custom time zone ID for the given time zone ID.
  1278. * @param id The input timezone ID to be canonicalized.
  1279. * @param len The length of id, or -1 if null-terminated.
  1280. * @param result The buffer receives the canonical system timezone ID
  1281. * or the custom timezone ID in normalized format.
  1282. * @param resultCapacity The capacity of the result buffer.
  1283. * @param isSystemID Receives if the given ID is a known system
  1284. * timezone ID.
  1285. * @param status Receives the status. When the given timezone ID
  1286. * is neither a known system time zone ID nor a
  1287. * valid custom timezone ID, U_ILLEGAL_ARGUMENT_ERROR
  1288. * is set.
  1289. * @return The result string length, not including the terminating
  1290. * null.
  1291. * @stable ICU 4.0
  1292. */
  1293. U_CAPI int32_t U_EXPORT2
  1294. ucal_getCanonicalTimeZoneID(const UChar* id, int32_t len,
  1295. UChar* result, int32_t resultCapacity, UBool *isSystemID, UErrorCode* status);
  1296. /**
  1297. * Returns the preferred time zone ID in the IANA time zone database for the given time zone ID.
  1298. * There are two types of preferred IDs. The first type is the one defined in zone.tab file,
  1299. * such as "America/Los_Angeles". The second types is the one defined for zones not associated
  1300. * with a specific region, but not defined with "Link" syntax such as "Etc/GMT+10".
  1301. *
  1302. * <p>Note: For most of valid time zone IDs, this method returns an ID same as ucal_getCanonicalTimeZoneID().
  1303. * ucal_getCanonicalTimeZoneID() is based on canonical time zone IDs defined in Unicode CLDR.
  1304. * These canonical time zone IDs in CLDR were based on very old version of the time zone database.
  1305. * In the IANA time zone database, some IDs were updated since then. This API returns a newer
  1306. * time zone ID. For example, CLDR defines "Asia/Calcutta" as the canonical time zone ID. This
  1307. * method returns "Asia/Kolkata" instead.
  1308. * <p> "Etc/Unknown" is a special time zone ID defined by CLDR. There are no corresponding zones
  1309. * in the IANA time zone database. Therefore, this API returns U_ILLEGAL_ARGUMENT_ERROR when the
  1310. * input ID is "Etc/Unknown".
  1311. *
  1312. * @param id The input time zone ID.
  1313. * @param len The length of the input time zone ID.
  1314. * @param result The buffer receives the preferred time zone ID in the IANA time zone database.
  1315. * @param resultCapacity The capacity of the result buffer.
  1316. * @param status Receives the status. When the given time zone ID is not a known system time zone
  1317. * ID, U_ILLEGAL_ARGUMENT_ERROR is set.
  1318. * @return The result string length, not including the terminating null.
  1319. * @stable ICU 74
  1320. */
  1321. U_CAPI int32_t U_EXPORT2
  1322. ucal_getIanaTimeZoneID(const UChar* id, int32_t len,
  1323. UChar* result, int32_t resultCapacity, UErrorCode* status);
  1324. /**
  1325. * Get the resource keyword value string designating the calendar type for the UCalendar.
  1326. * @param cal The UCalendar to query.
  1327. * @param status The error code for the operation.
  1328. * @return The resource keyword value string.
  1329. * @stable ICU 4.2
  1330. */
  1331. U_CAPI const char * U_EXPORT2
  1332. ucal_getType(const UCalendar *cal, UErrorCode* status);
  1333. /**
  1334. * Given a key and a locale, returns an array of string values in a preferred
  1335. * order that would make a difference. These are all and only those values where
  1336. * the open (creation) of the service with the locale formed from the input locale
  1337. * plus input keyword and that value has different behavior than creation with the
  1338. * input locale alone.
  1339. * @param key one of the keys supported by this service. For now, only
  1340. * "calendar" is supported.
  1341. * @param locale the locale
  1342. * @param commonlyUsed if set to true it will return only commonly used values
  1343. * with the given locale in preferred order. Otherwise,
  1344. * it will return all the available values for the locale.
  1345. * @param status error status
  1346. * @return a string enumeration over keyword values for the given key and the locale.
  1347. * @stable ICU 4.2
  1348. */
  1349. U_CAPI UEnumeration* U_EXPORT2
  1350. ucal_getKeywordValuesForLocale(const char* key,
  1351. const char* locale,
  1352. UBool commonlyUsed,
  1353. UErrorCode* status);
  1354. /** Weekday types, as returned by ucal_getDayOfWeekType().
  1355. * @stable ICU 4.4
  1356. */
  1357. enum UCalendarWeekdayType {
  1358. /**
  1359. * Designates a full weekday (no part of the day is included in the weekend).
  1360. * @stable ICU 4.4
  1361. */
  1362. UCAL_WEEKDAY,
  1363. /**
  1364. * Designates a full weekend day (the entire day is included in the weekend).
  1365. * @stable ICU 4.4
  1366. */
  1367. UCAL_WEEKEND,
  1368. /**
  1369. * Designates a day that starts as a weekday and transitions to the weekend.
  1370. * Call ucal_getWeekendTransition() to get the time of transition.
  1371. * @stable ICU 4.4
  1372. */
  1373. UCAL_WEEKEND_ONSET,
  1374. /**
  1375. * Designates a day that starts as the weekend and transitions to a weekday.
  1376. * Call ucal_getWeekendTransition() to get the time of transition.
  1377. * @stable ICU 4.4
  1378. */
  1379. UCAL_WEEKEND_CEASE
  1380. };
  1381. /** @stable ICU 4.4 */
  1382. typedef enum UCalendarWeekdayType UCalendarWeekdayType;
  1383. /**
  1384. * Returns whether the given day of the week is a weekday, a weekend day,
  1385. * or a day that transitions from one to the other, for the locale and
  1386. * calendar system associated with this UCalendar (the locale's region is
  1387. * often the most determinant factor). If a transition occurs at midnight,
  1388. * then the days before and after the transition will have the
  1389. * type UCAL_WEEKDAY or UCAL_WEEKEND. If a transition occurs at a time
  1390. * other than midnight, then the day of the transition will have
  1391. * the type UCAL_WEEKEND_ONSET or UCAL_WEEKEND_CEASE. In this case, the
  1392. * function ucal_getWeekendTransition() will return the point of
  1393. * transition.
  1394. * @param cal The UCalendar to query.
  1395. * @param dayOfWeek The day of the week whose type is desired (UCAL_SUNDAY..UCAL_SATURDAY).
  1396. * @param status The error code for the operation.
  1397. * @return The UCalendarWeekdayType for the day of the week.
  1398. * @stable ICU 4.4
  1399. */
  1400. U_CAPI UCalendarWeekdayType U_EXPORT2
  1401. ucal_getDayOfWeekType(const UCalendar *cal, UCalendarDaysOfWeek dayOfWeek, UErrorCode* status);
  1402. /**
  1403. * Returns the time during the day at which the weekend begins or ends in
  1404. * this calendar system. If ucal_getDayOfWeekType() returns UCAL_WEEKEND_ONSET
  1405. * for the specified dayOfWeek, return the time at which the weekend begins.
  1406. * If ucal_getDayOfWeekType() returns UCAL_WEEKEND_CEASE for the specified dayOfWeek,
  1407. * return the time at which the weekend ends. If ucal_getDayOfWeekType() returns
  1408. * some other UCalendarWeekdayType for the specified dayOfWeek, is it an error condition
  1409. * (U_ILLEGAL_ARGUMENT_ERROR).
  1410. * @param cal The UCalendar to query.
  1411. * @param dayOfWeek The day of the week for which the weekend transition time is
  1412. * desired (UCAL_SUNDAY..UCAL_SATURDAY).
  1413. * @param status The error code for the operation.
  1414. * @return The milliseconds after midnight at which the weekend begins or ends.
  1415. * @stable ICU 4.4
  1416. */
  1417. U_CAPI int32_t U_EXPORT2
  1418. ucal_getWeekendTransition(const UCalendar *cal, UCalendarDaysOfWeek dayOfWeek, UErrorCode *status);
  1419. /**
  1420. * Returns true if the given UDate is in the weekend in
  1421. * this calendar system.
  1422. * @param cal The UCalendar to query.
  1423. * @param date The UDate in question.
  1424. * @param status The error code for the operation.
  1425. * @return true if the given UDate is in the weekend in
  1426. * this calendar system, false otherwise.
  1427. * @stable ICU 4.4
  1428. */
  1429. U_CAPI UBool U_EXPORT2
  1430. ucal_isWeekend(const UCalendar *cal, UDate date, UErrorCode *status);
  1431. /**
  1432. * Return the difference between the target time and the time this calendar object is currently set to.
  1433. * If the target time is after the current calendar setting, the the returned value will be positive.
  1434. * The field parameter specifies the units of the return value. For example, if field is UCAL_MONTH
  1435. * and ucal_getFieldDifference returns 3, then the target time is 3 to less than 4 months after the
  1436. * current calendar setting.
  1437. *
  1438. * As a side effect of this call, this calendar is advanced toward target by the given amount. That is,
  1439. * calling this function has the side effect of calling ucal_add on this calendar with the specified
  1440. * field and an amount equal to the return value from this function.
  1441. *
  1442. * A typical way of using this function is to call it first with the largest field of interest, then
  1443. * with progressively smaller fields.
  1444. *
  1445. * @param cal The UCalendar to compare and update.
  1446. * @param target The target date to compare to the current calendar setting.
  1447. * @param field The field to compare; one of UCAL_ERA, UCAL_YEAR, UCAL_MONTH,
  1448. * UCAL_WEEK_OF_YEAR, UCAL_WEEK_OF_MONTH, UCAL_DATE, UCAL_DAY_OF_YEAR, UCAL_DAY_OF_WEEK,
  1449. * UCAL_DAY_OF_WEEK_IN_MONTH, UCAL_AM_PM, UCAL_HOUR, UCAL_HOUR_OF_DAY, UCAL_MINUTE, UCAL_SECOND,
  1450. * UCAL_MILLISECOND, UCAL_ZONE_OFFSET, UCAL_DST_OFFSET.
  1451. * @param status A pointer to an UErrorCode to receive any errors
  1452. * @return The date difference for the specified field.
  1453. * @stable ICU 4.8
  1454. */
  1455. U_CAPI int32_t U_EXPORT2
  1456. ucal_getFieldDifference(UCalendar* cal,
  1457. UDate target,
  1458. UCalendarDateFields field,
  1459. UErrorCode* status);
  1460. /**
  1461. * Time zone transition types for ucal_getTimeZoneTransitionDate
  1462. * @stable ICU 50
  1463. */
  1464. enum UTimeZoneTransitionType {
  1465. /**
  1466. * Get the next transition after the current date,
  1467. * i.e. excludes the current date
  1468. * @stable ICU 50
  1469. */
  1470. UCAL_TZ_TRANSITION_NEXT,
  1471. /**
  1472. * Get the next transition on or after the current date,
  1473. * i.e. may include the current date
  1474. * @stable ICU 50
  1475. */
  1476. UCAL_TZ_TRANSITION_NEXT_INCLUSIVE,
  1477. /**
  1478. * Get the previous transition before the current date,
  1479. * i.e. excludes the current date
  1480. * @stable ICU 50
  1481. */
  1482. UCAL_TZ_TRANSITION_PREVIOUS,
  1483. /**
  1484. * Get the previous transition on or before the current date,
  1485. * i.e. may include the current date
  1486. * @stable ICU 50
  1487. */
  1488. UCAL_TZ_TRANSITION_PREVIOUS_INCLUSIVE
  1489. };
  1490. typedef enum UTimeZoneTransitionType UTimeZoneTransitionType; /**< @stable ICU 50 */
  1491. /**
  1492. * Get the UDate for the next/previous time zone transition relative to
  1493. * the calendar's current date, in the time zone to which the calendar
  1494. * is currently set. If there is no known time zone transition of the
  1495. * requested type relative to the calendar's date, the function returns
  1496. * false.
  1497. * @param cal The UCalendar to query.
  1498. * @param type The type of transition desired.
  1499. * @param transition A pointer to a UDate to be set to the transition time.
  1500. * If the function returns false, the value set is unspecified.
  1501. * @param status A pointer to a UErrorCode to receive any errors.
  1502. * @return true if a valid transition time is set in *transition, false
  1503. * otherwise.
  1504. * @stable ICU 50
  1505. */
  1506. U_CAPI UBool U_EXPORT2
  1507. ucal_getTimeZoneTransitionDate(const UCalendar* cal, UTimeZoneTransitionType type,
  1508. UDate* transition, UErrorCode* status);
  1509. /**
  1510. * Converts a system time zone ID to an equivalent Windows time zone ID. For example,
  1511. * Windows time zone ID "Pacific Standard Time" is returned for input "America/Los_Angeles".
  1512. *
  1513. * <p>There are system time zones that cannot be mapped to Windows zones. When the input
  1514. * system time zone ID is unknown or unmappable to a Windows time zone, then this
  1515. * function returns 0 as the result length, but the operation itself remains successful
  1516. * (no error status set on return).
  1517. *
  1518. * <p>This implementation utilizes <a href="http://unicode.org/cldr/charts/supplemental/zone_tzid.html">
  1519. * Zone-Tzid mapping data</a>. The mapping data is updated time to time. To get the latest changes,
  1520. * please read the ICU user guide section <a href="https://unicode-org.github.io/icu/userguide/datetime/timezone#updating-the-time-zone-data">
  1521. * Updating the Time Zone Data</a>.
  1522. *
  1523. * @param id A system time zone ID.
  1524. * @param len The length of <code>id</code>, or -1 if null-terminated.
  1525. * @param winid A buffer to receive a Windows time zone ID.
  1526. * @param winidCapacity The capacity of the result buffer <code>winid</code>.
  1527. * @param status Receives the status.
  1528. * @return The result string length, not including the terminating null.
  1529. * @see ucal_getTimeZoneIDForWindowsID
  1530. *
  1531. * @stable ICU 52
  1532. */
  1533. U_CAPI int32_t U_EXPORT2
  1534. ucal_getWindowsTimeZoneID(const UChar* id, int32_t len,
  1535. UChar* winid, int32_t winidCapacity, UErrorCode* status);
  1536. /**
  1537. * Converts a Windows time zone ID to an equivalent system time zone ID
  1538. * for a region. For example, system time zone ID "America/Los_Angeles" is returned
  1539. * for input Windows ID "Pacific Standard Time" and region "US" (or <code>null</code>),
  1540. * "America/Vancouver" is returned for the same Windows ID "Pacific Standard Time" and
  1541. * region "CA".
  1542. *
  1543. * <p>Not all Windows time zones can be mapped to system time zones. When the input
  1544. * Windows time zone ID is unknown or unmappable to a system time zone, then this
  1545. * function returns 0 as the result length, but the operation itself remains successful
  1546. * (no error status set on return).
  1547. *
  1548. * <p>This implementation utilizes <a href="http://unicode.org/cldr/charts/supplemental/zone_tzid.html">
  1549. * Zone-Tzid mapping data</a>. The mapping data is updated time to time. To get the latest changes,
  1550. * please read the ICU user guide section <a href="https://unicode-org.github.io/icu/userguide/datetime/timezone#updating-the-time-zone-data">
  1551. * Updating the Time Zone Data</a>.
  1552. *
  1553. * @param winid A Windows time zone ID.
  1554. * @param len The length of <code>winid</code>, or -1 if null-terminated.
  1555. * @param region A null-terminated region code, or <code>NULL</code> if no regional preference.
  1556. * @param id A buffer to receive a system time zone ID.
  1557. * @param idCapacity The capacity of the result buffer <code>id</code>.
  1558. * @param status Receives the status.
  1559. * @return The result string length, not including the terminating null.
  1560. * @see ucal_getWindowsTimeZoneID
  1561. *
  1562. * @stable ICU 52
  1563. */
  1564. U_CAPI int32_t U_EXPORT2
  1565. ucal_getTimeZoneIDForWindowsID(const UChar* winid, int32_t len, const char* region,
  1566. UChar* id, int32_t idCapacity, UErrorCode* status);
  1567. /**
  1568. * Options used by ucal_getTimeZoneOffsetFromLocal and BasicTimeZone::getOffsetFromLocal()
  1569. * to specify how to interpret an input time when it does not exist, or when it is ambiguous,
  1570. * around a time zone transition.
  1571. * @stable ICU 69
  1572. */
  1573. enum UTimeZoneLocalOption {
  1574. /**
  1575. * An input time is always interpreted as local time before
  1576. * a time zone transition.
  1577. * @stable ICU 69
  1578. */
  1579. UCAL_TZ_LOCAL_FORMER = 0x04,
  1580. /**
  1581. * An input time is always interpreted as local time after
  1582. * a time zone transition.
  1583. * @stable ICU 69
  1584. */
  1585. UCAL_TZ_LOCAL_LATTER = 0x0C,
  1586. /**
  1587. * An input time is interpreted as standard time when local
  1588. * time is switched to/from daylight saving time. When both
  1589. * sides of a time zone transition are standard time,
  1590. * or daylight saving time, the local time before the
  1591. * transition is used.
  1592. * @stable ICU 69
  1593. */
  1594. UCAL_TZ_LOCAL_STANDARD_FORMER = UCAL_TZ_LOCAL_FORMER | 0x01,
  1595. /**
  1596. * An input time is interpreted as standard time when local
  1597. * time is switched to/from daylight saving time. When both
  1598. * sides of a time zone transition are standard time,
  1599. * or daylight saving time, the local time after the
  1600. * transition is used.
  1601. * @stable ICU 69
  1602. */
  1603. UCAL_TZ_LOCAL_STANDARD_LATTER = UCAL_TZ_LOCAL_LATTER | 0x01,
  1604. /**
  1605. * An input time is interpreted as daylight saving time when
  1606. * local time is switched to/from standard time. When both
  1607. * sides of a time zone transition are standard time,
  1608. * or daylight saving time, the local time before the
  1609. * transition is used.
  1610. * @stable ICU 69
  1611. */
  1612. UCAL_TZ_LOCAL_DAYLIGHT_FORMER = UCAL_TZ_LOCAL_FORMER | 0x03,
  1613. /**
  1614. * An input time is interpreted as daylight saving time when
  1615. * local time is switched to/from standard time. When both
  1616. * sides of a time zone transition are standard time,
  1617. * or daylight saving time, the local time after the
  1618. * transition is used.
  1619. * @stable ICU 69
  1620. */
  1621. UCAL_TZ_LOCAL_DAYLIGHT_LATTER = UCAL_TZ_LOCAL_LATTER | 0x03,
  1622. };
  1623. typedef enum UTimeZoneLocalOption UTimeZoneLocalOption; /**< @stable ICU 69 */
  1624. /**
  1625. * Returns the time zone raw and GMT offset for the given moment
  1626. * in time. Upon return, local-millis = GMT-millis + rawOffset +
  1627. * dstOffset. All computations are performed in the proleptic
  1628. * Gregorian calendar.
  1629. *
  1630. * @param cal The UCalendar which specify the local date and time value to query.
  1631. * @param nonExistingTimeOpt The option to indicate how to interpret the date and
  1632. * time in the calendar represent a local time that skipped at a positive time
  1633. * zone transitions (e.g. when the daylight saving time starts or the time zone
  1634. * offset is increased due to a time zone rule change).
  1635. * @param duplicatedTimeOpt The option to indicate how to interpret the date and
  1636. * time in the calendar represent a local time that repeating multiple times at a
  1637. * negative time zone transition (e.g. when the daylight saving time ends or the
  1638. * time zone offset is decreased due to a time zone rule change)
  1639. * @param rawOffset output parameter to receive the raw offset, that
  1640. * is, the offset not including DST adjustments.
  1641. * If the status is set to one of the error code, the value set is unspecified.
  1642. * @param dstOffset output parameter to receive the DST offset,
  1643. * that is, the offset to be added to `rawOffset' to obtain the
  1644. * total offset between local and GMT time. If DST is not in
  1645. * effect, this value is zero; otherwise it is a positive value,
  1646. * typically one hour.
  1647. * If the status is set to one of the error code, the value set is unspecified.
  1648. * @param status A pointer to a UErrorCode to receive any errors.
  1649. * @stable ICU 69
  1650. */
  1651. U_CAPI void U_EXPORT2
  1652. ucal_getTimeZoneOffsetFromLocal(
  1653. const UCalendar* cal,
  1654. UTimeZoneLocalOption nonExistingTimeOpt,
  1655. UTimeZoneLocalOption duplicatedTimeOpt,
  1656. int32_t* rawOffset, int32_t* dstOffset, UErrorCode* status);
  1657. #endif /* #if !UCONFIG_NO_FORMATTING */
  1658. #endif