ucal.h 54 KB

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