ucal.h 55 KB

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