ucal.h 62 KB

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