calendar.h 105 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551
  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) 1997-2014, International Business Machines
  6. * Corporation and others. All Rights Reserved.
  7. ********************************************************************************
  8. *
  9. * File CALENDAR.H
  10. *
  11. * Modification History:
  12. *
  13. * Date Name Description
  14. * 04/22/97 aliu Expanded and corrected comments and other header
  15. * contents.
  16. * 05/01/97 aliu Made equals(), before(), after() arguments const.
  17. * 05/20/97 aliu Replaced fAreFieldsSet with fAreFieldsInSync and
  18. * fAreAllFieldsSet.
  19. * 07/27/98 stephen Sync up with JDK 1.2
  20. * 11/15/99 weiv added YEAR_WOY and DOW_LOCAL
  21. * to EDateFields
  22. * 8/19/2002 srl Removed Javaisms
  23. * 11/07/2003 srl Update, clean up documentation.
  24. ********************************************************************************
  25. */
  26. #ifndef CALENDAR_H
  27. #define CALENDAR_H
  28. #include "unicode/utypes.h"
  29. /**
  30. * \file
  31. * \brief C++ API: Calendar object
  32. */
  33. #if !UCONFIG_NO_FORMATTING
  34. #include "unicode/uobject.h"
  35. #include "unicode/locid.h"
  36. #include "unicode/timezone.h"
  37. #include "unicode/ucal.h"
  38. #include "unicode/umisc.h"
  39. U_NAMESPACE_BEGIN
  40. class ICUServiceFactory;
  41. /**
  42. * @internal
  43. */
  44. typedef int32_t UFieldResolutionTable[12][8];
  45. class BasicTimeZone;
  46. /**
  47. * <code>Calendar</code> is an abstract base class for converting between
  48. * a <code>UDate</code> object and a set of integer fields such as
  49. * <code>YEAR</code>, <code>MONTH</code>, <code>DAY</code>, <code>HOUR</code>,
  50. * and so on. (A <code>UDate</code> object represents a specific instant in
  51. * time with millisecond precision. See UDate
  52. * for information about the <code>UDate</code> class.)
  53. *
  54. * <p>
  55. * Subclasses of <code>Calendar</code> interpret a <code>UDate</code>
  56. * according to the rules of a specific calendar system.
  57. * The most commonly used subclass of <code>Calendar</code> is
  58. * <code>GregorianCalendar</code>. Other subclasses could represent
  59. * the various types of lunar calendars in use in many parts of the world.
  60. *
  61. * <p>
  62. * <b>NOTE</b>: (ICU 2.6) The subclass interface should be considered unstable
  63. * - it WILL change.
  64. *
  65. * <p>
  66. * Like other locale-sensitive classes, <code>Calendar</code> provides a
  67. * static method, <code>createInstance</code>, for getting a generally useful
  68. * object of this type. <code>Calendar</code>'s <code>createInstance</code> method
  69. * returns the appropriate <code>Calendar</code> subclass whose
  70. * time fields have been initialized with the current date and time:
  71. * \htmlonly<blockquote>\endhtmlonly
  72. * <pre>
  73. * Calendar *rightNow = Calendar::createInstance(errCode);
  74. * </pre>
  75. * \htmlonly</blockquote>\endhtmlonly
  76. *
  77. * <p>
  78. * A <code>Calendar</code> object can produce all the time field values
  79. * needed to implement the date-time formatting for a particular language
  80. * and calendar style (for example, Japanese-Gregorian, Japanese-Traditional).
  81. *
  82. * <p>
  83. * When computing a <code>UDate</code> from time fields, some special circumstances
  84. * may arise: there may be insufficient information to compute the
  85. * <code>UDate</code> (such as only year and month but no day in the month),
  86. * there may be inconsistent information (such as "Tuesday, July 15, 1996"
  87. * -- July 15, 1996 is actually a Monday), or the input time might be ambiguous
  88. * because of time zone transition.
  89. *
  90. * <p>
  91. * <strong>Insufficient information.</strong> The calendar will use default
  92. * information to specify the missing fields. This may vary by calendar; for
  93. * the Gregorian calendar, the default for a field is the same as that of the
  94. * start of the epoch: i.e., YEAR = 1970, MONTH = JANUARY, DATE = 1, etc.
  95. *
  96. * <p>
  97. * <strong>Inconsistent information.</strong> If fields conflict, the calendar
  98. * will give preference to fields set more recently. For example, when
  99. * determining the day, the calendar will look for one of the following
  100. * combinations of fields. The most recent combination, as determined by the
  101. * most recently set single field, will be used.
  102. *
  103. * \htmlonly<blockquote>\endhtmlonly
  104. * <pre>
  105. * MONTH + DAY_OF_MONTH
  106. * MONTH + WEEK_OF_MONTH + DAY_OF_WEEK
  107. * MONTH + DAY_OF_WEEK_IN_MONTH + DAY_OF_WEEK
  108. * DAY_OF_YEAR
  109. * DAY_OF_WEEK + WEEK_OF_YEAR
  110. * </pre>
  111. * \htmlonly</blockquote>\endhtmlonly
  112. *
  113. * For the time of day:
  114. *
  115. * \htmlonly<blockquote>\endhtmlonly
  116. * <pre>
  117. * HOUR_OF_DAY
  118. * AM_PM + HOUR
  119. * </pre>
  120. * \htmlonly</blockquote>\endhtmlonly
  121. *
  122. * <p>
  123. * <strong>Ambiguous Wall Clock Time.</strong> When time offset from UTC has
  124. * changed, it produces an ambiguous time slot around the transition. For example,
  125. * many US locations observe daylight saving time. On the date switching to daylight
  126. * saving time in US, wall clock time jumps from 12:59 AM (standard) to 2:00 AM
  127. * (daylight). Therefore, wall clock time from 1:00 AM to 1:59 AM do not exist on
  128. * the date. When the input wall time fall into this missing time slot, the ICU
  129. * Calendar resolves the time using the UTC offset before the transition by default.
  130. * In this example, 1:30 AM is interpreted as 1:30 AM standard time (non-exist),
  131. * so the final result will be 2:30 AM daylight time.
  132. *
  133. * <p>On the date switching back to standard time, wall clock time is moved back one
  134. * hour at 2:00 AM. So wall clock time from 1:00 AM to 1:59 AM occur twice. In this
  135. * case, the ICU Calendar resolves the time using the UTC offset after the transition
  136. * by default. For example, 1:30 AM on the date is resolved as 1:30 AM standard time.
  137. *
  138. * <p>Ambiguous wall clock time resolution behaviors can be customized by Calendar APIs
  139. * {@link #setRepeatedWallTimeOption} and {@link #setSkippedWallTimeOption}.
  140. * These methods are available in ICU 49 or later versions.
  141. *
  142. * <p>
  143. * <strong>Note:</strong> for some non-Gregorian calendars, different
  144. * fields may be necessary for complete disambiguation. For example, a full
  145. * specification of the historial Arabic astronomical calendar requires year,
  146. * month, day-of-month <em>and</em> day-of-week in some cases.
  147. *
  148. * <p>
  149. * <strong>Note:</strong> There are certain possible ambiguities in
  150. * interpretation of certain singular times, which are resolved in the
  151. * following ways:
  152. * <ol>
  153. * <li> 24:00:00 "belongs" to the following day. That is,
  154. * 23:59 on Dec 31, 1969 &lt; 24:00 on Jan 1, 1970 &lt; 24:01:00 on Jan 1, 1970
  155. *
  156. * <li> Although historically not precise, midnight also belongs to "am",
  157. * and noon belongs to "pm", so on the same day,
  158. * 12:00 am (midnight) &lt; 12:01 am, and 12:00 pm (noon) &lt; 12:01 pm
  159. * </ol>
  160. *
  161. * <p>
  162. * The date or time format strings are not part of the definition of a
  163. * calendar, as those must be modifiable or overridable by the user at
  164. * runtime. Use {@link DateFormat}
  165. * to format dates.
  166. *
  167. * <p>
  168. * <code>Calendar</code> provides an API for field "rolling", where fields
  169. * can be incremented or decremented, but wrap around. For example, rolling the
  170. * month up in the date <code>December 12, <b>1996</b></code> results in
  171. * <code>January 12, <b>1996</b></code>.
  172. *
  173. * <p>
  174. * <code>Calendar</code> also provides a date arithmetic function for
  175. * adding the specified (signed) amount of time to a particular time field.
  176. * For example, subtracting 5 days from the date <code>September 12, 1996</code>
  177. * results in <code>September 7, 1996</code>.
  178. *
  179. * <p><big><b>Supported range</b></big>
  180. *
  181. * <p>The allowable range of <code>Calendar</code> has been
  182. * narrowed. <code>GregorianCalendar</code> used to attempt to support
  183. * the range of dates with millisecond values from
  184. * <code>Long.MIN_VALUE</code> to <code>Long.MAX_VALUE</code>.
  185. * The new <code>Calendar</code> protocol specifies the
  186. * maximum range of supportable dates as those having Julian day numbers
  187. * of <code>-0x7F000000</code> to <code>+0x7F000000</code>. This
  188. * corresponds to years from ~5,800,000 BCE to ~5,800,000 CE. Programmers
  189. * should use the protected constants in <code>Calendar</code> to
  190. * specify an extremely early or extremely late date.</p>
  191. *
  192. * @stable ICU 2.0
  193. */
  194. class U_I18N_API Calendar : public UObject {
  195. public:
  196. /**
  197. * Field IDs for date and time. Used to specify date/time fields. ERA is calendar
  198. * specific. Example ranges given are for illustration only; see specific Calendar
  199. * subclasses for actual ranges.
  200. * @deprecated ICU 2.6. Use C enum UCalendarDateFields defined in ucal.h
  201. */
  202. enum EDateFields {
  203. #ifndef U_HIDE_DEPRECATED_API
  204. /*
  205. * ERA may be defined on other platforms. To avoid any potential problems undefined it here.
  206. */
  207. #ifdef ERA
  208. #undef ERA
  209. #endif
  210. ERA, // Example: 0..1
  211. YEAR, // Example: 1..big number
  212. MONTH, // Example: 0..11
  213. WEEK_OF_YEAR, // Example: 1..53
  214. WEEK_OF_MONTH, // Example: 1..4
  215. DATE, // Example: 1..31
  216. DAY_OF_YEAR, // Example: 1..365
  217. DAY_OF_WEEK, // Example: 1..7
  218. DAY_OF_WEEK_IN_MONTH, // Example: 1..4, may be specified as -1
  219. AM_PM, // Example: 0..1
  220. HOUR, // Example: 0..11
  221. HOUR_OF_DAY, // Example: 0..23
  222. MINUTE, // Example: 0..59
  223. SECOND, // Example: 0..59
  224. MILLISECOND, // Example: 0..999
  225. ZONE_OFFSET, // Example: -12*U_MILLIS_PER_HOUR..12*U_MILLIS_PER_HOUR
  226. DST_OFFSET, // Example: 0 or U_MILLIS_PER_HOUR
  227. YEAR_WOY, // 'Y' Example: 1..big number - Year of Week of Year
  228. DOW_LOCAL, // 'e' Example: 1..7 - Day of Week / Localized
  229. EXTENDED_YEAR,
  230. JULIAN_DAY,
  231. MILLISECONDS_IN_DAY,
  232. IS_LEAP_MONTH,
  233. FIELD_COUNT = UCAL_FIELD_COUNT // See ucal.h for other fields.
  234. #endif /* U_HIDE_DEPRECATED_API */
  235. };
  236. #ifndef U_HIDE_DEPRECATED_API
  237. /**
  238. * Useful constant for days of week. Note: Calendar day-of-week is 1-based. Clients
  239. * who create locale resources for the field of first-day-of-week should be aware of
  240. * this. For instance, in US locale, first-day-of-week is set to 1, i.e., SUNDAY.
  241. * @deprecated ICU 2.6. Use C enum UCalendarDaysOfWeek defined in ucal.h
  242. */
  243. enum EDaysOfWeek {
  244. SUNDAY = 1,
  245. MONDAY,
  246. TUESDAY,
  247. WEDNESDAY,
  248. THURSDAY,
  249. FRIDAY,
  250. SATURDAY
  251. };
  252. /**
  253. * Useful constants for month. Note: Calendar month is 0-based.
  254. * @deprecated ICU 2.6. Use C enum UCalendarMonths defined in ucal.h
  255. */
  256. enum EMonths {
  257. JANUARY,
  258. FEBRUARY,
  259. MARCH,
  260. APRIL,
  261. MAY,
  262. JUNE,
  263. JULY,
  264. AUGUST,
  265. SEPTEMBER,
  266. OCTOBER,
  267. NOVEMBER,
  268. DECEMBER,
  269. UNDECIMBER
  270. };
  271. /**
  272. * Useful constants for hour in 12-hour clock. Used in GregorianCalendar.
  273. * @deprecated ICU 2.6. Use C enum UCalendarAMPMs defined in ucal.h
  274. */
  275. enum EAmpm {
  276. AM,
  277. PM
  278. };
  279. #endif /* U_HIDE_DEPRECATED_API */
  280. /**
  281. * destructor
  282. * @stable ICU 2.0
  283. */
  284. virtual ~Calendar();
  285. /**
  286. * Create and return a polymorphic copy of this calendar.
  287. *
  288. * @return a polymorphic copy of this calendar.
  289. * @stable ICU 2.0
  290. */
  291. virtual Calendar* clone(void) const = 0;
  292. /**
  293. * Creates a Calendar using the default timezone and locale. Clients are responsible
  294. * for deleting the object returned.
  295. *
  296. * @param success Indicates the success/failure of Calendar creation. Filled in
  297. * with U_ZERO_ERROR if created successfully, set to a failure result
  298. * otherwise. U_MISSING_RESOURCE_ERROR will be returned if the resource data
  299. * requests a calendar type which has not been installed.
  300. * @return A Calendar if created successfully. NULL otherwise.
  301. * @stable ICU 2.0
  302. */
  303. static Calendar* U_EXPORT2 createInstance(UErrorCode& success);
  304. /**
  305. * Creates a Calendar using the given timezone and the default locale.
  306. * The Calendar takes ownership of zoneToAdopt; the
  307. * client must not delete it.
  308. *
  309. * @param zoneToAdopt The given timezone to be adopted.
  310. * @param success Indicates the success/failure of Calendar creation. Filled in
  311. * with U_ZERO_ERROR if created successfully, set to a failure result
  312. * otherwise.
  313. * @return A Calendar if created successfully. NULL otherwise.
  314. * @stable ICU 2.0
  315. */
  316. static Calendar* U_EXPORT2 createInstance(TimeZone* zoneToAdopt, UErrorCode& success);
  317. /**
  318. * Creates a Calendar using the given timezone and the default locale. The TimeZone
  319. * is _not_ adopted; the client is still responsible for deleting it.
  320. *
  321. * @param zone The timezone.
  322. * @param success Indicates the success/failure of Calendar creation. Filled in
  323. * with U_ZERO_ERROR if created successfully, set to a failure result
  324. * otherwise.
  325. * @return A Calendar if created successfully. NULL otherwise.
  326. * @stable ICU 2.0
  327. */
  328. static Calendar* U_EXPORT2 createInstance(const TimeZone& zone, UErrorCode& success);
  329. /**
  330. * Creates a Calendar using the default timezone and the given locale.
  331. *
  332. * @param aLocale The given locale.
  333. * @param success Indicates the success/failure of Calendar creation. Filled in
  334. * with U_ZERO_ERROR if created successfully, set to a failure result
  335. * otherwise.
  336. * @return A Calendar if created successfully. NULL otherwise.
  337. * @stable ICU 2.0
  338. */
  339. static Calendar* U_EXPORT2 createInstance(const Locale& aLocale, UErrorCode& success);
  340. /**
  341. * Creates a Calendar using the given timezone and given locale.
  342. * The Calendar takes ownership of zoneToAdopt; the
  343. * client must not delete it.
  344. *
  345. * @param zoneToAdopt The given timezone to be adopted.
  346. * @param aLocale The given locale.
  347. * @param success Indicates the success/failure of Calendar creation. Filled in
  348. * with U_ZERO_ERROR if created successfully, set to a failure result
  349. * otherwise.
  350. * @return A Calendar if created successfully. NULL otherwise.
  351. * @stable ICU 2.0
  352. */
  353. static Calendar* U_EXPORT2 createInstance(TimeZone* zoneToAdopt, const Locale& aLocale, UErrorCode& success);
  354. /**
  355. * Gets a Calendar using the given timezone and given locale. The TimeZone
  356. * is _not_ adopted; the client is still responsible for deleting it.
  357. *
  358. * @param zone The given timezone.
  359. * @param aLocale The given locale.
  360. * @param success Indicates the success/failure of Calendar creation. Filled in
  361. * with U_ZERO_ERROR if created successfully, set to a failure result
  362. * otherwise.
  363. * @return A Calendar if created successfully. NULL otherwise.
  364. * @stable ICU 2.0
  365. */
  366. static Calendar* U_EXPORT2 createInstance(const TimeZone& zone, const Locale& aLocale, UErrorCode& success);
  367. /**
  368. * Returns a list of the locales for which Calendars are installed.
  369. *
  370. * @param count Number of locales returned.
  371. * @return An array of Locale objects representing the set of locales for which
  372. * Calendars are installed. The system retains ownership of this list;
  373. * the caller must NOT delete it. Does not include user-registered Calendars.
  374. * @stable ICU 2.0
  375. */
  376. static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
  377. /**
  378. * Given a key and a locale, returns an array of string values in a preferred
  379. * order that would make a difference. These are all and only those values where
  380. * the open (creation) of the service with the locale formed from the input locale
  381. * plus input keyword and that value has different behavior than creation with the
  382. * input locale alone.
  383. * @param key one of the keys supported by this service. For now, only
  384. * "calendar" is supported.
  385. * @param locale the locale
  386. * @param commonlyUsed if set to true it will return only commonly used values
  387. * with the given locale in preferred order. Otherwise,
  388. * it will return all the available values for the locale.
  389. * @param status ICU Error Code
  390. * @return a string enumeration over keyword values for the given key and the locale.
  391. * @stable ICU 4.2
  392. */
  393. static StringEnumeration* U_EXPORT2 getKeywordValuesForLocale(const char* key,
  394. const Locale& locale, UBool commonlyUsed, UErrorCode& status);
  395. /**
  396. * Returns the current UTC (GMT) time measured in milliseconds since 0:00:00 on 1/1/70
  397. * (derived from the system time).
  398. *
  399. * @return The current UTC time in milliseconds.
  400. * @stable ICU 2.0
  401. */
  402. static UDate U_EXPORT2 getNow(void);
  403. /**
  404. * Gets this Calendar's time as milliseconds. May involve recalculation of time due
  405. * to previous calls to set time field values. The time specified is non-local UTC
  406. * (GMT) time. Although this method is const, this object may actually be changed
  407. * (semantically const).
  408. *
  409. * @param status Output param set to success/failure code on exit. If any value
  410. * previously set in the time field is invalid or restricted by
  411. * leniency, this will be set to an error status.
  412. * @return The current time in UTC (GMT) time, or zero if the operation
  413. * failed.
  414. * @stable ICU 2.0
  415. */
  416. inline UDate getTime(UErrorCode& status) const { return getTimeInMillis(status); }
  417. /**
  418. * Sets this Calendar's current time with the given UDate. The time specified should
  419. * be in non-local UTC (GMT) time.
  420. *
  421. * @param date The given UDate in UTC (GMT) time.
  422. * @param status Output param set to success/failure code on exit. If any value
  423. * set in the time field is invalid or restricted by
  424. * leniency, this will be set to an error status.
  425. * @stable ICU 2.0
  426. */
  427. inline void setTime(UDate date, UErrorCode& status) { setTimeInMillis(date, status); }
  428. /**
  429. * Compares the equality of two Calendar objects. Objects of different subclasses
  430. * are considered unequal. This comparison is very exacting; two Calendar objects
  431. * must be in exactly the same state to be considered equal. To compare based on the
  432. * represented time, use equals() instead.
  433. *
  434. * @param that The Calendar object to be compared with.
  435. * @return True if the given Calendar is the same as this Calendar; false
  436. * otherwise.
  437. * @stable ICU 2.0
  438. */
  439. virtual UBool operator==(const Calendar& that) const;
  440. /**
  441. * Compares the inequality of two Calendar objects.
  442. *
  443. * @param that The Calendar object to be compared with.
  444. * @return True if the given Calendar is not the same as this Calendar; false
  445. * otherwise.
  446. * @stable ICU 2.0
  447. */
  448. UBool operator!=(const Calendar& that) const {return !operator==(that);}
  449. /**
  450. * Returns TRUE if the given Calendar object is equivalent to this
  451. * one. An equivalent Calendar will behave exactly as this one
  452. * does, but it may be set to a different time. By contrast, for
  453. * the operator==() method to return TRUE, the other Calendar must
  454. * be set to the same time.
  455. *
  456. * @param other the Calendar to be compared with this Calendar
  457. * @stable ICU 2.4
  458. */
  459. virtual UBool isEquivalentTo(const Calendar& other) const;
  460. /**
  461. * Compares the Calendar time, whereas Calendar::operator== compares the equality of
  462. * Calendar objects.
  463. *
  464. * @param when The Calendar to be compared with this Calendar. Although this is a
  465. * const parameter, the object may be modified physically
  466. * (semantically const).
  467. * @param status Output param set to success/failure code on exit. If any value
  468. * previously set in the time field is invalid or restricted by
  469. * leniency, this will be set to an error status.
  470. * @return True if the current time of this Calendar is equal to the time of
  471. * Calendar when; false otherwise.
  472. * @stable ICU 2.0
  473. */
  474. UBool equals(const Calendar& when, UErrorCode& status) const;
  475. /**
  476. * Returns true if this Calendar's current time is before "when"'s current time.
  477. *
  478. * @param when The Calendar to be compared with this Calendar. Although this is a
  479. * const parameter, the object may be modified physically
  480. * (semantically const).
  481. * @param status Output param set to success/failure code on exit. If any value
  482. * previously set in the time field is invalid or restricted by
  483. * leniency, this will be set to an error status.
  484. * @return True if the current time of this Calendar is before the time of
  485. * Calendar when; false otherwise.
  486. * @stable ICU 2.0
  487. */
  488. UBool before(const Calendar& when, UErrorCode& status) const;
  489. /**
  490. * Returns true if this Calendar's current time is after "when"'s current time.
  491. *
  492. * @param when The Calendar to be compared with this Calendar. Although this is a
  493. * const parameter, the object may be modified physically
  494. * (semantically const).
  495. * @param status Output param set to success/failure code on exit. If any value
  496. * previously set in the time field is invalid or restricted by
  497. * leniency, this will be set to an error status.
  498. * @return True if the current time of this Calendar is after the time of
  499. * Calendar when; false otherwise.
  500. * @stable ICU 2.0
  501. */
  502. UBool after(const Calendar& when, UErrorCode& status) const;
  503. /**
  504. * UDate Arithmetic function. Adds the specified (signed) amount of time to the given
  505. * time field, based on the calendar's rules. For example, to subtract 5 days from
  506. * the current time of the calendar, call add(Calendar::DATE, -5). When adding on
  507. * the month or Calendar::MONTH field, other fields like date might conflict and
  508. * need to be changed. For instance, adding 1 month on the date 01/31/96 will result
  509. * in 02/29/96.
  510. * Adding a positive value always means moving forward in time, so for the Gregorian calendar,
  511. * starting with 100 BC and adding +1 to year results in 99 BC (even though this actually reduces
  512. * the numeric value of the field itself).
  513. *
  514. * @param field Specifies which date field to modify.
  515. * @param amount The amount of time to be added to the field, in the natural unit
  516. * for that field (e.g., days for the day fields, hours for the hour
  517. * field.)
  518. * @param status Output param set to success/failure code on exit. If any value
  519. * previously set in the time field is invalid or restricted by
  520. * leniency, this will be set to an error status.
  521. * @deprecated ICU 2.6. use add(UCalendarDateFields field, int32_t amount, UErrorCode& status) instead.
  522. */
  523. virtual void add(EDateFields field, int32_t amount, UErrorCode& status);
  524. /**
  525. * UDate Arithmetic function. Adds the specified (signed) amount of time to the given
  526. * time field, based on the calendar's rules. For example, to subtract 5 days from
  527. * the current time of the calendar, call add(Calendar::DATE, -5). When adding on
  528. * the month or Calendar::MONTH field, other fields like date might conflict and
  529. * need to be changed. For instance, adding 1 month on the date 01/31/96 will result
  530. * in 02/29/96.
  531. * Adding a positive value always means moving forward in time, so for the Gregorian calendar,
  532. * starting with 100 BC and adding +1 to year results in 99 BC (even though this actually reduces
  533. * the numeric value of the field itself).
  534. *
  535. * @param field Specifies which date field to modify.
  536. * @param amount The amount of time to be added to the field, in the natural unit
  537. * for that field (e.g., days for the day fields, hours for the hour
  538. * field.)
  539. * @param status Output param set to success/failure code on exit. If any value
  540. * previously set in the time field is invalid or restricted by
  541. * leniency, this will be set to an error status.
  542. * @stable ICU 2.6.
  543. */
  544. virtual void add(UCalendarDateFields field, int32_t amount, UErrorCode& status);
  545. #ifndef U_HIDE_DEPRECATED_API
  546. /**
  547. * Time Field Rolling function. Rolls (up/down) a single unit of time on the given
  548. * time field. For example, to roll the current date up by one day, call
  549. * roll(Calendar::DATE, true). When rolling on the year or Calendar::YEAR field, it
  550. * will roll the year value in the range between getMinimum(Calendar::YEAR) and the
  551. * value returned by getMaximum(Calendar::YEAR). When rolling on the month or
  552. * Calendar::MONTH field, other fields like date might conflict and, need to be
  553. * changed. For instance, rolling the month up on the date 01/31/96 will result in
  554. * 02/29/96. Rolling up always means rolling forward in time (unless the limit of the
  555. * field is reached, in which case it may pin or wrap), so for Gregorian calendar,
  556. * starting with 100 BC and rolling the year up results in 99 BC.
  557. * When eras have a definite beginning and end (as in the Chinese calendar, or as in
  558. * most eras in the Japanese calendar) then rolling the year past either limit of the
  559. * era will cause the year to wrap around. When eras only have a limit at one end,
  560. * then attempting to roll the year past that limit will result in pinning the year
  561. * at that limit. Note that for most calendars in which era 0 years move forward in
  562. * time (such as Buddhist, Hebrew, or Islamic), it is possible for add or roll to
  563. * result in negative years for era 0 (that is the only way to represent years before
  564. * the calendar epoch).
  565. * When rolling on the hour-in-day or Calendar::HOUR_OF_DAY field, it will roll the
  566. * hour value in the range between 0 and 23, which is zero-based.
  567. * <P>
  568. * NOTE: Do not use this method -- use roll(EDateFields, int, UErrorCode&) instead.
  569. *
  570. * @param field The time field.
  571. * @param up Indicates if the value of the specified time field is to be rolled
  572. * up or rolled down. Use true if rolling up, false otherwise.
  573. * @param status Output param set to success/failure code on exit. If any value
  574. * previously set in the time field is invalid or restricted by
  575. * leniency, this will be set to an error status.
  576. * @deprecated ICU 2.6. Use roll(UCalendarDateFields field, UBool up, UErrorCode& status) instead.
  577. */
  578. inline void roll(EDateFields field, UBool up, UErrorCode& status);
  579. #endif /* U_HIDE_DEPRECATED_API */
  580. /**
  581. * Time Field Rolling function. Rolls (up/down) a single unit of time on the given
  582. * time field. For example, to roll the current date up by one day, call
  583. * roll(Calendar::DATE, true). When rolling on the year or Calendar::YEAR field, it
  584. * will roll the year value in the range between getMinimum(Calendar::YEAR) and the
  585. * value returned by getMaximum(Calendar::YEAR). When rolling on the month or
  586. * Calendar::MONTH field, other fields like date might conflict and, need to be
  587. * changed. For instance, rolling the month up on the date 01/31/96 will result in
  588. * 02/29/96. Rolling up always means rolling forward in time (unless the limit of the
  589. * field is reached, in which case it may pin or wrap), so for Gregorian calendar,
  590. * starting with 100 BC and rolling the year up results in 99 BC.
  591. * When eras have a definite beginning and end (as in the Chinese calendar, or as in
  592. * most eras in the Japanese calendar) then rolling the year past either limit of the
  593. * era will cause the year to wrap around. When eras only have a limit at one end,
  594. * then attempting to roll the year past that limit will result in pinning the year
  595. * at that limit. Note that for most calendars in which era 0 years move forward in
  596. * time (such as Buddhist, Hebrew, or Islamic), it is possible for add or roll to
  597. * result in negative years for era 0 (that is the only way to represent years before
  598. * the calendar epoch).
  599. * When rolling on the hour-in-day or Calendar::HOUR_OF_DAY field, it will roll the
  600. * hour value in the range between 0 and 23, which is zero-based.
  601. * <P>
  602. * NOTE: Do not use this method -- use roll(UCalendarDateFields, int, UErrorCode&) instead.
  603. *
  604. * @param field The time field.
  605. * @param up Indicates if the value of the specified time field is to be rolled
  606. * up or rolled down. Use true if rolling up, false otherwise.
  607. * @param status Output param set to success/failure code on exit. If any value
  608. * previously set in the time field is invalid or restricted by
  609. * leniency, this will be set to an error status.
  610. * @stable ICU 2.6.
  611. */
  612. inline void roll(UCalendarDateFields field, UBool up, UErrorCode& status);
  613. /**
  614. * Time Field Rolling function. Rolls by the given amount on the given
  615. * time field. For example, to roll the current date up by one day, call
  616. * roll(Calendar::DATE, +1, status). When rolling on the month or
  617. * Calendar::MONTH field, other fields like date might conflict and, need to be
  618. * changed. For instance, rolling the month up on the date 01/31/96 will result in
  619. * 02/29/96. Rolling by a positive value always means rolling forward in time (unless
  620. * the limit of the field is reached, in which case it may pin or wrap), so for
  621. * Gregorian calendar, starting with 100 BC and rolling the year by + 1 results in 99 BC.
  622. * When eras have a definite beginning and end (as in the Chinese calendar, or as in
  623. * most eras in the Japanese calendar) then rolling the year past either limit of the
  624. * era will cause the year to wrap around. When eras only have a limit at one end,
  625. * then attempting to roll the year past that limit will result in pinning the year
  626. * at that limit. Note that for most calendars in which era 0 years move forward in
  627. * time (such as Buddhist, Hebrew, or Islamic), it is possible for add or roll to
  628. * result in negative years for era 0 (that is the only way to represent years before
  629. * the calendar epoch).
  630. * When rolling on the hour-in-day or Calendar::HOUR_OF_DAY field, it will roll the
  631. * hour value in the range between 0 and 23, which is zero-based.
  632. * <P>
  633. * The only difference between roll() and add() is that roll() does not change
  634. * the value of more significant fields when it reaches the minimum or maximum
  635. * of its range, whereas add() does.
  636. *
  637. * @param field The time field.
  638. * @param amount Indicates amount to roll.
  639. * @param status Output param set to success/failure code on exit. If any value
  640. * previously set in the time field is invalid, this will be set to
  641. * an error status.
  642. * @deprecated ICU 2.6. Use roll(UCalendarDateFields field, int32_t amount, UErrorCode& status) instead.
  643. */
  644. virtual void roll(EDateFields field, int32_t amount, UErrorCode& status);
  645. /**
  646. * Time Field Rolling function. Rolls by the given amount on the given
  647. * time field. For example, to roll the current date up by one day, call
  648. * roll(Calendar::DATE, +1, status). When rolling on the month or
  649. * Calendar::MONTH field, other fields like date might conflict and, need to be
  650. * changed. For instance, rolling the month up on the date 01/31/96 will result in
  651. * 02/29/96. Rolling by a positive value always means rolling forward in time (unless
  652. * the limit of the field is reached, in which case it may pin or wrap), so for
  653. * Gregorian calendar, starting with 100 BC and rolling the year by + 1 results in 99 BC.
  654. * When eras have a definite beginning and end (as in the Chinese calendar, or as in
  655. * most eras in the Japanese calendar) then rolling the year past either limit of the
  656. * era will cause the year to wrap around. When eras only have a limit at one end,
  657. * then attempting to roll the year past that limit will result in pinning the year
  658. * at that limit. Note that for most calendars in which era 0 years move forward in
  659. * time (such as Buddhist, Hebrew, or Islamic), it is possible for add or roll to
  660. * result in negative years for era 0 (that is the only way to represent years before
  661. * the calendar epoch).
  662. * When rolling on the hour-in-day or Calendar::HOUR_OF_DAY field, it will roll the
  663. * hour value in the range between 0 and 23, which is zero-based.
  664. * <P>
  665. * The only difference between roll() and add() is that roll() does not change
  666. * the value of more significant fields when it reaches the minimum or maximum
  667. * of its range, whereas add() does.
  668. *
  669. * @param field The time field.
  670. * @param amount Indicates amount to roll.
  671. * @param status Output param set to success/failure code on exit. If any value
  672. * previously set in the time field is invalid, this will be set to
  673. * an error status.
  674. * @stable ICU 2.6.
  675. */
  676. virtual void roll(UCalendarDateFields field, int32_t amount, UErrorCode& status);
  677. /**
  678. * Return the difference between the given time and the time this
  679. * calendar object is set to. If this calendar is set
  680. * <em>before</em> the given time, the returned value will be
  681. * positive. If this calendar is set <em>after</em> the given
  682. * time, the returned value will be negative. The
  683. * <code>field</code> parameter specifies the units of the return
  684. * value. For example, if <code>fieldDifference(when,
  685. * Calendar::MONTH)</code> returns 3, then this calendar is set to
  686. * 3 months before <code>when</code>, and possibly some addition
  687. * time less than one month.
  688. *
  689. * <p>As a side effect of this call, this calendar is advanced
  690. * toward <code>when</code> by the given amount. That is, calling
  691. * this method has the side effect of calling <code>add(field,
  692. * n)</code>, where <code>n</code> is the return value.
  693. *
  694. * <p>Usage: To use this method, call it first with the largest
  695. * field of interest, then with progressively smaller fields. For
  696. * example:
  697. *
  698. * <pre>
  699. * int y = cal->fieldDifference(when, Calendar::YEAR, err);
  700. * int m = cal->fieldDifference(when, Calendar::MONTH, err);
  701. * int d = cal->fieldDifference(when, Calendar::DATE, err);</pre>
  702. *
  703. * computes the difference between <code>cal</code> and
  704. * <code>when</code> in years, months, and days.
  705. *
  706. * <p>Note: <code>fieldDifference()</code> is
  707. * <em>asymmetrical</em>. That is, in the following code:
  708. *
  709. * <pre>
  710. * cal->setTime(date1, err);
  711. * int m1 = cal->fieldDifference(date2, Calendar::MONTH, err);
  712. * int d1 = cal->fieldDifference(date2, Calendar::DATE, err);
  713. * cal->setTime(date2, err);
  714. * int m2 = cal->fieldDifference(date1, Calendar::MONTH, err);
  715. * int d2 = cal->fieldDifference(date1, Calendar::DATE, err);</pre>
  716. *
  717. * one might expect that <code>m1 == -m2 && d1 == -d2</code>.
  718. * However, this is not generally the case, because of
  719. * irregularities in the underlying calendar system (e.g., the
  720. * Gregorian calendar has a varying number of days per month).
  721. *
  722. * @param when the date to compare this calendar's time to
  723. * @param field the field in which to compute the result
  724. * @param status Output param set to success/failure code on exit. If any value
  725. * previously set in the time field is invalid, this will be set to
  726. * an error status.
  727. * @return the difference, either positive or negative, between
  728. * this calendar's time and <code>when</code>, in terms of
  729. * <code>field</code>.
  730. * @deprecated ICU 2.6. Use fieldDifference(UDate when, UCalendarDateFields field, UErrorCode& status).
  731. */
  732. virtual int32_t fieldDifference(UDate when, EDateFields field, UErrorCode& status);
  733. /**
  734. * Return the difference between the given time and the time this
  735. * calendar object is set to. If this calendar is set
  736. * <em>before</em> the given time, the returned value will be
  737. * positive. If this calendar is set <em>after</em> the given
  738. * time, the returned value will be negative. The
  739. * <code>field</code> parameter specifies the units of the return
  740. * value. For example, if <code>fieldDifference(when,
  741. * Calendar::MONTH)</code> returns 3, then this calendar is set to
  742. * 3 months before <code>when</code>, and possibly some addition
  743. * time less than one month.
  744. *
  745. * <p>As a side effect of this call, this calendar is advanced
  746. * toward <code>when</code> by the given amount. That is, calling
  747. * this method has the side effect of calling <code>add(field,
  748. * n)</code>, where <code>n</code> is the return value.
  749. *
  750. * <p>Usage: To use this method, call it first with the largest
  751. * field of interest, then with progressively smaller fields. For
  752. * example:
  753. *
  754. * <pre>
  755. * int y = cal->fieldDifference(when, Calendar::YEAR, err);
  756. * int m = cal->fieldDifference(when, Calendar::MONTH, err);
  757. * int d = cal->fieldDifference(when, Calendar::DATE, err);</pre>
  758. *
  759. * computes the difference between <code>cal</code> and
  760. * <code>when</code> in years, months, and days.
  761. *
  762. * <p>Note: <code>fieldDifference()</code> is
  763. * <em>asymmetrical</em>. That is, in the following code:
  764. *
  765. * <pre>
  766. * cal->setTime(date1, err);
  767. * int m1 = cal->fieldDifference(date2, Calendar::MONTH, err);
  768. * int d1 = cal->fieldDifference(date2, Calendar::DATE, err);
  769. * cal->setTime(date2, err);
  770. * int m2 = cal->fieldDifference(date1, Calendar::MONTH, err);
  771. * int d2 = cal->fieldDifference(date1, Calendar::DATE, err);</pre>
  772. *
  773. * one might expect that <code>m1 == -m2 && d1 == -d2</code>.
  774. * However, this is not generally the case, because of
  775. * irregularities in the underlying calendar system (e.g., the
  776. * Gregorian calendar has a varying number of days per month).
  777. *
  778. * @param when the date to compare this calendar's time to
  779. * @param field the field in which to compute the result
  780. * @param status Output param set to success/failure code on exit. If any value
  781. * previously set in the time field is invalid, this will be set to
  782. * an error status.
  783. * @return the difference, either positive or negative, between
  784. * this calendar's time and <code>when</code>, in terms of
  785. * <code>field</code>.
  786. * @stable ICU 2.6.
  787. */
  788. virtual int32_t fieldDifference(UDate when, UCalendarDateFields field, UErrorCode& status);
  789. /**
  790. * Sets the calendar's time zone to be the one passed in. The Calendar takes ownership
  791. * of the TimeZone; the caller is no longer responsible for deleting it. If the
  792. * given time zone is NULL, this function has no effect.
  793. *
  794. * @param value The given time zone.
  795. * @stable ICU 2.0
  796. */
  797. void adoptTimeZone(TimeZone* value);
  798. /**
  799. * Sets the calendar's time zone to be the same as the one passed in. The TimeZone
  800. * passed in is _not_ adopted; the client is still responsible for deleting it.
  801. *
  802. * @param zone The given time zone.
  803. * @stable ICU 2.0
  804. */
  805. void setTimeZone(const TimeZone& zone);
  806. /**
  807. * Returns a reference to the time zone owned by this calendar. The returned reference
  808. * is only valid until clients make another call to adoptTimeZone or setTimeZone,
  809. * or this Calendar is destroyed.
  810. *
  811. * @return The time zone object associated with this calendar.
  812. * @stable ICU 2.0
  813. */
  814. const TimeZone& getTimeZone(void) const;
  815. /**
  816. * Returns the time zone owned by this calendar. The caller owns the returned object
  817. * and must delete it when done. After this call, the new time zone associated
  818. * with this Calendar is the default TimeZone as returned by TimeZone::createDefault().
  819. *
  820. * @return The time zone object which was associated with this calendar.
  821. * @stable ICU 2.0
  822. */
  823. TimeZone* orphanTimeZone(void);
  824. /**
  825. * Queries if the current date for this Calendar is in Daylight Savings Time.
  826. *
  827. * @param status Fill-in parameter which receives the status of this operation.
  828. * @return True if the current date for this Calendar is in Daylight Savings Time,
  829. * false, otherwise.
  830. * @stable ICU 2.0
  831. */
  832. virtual UBool inDaylightTime(UErrorCode& status) const = 0;
  833. /**
  834. * Specifies whether or not date/time interpretation is to be lenient. With lenient
  835. * interpretation, a date such as "February 942, 1996" will be treated as being
  836. * equivalent to the 941st day after February 1, 1996. With strict interpretation,
  837. * such dates will cause an error when computing time from the time field values
  838. * representing the dates.
  839. *
  840. * @param lenient True specifies date/time interpretation to be lenient.
  841. *
  842. * @see DateFormat#setLenient
  843. * @stable ICU 2.0
  844. */
  845. void setLenient(UBool lenient);
  846. /**
  847. * Tells whether date/time interpretation is to be lenient.
  848. *
  849. * @return True tells that date/time interpretation is to be lenient.
  850. * @stable ICU 2.0
  851. */
  852. UBool isLenient(void) const;
  853. /**
  854. * Sets the behavior for handling wall time repeating multiple times
  855. * at negative time zone offset transitions. For example, 1:30 AM on
  856. * November 6, 2011 in US Eastern time (Ameirca/New_York) occurs twice;
  857. * 1:30 AM EDT, then 1:30 AM EST one hour later. When <code>UCAL_WALLTIME_FIRST</code>
  858. * is used, the wall time 1:30AM in this example will be interpreted as 1:30 AM EDT
  859. * (first occurrence). When <code>UCAL_WALLTIME_LAST</code> is used, it will be
  860. * interpreted as 1:30 AM EST (last occurrence). The default value is
  861. * <code>UCAL_WALLTIME_LAST</code>.
  862. * <p>
  863. * <b>Note:</b>When <code>UCAL_WALLTIME_NEXT_VALID</code> is not a valid
  864. * option for this. When the argument is neither <code>UCAL_WALLTIME_FIRST</code>
  865. * nor <code>UCAL_WALLTIME_LAST</code>, this method has no effect and will keep
  866. * the current setting.
  867. *
  868. * @param option the behavior for handling repeating wall time, either
  869. * <code>UCAL_WALLTIME_FIRST</code> or <code>UCAL_WALLTIME_LAST</code>.
  870. * @see #getRepeatedWallTimeOption
  871. * @stable ICU 49
  872. */
  873. void setRepeatedWallTimeOption(UCalendarWallTimeOption option);
  874. /**
  875. * Gets the behavior for handling wall time repeating multiple times
  876. * at negative time zone offset transitions.
  877. *
  878. * @return the behavior for handling repeating wall time, either
  879. * <code>UCAL_WALLTIME_FIRST</code> or <code>UCAL_WALLTIME_LAST</code>.
  880. * @see #setRepeatedWallTimeOption
  881. * @stable ICU 49
  882. */
  883. UCalendarWallTimeOption getRepeatedWallTimeOption(void) const;
  884. /**
  885. * Sets the behavior for handling skipped wall time at positive time zone offset
  886. * transitions. For example, 2:30 AM on March 13, 2011 in US Eastern time (America/New_York)
  887. * does not exist because the wall time jump from 1:59 AM EST to 3:00 AM EDT. When
  888. * <code>UCAL_WALLTIME_FIRST</code> is used, 2:30 AM is interpreted as 30 minutes before 3:00 AM
  889. * EDT, therefore, it will be resolved as 1:30 AM EST. When <code>UCAL_WALLTIME_LAST</code>
  890. * is used, 2:30 AM is interpreted as 31 minutes after 1:59 AM EST, therefore, it will be
  891. * resolved as 3:30 AM EDT. When <code>UCAL_WALLTIME_NEXT_VALID</code> is used, 2:30 AM will
  892. * be resolved as next valid wall time, that is 3:00 AM EDT. The default value is
  893. * <code>UCAL_WALLTIME_LAST</code>.
  894. * <p>
  895. * <b>Note:</b>This option is effective only when this calendar is lenient.
  896. * When the calendar is strict, such non-existing wall time will cause an error.
  897. *
  898. * @param option the behavior for handling skipped wall time at positive time zone
  899. * offset transitions, one of <code>UCAL_WALLTIME_FIRST</code>, <code>UCAL_WALLTIME_LAST</code> and
  900. * <code>UCAL_WALLTIME_NEXT_VALID</code>.
  901. * @see #getSkippedWallTimeOption
  902. *
  903. * @stable ICU 49
  904. */
  905. void setSkippedWallTimeOption(UCalendarWallTimeOption option);
  906. /**
  907. * Gets the behavior for handling skipped wall time at positive time zone offset
  908. * transitions.
  909. *
  910. * @return the behavior for handling skipped wall time, one of
  911. * <code>UCAL_WALLTIME_FIRST</code>, <code>UCAL_WALLTIME_LAST</code>
  912. * and <code>UCAL_WALLTIME_NEXT_VALID</code>.
  913. * @see #setSkippedWallTimeOption
  914. * @stable ICU 49
  915. */
  916. UCalendarWallTimeOption getSkippedWallTimeOption(void) const;
  917. #ifndef U_HIDE_DEPRECATED_API
  918. /**
  919. * Sets what the first day of the week is; e.g., Sunday in US, Monday in France.
  920. *
  921. * @param value The given first day of the week.
  922. * @deprecated ICU 2.6. Use setFirstDayOfWeek(UCalendarDaysOfWeek value) instead.
  923. */
  924. void setFirstDayOfWeek(EDaysOfWeek value);
  925. #endif /* U_HIDE_DEPRECATED_API */
  926. /**
  927. * Sets what the first day of the week is; e.g., Sunday in US, Monday in France.
  928. *
  929. * @param value The given first day of the week.
  930. * @stable ICU 2.6.
  931. */
  932. void setFirstDayOfWeek(UCalendarDaysOfWeek value);
  933. #ifndef U_HIDE_DEPRECATED_API
  934. /**
  935. * Gets what the first day of the week is; e.g., Sunday in US, Monday in France.
  936. *
  937. * @return The first day of the week.
  938. * @deprecated ICU 2.6 use the overload with error code
  939. */
  940. EDaysOfWeek getFirstDayOfWeek(void) const;
  941. #endif /* U_HIDE_DEPRECATED_API */
  942. /**
  943. * Gets what the first day of the week is; e.g., Sunday in US, Monday in France.
  944. *
  945. * @param status error code
  946. * @return The first day of the week.
  947. * @stable ICU 2.6
  948. */
  949. UCalendarDaysOfWeek getFirstDayOfWeek(UErrorCode &status) const;
  950. /**
  951. * Sets what the minimal days required in the first week of the year are; For
  952. * example, if the first week is defined as one that contains the first day of the
  953. * first month of a year, call the method with value 1. If it must be a full week,
  954. * use value 7.
  955. *
  956. * @param value The given minimal days required in the first week of the year.
  957. * @stable ICU 2.0
  958. */
  959. void setMinimalDaysInFirstWeek(uint8_t value);
  960. /**
  961. * Gets what the minimal days required in the first week of the year are; e.g., if
  962. * the first week is defined as one that contains the first day of the first month
  963. * of a year, getMinimalDaysInFirstWeek returns 1. If the minimal days required must
  964. * be a full week, getMinimalDaysInFirstWeek returns 7.
  965. *
  966. * @return The minimal days required in the first week of the year.
  967. * @stable ICU 2.0
  968. */
  969. uint8_t getMinimalDaysInFirstWeek(void) const;
  970. /**
  971. * Gets the minimum value for the given time field. e.g., for Gregorian
  972. * DAY_OF_MONTH, 1.
  973. *
  974. * @param field The given time field.
  975. * @return The minimum value for the given time field.
  976. * @deprecated ICU 2.6. Use getMinimum(UCalendarDateFields field) instead.
  977. */
  978. virtual int32_t getMinimum(EDateFields field) const;
  979. /**
  980. * Gets the minimum value for the given time field. e.g., for Gregorian
  981. * DAY_OF_MONTH, 1.
  982. *
  983. * @param field The given time field.
  984. * @return The minimum value for the given time field.
  985. * @stable ICU 2.6.
  986. */
  987. virtual int32_t getMinimum(UCalendarDateFields field) const;
  988. /**
  989. * Gets the maximum value for the given time field. e.g. for Gregorian DAY_OF_MONTH,
  990. * 31.
  991. *
  992. * @param field The given time field.
  993. * @return The maximum value for the given time field.
  994. * @deprecated ICU 2.6. Use getMaximum(UCalendarDateFields field) instead.
  995. */
  996. virtual int32_t getMaximum(EDateFields field) const;
  997. /**
  998. * Gets the maximum value for the given time field. e.g. for Gregorian DAY_OF_MONTH,
  999. * 31.
  1000. *
  1001. * @param field The given time field.
  1002. * @return The maximum value for the given time field.
  1003. * @stable ICU 2.6.
  1004. */
  1005. virtual int32_t getMaximum(UCalendarDateFields field) const;
  1006. /**
  1007. * Gets the highest minimum value for the given field if varies. Otherwise same as
  1008. * getMinimum(). For Gregorian, no difference.
  1009. *
  1010. * @param field The given time field.
  1011. * @return The highest minimum value for the given time field.
  1012. * @deprecated ICU 2.6. Use getGreatestMinimum(UCalendarDateFields field) instead.
  1013. */
  1014. virtual int32_t getGreatestMinimum(EDateFields field) const;
  1015. /**
  1016. * Gets the highest minimum value for the given field if varies. Otherwise same as
  1017. * getMinimum(). For Gregorian, no difference.
  1018. *
  1019. * @param field The given time field.
  1020. * @return The highest minimum value for the given time field.
  1021. * @stable ICU 2.6.
  1022. */
  1023. virtual int32_t getGreatestMinimum(UCalendarDateFields field) const;
  1024. /**
  1025. * Gets the lowest maximum value for the given field if varies. Otherwise same as
  1026. * getMaximum(). e.g., for Gregorian DAY_OF_MONTH, 28.
  1027. *
  1028. * @param field The given time field.
  1029. * @return The lowest maximum value for the given time field.
  1030. * @deprecated ICU 2.6. Use getLeastMaximum(UCalendarDateFields field) instead.
  1031. */
  1032. virtual int32_t getLeastMaximum(EDateFields field) const;
  1033. /**
  1034. * Gets the lowest maximum value for the given field if varies. Otherwise same as
  1035. * getMaximum(). e.g., for Gregorian DAY_OF_MONTH, 28.
  1036. *
  1037. * @param field The given time field.
  1038. * @return The lowest maximum value for the given time field.
  1039. * @stable ICU 2.6.
  1040. */
  1041. virtual int32_t getLeastMaximum(UCalendarDateFields field) const;
  1042. #ifndef U_HIDE_DEPRECATED_API
  1043. /**
  1044. * Return the minimum value that this field could have, given the current date.
  1045. * For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum().
  1046. *
  1047. * The version of this function on Calendar uses an iterative algorithm to determine the
  1048. * actual minimum value for the field. There is almost always a more efficient way to
  1049. * accomplish this (in most cases, you can simply return getMinimum()). GregorianCalendar
  1050. * overrides this function with a more efficient implementation.
  1051. *
  1052. * @param field the field to determine the minimum of
  1053. * @param status Fill-in parameter which receives the status of this operation.
  1054. * @return the minimum of the given field for the current date of this Calendar
  1055. * @deprecated ICU 2.6. Use getActualMinimum(UCalendarDateFields field, UErrorCode& status) instead.
  1056. */
  1057. int32_t getActualMinimum(EDateFields field, UErrorCode& status) const;
  1058. #endif /* U_HIDE_DEPRECATED_API */
  1059. /**
  1060. * Return the minimum value that this field could have, given the current date.
  1061. * For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum().
  1062. *
  1063. * The version of this function on Calendar uses an iterative algorithm to determine the
  1064. * actual minimum value for the field. There is almost always a more efficient way to
  1065. * accomplish this (in most cases, you can simply return getMinimum()). GregorianCalendar
  1066. * overrides this function with a more efficient implementation.
  1067. *
  1068. * @param field the field to determine the minimum of
  1069. * @param status Fill-in parameter which receives the status of this operation.
  1070. * @return the minimum of the given field for the current date of this Calendar
  1071. * @stable ICU 2.6.
  1072. */
  1073. virtual int32_t getActualMinimum(UCalendarDateFields field, UErrorCode& status) const;
  1074. #ifndef U_HIDE_DEPRECATED_API
  1075. /**
  1076. * Return the maximum value that this field could have, given the current date.
  1077. * For example, with the date "Feb 3, 1997" and the DAY_OF_MONTH field, the actual
  1078. * maximum would be 28; for "Feb 3, 1996" it s 29. Similarly for a Hebrew calendar,
  1079. * for some years the actual maximum for MONTH is 12, and for others 13.
  1080. *
  1081. * The version of this function on Calendar uses an iterative algorithm to determine the
  1082. * actual maximum value for the field. There is almost always a more efficient way to
  1083. * accomplish this (in most cases, you can simply return getMaximum()). GregorianCalendar
  1084. * overrides this function with a more efficient implementation.
  1085. *
  1086. * @param field the field to determine the maximum of
  1087. * @param status Fill-in parameter which receives the status of this operation.
  1088. * @return the maximum of the given field for the current date of this Calendar
  1089. * @deprecated ICU 2.6. Use getActualMaximum(UCalendarDateFields field, UErrorCode& status) instead.
  1090. */
  1091. int32_t getActualMaximum(EDateFields field, UErrorCode& status) const;
  1092. #endif /* U_HIDE_DEPRECATED_API */
  1093. /**
  1094. * Return the maximum value that this field could have, given the current date.
  1095. * For example, with the date "Feb 3, 1997" and the DAY_OF_MONTH field, the actual
  1096. * maximum would be 28; for "Feb 3, 1996" it s 29. Similarly for a Hebrew calendar,
  1097. * for some years the actual maximum for MONTH is 12, and for others 13.
  1098. *
  1099. * The version of this function on Calendar uses an iterative algorithm to determine the
  1100. * actual maximum value for the field. There is almost always a more efficient way to
  1101. * accomplish this (in most cases, you can simply return getMaximum()). GregorianCalendar
  1102. * overrides this function with a more efficient implementation.
  1103. *
  1104. * @param field the field to determine the maximum of
  1105. * @param status Fill-in parameter which receives the status of this operation.
  1106. * @return the maximum of the given field for the current date of this Calendar
  1107. * @stable ICU 2.6.
  1108. */
  1109. virtual int32_t getActualMaximum(UCalendarDateFields field, UErrorCode& status) const;
  1110. #ifndef U_HIDE_DEPRECATED_API
  1111. /**
  1112. * Gets the value for a given time field. Recalculate the current time field values
  1113. * if the time value has been changed by a call to setTime(). Return zero for unset
  1114. * fields if any fields have been explicitly set by a call to set(). To force a
  1115. * recomputation of all fields regardless of the previous state, call complete().
  1116. * This method is semantically const, but may alter the object in memory.
  1117. *
  1118. * @param field The given time field.
  1119. * @param status Fill-in parameter which receives the status of the operation.
  1120. * @return The value for the given time field, or zero if the field is unset,
  1121. * and set() has been called for any other field.
  1122. * @deprecated ICU 2.6. Use get(UCalendarDateFields field, UErrorCode& status) instead.
  1123. */
  1124. int32_t get(EDateFields field, UErrorCode& status) const;
  1125. #endif /* U_HIDE_DEPRECATED_API */
  1126. /**
  1127. * Gets the value for a given time field. Recalculate the current time field values
  1128. * if the time value has been changed by a call to setTime(). Return zero for unset
  1129. * fields if any fields have been explicitly set by a call to set(). To force a
  1130. * recomputation of all fields regardless of the previous state, call complete().
  1131. * This method is semantically const, but may alter the object in memory.
  1132. *
  1133. * @param field The given time field.
  1134. * @param status Fill-in parameter which receives the status of the operation.
  1135. * @return The value for the given time field, or zero if the field is unset,
  1136. * and set() has been called for any other field.
  1137. * @stable ICU 2.6.
  1138. */
  1139. int32_t get(UCalendarDateFields field, UErrorCode& status) const;
  1140. #ifndef U_HIDE_DEPRECATED_API
  1141. /**
  1142. * Determines if the given time field has a value set. This can affect in the
  1143. * resolving of time in Calendar. Unset fields have a value of zero, by definition.
  1144. *
  1145. * @param field The given time field.
  1146. * @return True if the given time field has a value set; false otherwise.
  1147. * @deprecated ICU 2.6. Use isSet(UCalendarDateFields field) instead.
  1148. */
  1149. UBool isSet(EDateFields field) const;
  1150. #endif /* U_HIDE_DEPRECATED_API */
  1151. /**
  1152. * Determines if the given time field has a value set. This can affect in the
  1153. * resolving of time in Calendar. Unset fields have a value of zero, by definition.
  1154. *
  1155. * @param field The given time field.
  1156. * @return True if the given time field has a value set; false otherwise.
  1157. * @stable ICU 2.6.
  1158. */
  1159. UBool isSet(UCalendarDateFields field) const;
  1160. #ifndef U_HIDE_DEPRECATED_API
  1161. /**
  1162. * Sets the given time field with the given value.
  1163. *
  1164. * @param field The given time field.
  1165. * @param value The value to be set for the given time field.
  1166. * @deprecated ICU 2.6. Use set(UCalendarDateFields field, int32_t value) instead.
  1167. */
  1168. void set(EDateFields field, int32_t value);
  1169. #endif /* U_HIDE_DEPRECATED_API */
  1170. /**
  1171. * Sets the given time field with the given value.
  1172. *
  1173. * @param field The given time field.
  1174. * @param value The value to be set for the given time field.
  1175. * @stable ICU 2.6.
  1176. */
  1177. void set(UCalendarDateFields field, int32_t value);
  1178. /**
  1179. * Sets the values for the fields YEAR, MONTH, and DATE. Other field values are
  1180. * retained; call clear() first if this is not desired.
  1181. *
  1182. * @param year The value used to set the YEAR time field.
  1183. * @param month The value used to set the MONTH time field. Month value is 0-based.
  1184. * e.g., 0 for January.
  1185. * @param date The value used to set the DATE time field.
  1186. * @stable ICU 2.0
  1187. */
  1188. void set(int32_t year, int32_t month, int32_t date);
  1189. /**
  1190. * Sets the values for the fields YEAR, MONTH, DATE, HOUR_OF_DAY, and MINUTE. Other
  1191. * field values are retained; call clear() first if this is not desired.
  1192. *
  1193. * @param year The value used to set the YEAR time field.
  1194. * @param month The value used to set the MONTH time field. Month value is
  1195. * 0-based. E.g., 0 for January.
  1196. * @param date The value used to set the DATE time field.
  1197. * @param hour The value used to set the HOUR_OF_DAY time field.
  1198. * @param minute The value used to set the MINUTE time field.
  1199. * @stable ICU 2.0
  1200. */
  1201. void set(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute);
  1202. /**
  1203. * Sets the values for the fields YEAR, MONTH, DATE, HOUR_OF_DAY, MINUTE, and SECOND.
  1204. * Other field values are retained; call clear() first if this is not desired.
  1205. *
  1206. * @param year The value used to set the YEAR time field.
  1207. * @param month The value used to set the MONTH time field. Month value is
  1208. * 0-based. E.g., 0 for January.
  1209. * @param date The value used to set the DATE time field.
  1210. * @param hour The value used to set the HOUR_OF_DAY time field.
  1211. * @param minute The value used to set the MINUTE time field.
  1212. * @param second The value used to set the SECOND time field.
  1213. * @stable ICU 2.0
  1214. */
  1215. void set(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, int32_t second);
  1216. /**
  1217. * Clears the values of all the time fields, making them both unset and assigning
  1218. * them a value of zero. The field values will be determined during the next
  1219. * resolving of time into time fields.
  1220. * @stable ICU 2.0
  1221. */
  1222. void clear(void);
  1223. #ifndef U_HIDE_DEPRECATED_API
  1224. /**
  1225. * Clears the value in the given time field, both making it unset and assigning it a
  1226. * value of zero. This field value will be determined during the next resolving of
  1227. * time into time fields.
  1228. *
  1229. * @param field The time field to be cleared.
  1230. * @deprecated ICU 2.6. Use clear(UCalendarDateFields field) instead.
  1231. */
  1232. void clear(EDateFields field);
  1233. #endif /* U_HIDE_DEPRECATED_API */
  1234. /**
  1235. * Clears the value in the given time field, both making it unset and assigning it a
  1236. * value of zero. This field value will be determined during the next resolving of
  1237. * time into time fields.
  1238. *
  1239. * @param field The time field to be cleared.
  1240. * @stable ICU 2.6.
  1241. */
  1242. void clear(UCalendarDateFields field);
  1243. /**
  1244. * Returns a unique class ID POLYMORPHICALLY. Pure virtual method. This method is to
  1245. * implement a simple version of RTTI, since not all C++ compilers support genuine
  1246. * RTTI. Polymorphic operator==() and clone() methods call this method.
  1247. * <P>
  1248. * Concrete subclasses of Calendar must implement getDynamicClassID() and also a
  1249. * static method and data member:
  1250. *
  1251. * static UClassID getStaticClassID() { return (UClassID)&amp;fgClassID; }
  1252. * static char fgClassID;
  1253. *
  1254. * @return The class ID for this object. All objects of a given class have the
  1255. * same class ID. Objects of other classes have different class IDs.
  1256. * @stable ICU 2.0
  1257. */
  1258. virtual UClassID getDynamicClassID(void) const = 0;
  1259. /**
  1260. * Returns the calendar type name string for this Calendar object.
  1261. * The returned string is the legacy ICU calendar attribute value,
  1262. * for example, "gregorian" or "japanese".
  1263. *
  1264. * See type="old type name" for the calendar attribute of locale IDs
  1265. * at http://www.unicode.org/reports/tr35/#Key_Type_Definitions
  1266. *
  1267. * Sample code for getting the LDML/BCP 47 calendar key value:
  1268. * \code
  1269. * const char *calType = cal->getType();
  1270. * if (0 == strcmp(calType, "unknown")) {
  1271. * // deal with unknown calendar type
  1272. * } else {
  1273. * string localeID("root@calendar=");
  1274. * localeID.append(calType);
  1275. * char langTag[100];
  1276. * UErrorCode errorCode = U_ZERO_ERROR;
  1277. * int32_t length = uloc_toLanguageTag(localeID.c_str(), langTag, (int32_t)sizeof(langTag), TRUE, &errorCode);
  1278. * if (U_FAILURE(errorCode)) {
  1279. * // deal with errors & overflow
  1280. * }
  1281. * string lang(langTag, length);
  1282. * size_t caPos = lang.find("-ca-");
  1283. * lang.erase(0, caPos + 4);
  1284. * // lang now contains the LDML calendar type
  1285. * }
  1286. * \endcode
  1287. *
  1288. * @return legacy calendar type name string
  1289. * @stable ICU 49
  1290. */
  1291. virtual const char * getType() const = 0;
  1292. /**
  1293. * Returns whether the given day of the week is a weekday, a weekend day,
  1294. * or a day that transitions from one to the other, for the locale and
  1295. * calendar system associated with this Calendar (the locale's region is
  1296. * often the most determinant factor). If a transition occurs at midnight,
  1297. * then the days before and after the transition will have the
  1298. * type UCAL_WEEKDAY or UCAL_WEEKEND. If a transition occurs at a time
  1299. * other than midnight, then the day of the transition will have
  1300. * the type UCAL_WEEKEND_ONSET or UCAL_WEEKEND_CEASE. In this case, the
  1301. * method getWeekendTransition() will return the point of
  1302. * transition.
  1303. * @param dayOfWeek The day of the week whose type is desired (UCAL_SUNDAY..UCAL_SATURDAY).
  1304. * @param status The error code for the operation.
  1305. * @return The UCalendarWeekdayType for the day of the week.
  1306. * @stable ICU 4.4
  1307. */
  1308. virtual UCalendarWeekdayType getDayOfWeekType(UCalendarDaysOfWeek dayOfWeek, UErrorCode &status) const;
  1309. /**
  1310. * Returns the time during the day at which the weekend begins or ends in
  1311. * this calendar system. If getDayOfWeekType() returns UCAL_WEEKEND_ONSET
  1312. * for the specified dayOfWeek, return the time at which the weekend begins.
  1313. * If getDayOfWeekType() returns UCAL_WEEKEND_CEASE for the specified dayOfWeek,
  1314. * return the time at which the weekend ends. If getDayOfWeekType() returns
  1315. * some other UCalendarWeekdayType for the specified dayOfWeek, is it an error condition
  1316. * (U_ILLEGAL_ARGUMENT_ERROR).
  1317. * @param dayOfWeek The day of the week for which the weekend transition time is
  1318. * desired (UCAL_SUNDAY..UCAL_SATURDAY).
  1319. * @param status The error code for the operation.
  1320. * @return The milliseconds after midnight at which the weekend begins or ends.
  1321. * @stable ICU 4.4
  1322. */
  1323. virtual int32_t getWeekendTransition(UCalendarDaysOfWeek dayOfWeek, UErrorCode &status) const;
  1324. /**
  1325. * Returns TRUE if the given UDate is in the weekend in
  1326. * this calendar system.
  1327. * @param date The UDate in question.
  1328. * @param status The error code for the operation.
  1329. * @return TRUE if the given UDate is in the weekend in
  1330. * this calendar system, FALSE otherwise.
  1331. * @stable ICU 4.4
  1332. */
  1333. virtual UBool isWeekend(UDate date, UErrorCode &status) const;
  1334. /**
  1335. * Returns TRUE if this Calendar's current date-time is in the weekend in
  1336. * this calendar system.
  1337. * @return TRUE if this Calendar's current date-time is in the weekend in
  1338. * this calendar system, FALSE otherwise.
  1339. * @stable ICU 4.4
  1340. */
  1341. virtual UBool isWeekend(void) const;
  1342. protected:
  1343. /**
  1344. * Constructs a Calendar with the default time zone as returned by
  1345. * TimeZone::createInstance(), and the default locale.
  1346. *
  1347. * @param success Indicates the status of Calendar object construction. Returns
  1348. * U_ZERO_ERROR if constructed successfully.
  1349. * @stable ICU 2.0
  1350. */
  1351. Calendar(UErrorCode& success);
  1352. /**
  1353. * Copy constructor
  1354. *
  1355. * @param source Calendar object to be copied from
  1356. * @stable ICU 2.0
  1357. */
  1358. Calendar(const Calendar& source);
  1359. /**
  1360. * Default assignment operator
  1361. *
  1362. * @param right Calendar object to be copied
  1363. * @stable ICU 2.0
  1364. */
  1365. Calendar& operator=(const Calendar& right);
  1366. /**
  1367. * Constructs a Calendar with the given time zone and locale. Clients are no longer
  1368. * responsible for deleting the given time zone object after it's adopted.
  1369. *
  1370. * @param zone The given time zone.
  1371. * @param aLocale The given locale.
  1372. * @param success Indicates the status of Calendar object construction. Returns
  1373. * U_ZERO_ERROR if constructed successfully.
  1374. * @stable ICU 2.0
  1375. */
  1376. Calendar(TimeZone* zone, const Locale& aLocale, UErrorCode& success);
  1377. /**
  1378. * Constructs a Calendar with the given time zone and locale.
  1379. *
  1380. * @param zone The given time zone.
  1381. * @param aLocale The given locale.
  1382. * @param success Indicates the status of Calendar object construction. Returns
  1383. * U_ZERO_ERROR if constructed successfully.
  1384. * @stable ICU 2.0
  1385. */
  1386. Calendar(const TimeZone& zone, const Locale& aLocale, UErrorCode& success);
  1387. /**
  1388. * Converts Calendar's time field values to GMT as milliseconds.
  1389. *
  1390. * @param status Output param set to success/failure code on exit. If any value
  1391. * previously set in the time field is invalid or restricted by
  1392. * leniency, this will be set to an error status.
  1393. * @stable ICU 2.0
  1394. */
  1395. virtual void computeTime(UErrorCode& status);
  1396. /**
  1397. * Converts GMT as milliseconds to time field values. This allows you to sync up the
  1398. * time field values with a new time that is set for the calendar. This method
  1399. * does NOT recompute the time first; to recompute the time, then the fields, use
  1400. * the method complete().
  1401. *
  1402. * @param status Output param set to success/failure code on exit. If any value
  1403. * previously set in the time field is invalid or restricted by
  1404. * leniency, this will be set to an error status.
  1405. * @stable ICU 2.0
  1406. */
  1407. virtual void computeFields(UErrorCode& status);
  1408. /**
  1409. * Gets this Calendar's current time as a long.
  1410. *
  1411. * @param status Output param set to success/failure code on exit. If any value
  1412. * previously set in the time field is invalid or restricted by
  1413. * leniency, this will be set to an error status.
  1414. * @return the current time as UTC milliseconds from the epoch.
  1415. * @stable ICU 2.0
  1416. */
  1417. double getTimeInMillis(UErrorCode& status) const;
  1418. /**
  1419. * Sets this Calendar's current time from the given long value.
  1420. * @param millis the new time in UTC milliseconds from the epoch.
  1421. * @param status Output param set to success/failure code on exit. If any value
  1422. * previously set in the time field is invalid or restricted by
  1423. * leniency, this will be set to an error status.
  1424. * @stable ICU 2.0
  1425. */
  1426. void setTimeInMillis( double millis, UErrorCode& status );
  1427. /**
  1428. * Recomputes the current time from currently set fields, and then fills in any
  1429. * unset fields in the time field list.
  1430. *
  1431. * @param status Output param set to success/failure code on exit. If any value
  1432. * previously set in the time field is invalid or restricted by
  1433. * leniency, this will be set to an error status.
  1434. * @stable ICU 2.0
  1435. */
  1436. void complete(UErrorCode& status);
  1437. #ifndef U_HIDE_DEPRECATED_API
  1438. /**
  1439. * Gets the value for a given time field. Subclasses can use this function to get
  1440. * field values without forcing recomputation of time.
  1441. *
  1442. * @param field The given time field.
  1443. * @return The value for the given time field.
  1444. * @deprecated ICU 2.6. Use internalGet(UCalendarDateFields field) instead.
  1445. */
  1446. inline int32_t internalGet(EDateFields field) const {return fFields[field];}
  1447. #endif /* U_HIDE_DEPRECATED_API */
  1448. #ifndef U_HIDE_INTERNAL_API
  1449. /**
  1450. * Gets the value for a given time field. Subclasses can use this function to get
  1451. * field values without forcing recomputation of time. If the field's stamp is UNSET,
  1452. * the defaultValue is used.
  1453. *
  1454. * @param field The given time field.
  1455. * @param defaultValue a default value used if the field is unset.
  1456. * @return The value for the given time field.
  1457. * @internal
  1458. */
  1459. inline int32_t internalGet(UCalendarDateFields field, int32_t defaultValue) const {return fStamp[field]>kUnset ? fFields[field] : defaultValue;}
  1460. /**
  1461. * Gets the value for a given time field. Subclasses can use this function to get
  1462. * field values without forcing recomputation of time.
  1463. *
  1464. * @param field The given time field.
  1465. * @return The value for the given time field.
  1466. * @internal
  1467. */
  1468. inline int32_t internalGet(UCalendarDateFields field) const {return fFields[field];}
  1469. #endif /* U_HIDE_INTERNAL_API */
  1470. #ifndef U_HIDE_DEPRECATED_API
  1471. /**
  1472. * Sets the value for a given time field. This is a fast internal method for
  1473. * subclasses. It does not affect the areFieldsInSync, isTimeSet, or areAllFieldsSet
  1474. * flags.
  1475. *
  1476. * @param field The given time field.
  1477. * @param value The value for the given time field.
  1478. * @deprecated ICU 2.6. Use internalSet(UCalendarDateFields field, int32_t value) instead.
  1479. */
  1480. void internalSet(EDateFields field, int32_t value);
  1481. #endif /* U_HIDE_DEPRECATED_API */
  1482. /**
  1483. * Sets the value for a given time field. This is a fast internal method for
  1484. * subclasses. It does not affect the areFieldsInSync, isTimeSet, or areAllFieldsSet
  1485. * flags.
  1486. *
  1487. * @param field The given time field.
  1488. * @param value The value for the given time field.
  1489. * @stable ICU 2.6.
  1490. */
  1491. inline void internalSet(UCalendarDateFields field, int32_t value);
  1492. /**
  1493. * Prepare this calendar for computing the actual minimum or maximum.
  1494. * This method modifies this calendar's fields; it is called on a
  1495. * temporary calendar.
  1496. * @internal
  1497. */
  1498. virtual void prepareGetActual(UCalendarDateFields field, UBool isMinimum, UErrorCode &status);
  1499. /**
  1500. * Limit enums. Not in sync with UCalendarLimitType (refers to internal fields).
  1501. * @internal
  1502. */
  1503. enum ELimitType {
  1504. #ifndef U_HIDE_INTERNAL_API
  1505. UCAL_LIMIT_MINIMUM = 0,
  1506. UCAL_LIMIT_GREATEST_MINIMUM,
  1507. UCAL_LIMIT_LEAST_MAXIMUM,
  1508. UCAL_LIMIT_MAXIMUM,
  1509. UCAL_LIMIT_COUNT
  1510. #endif /* U_HIDE_INTERNAL_API */
  1511. };
  1512. /**
  1513. * Subclass API for defining limits of different types.
  1514. * Subclasses must implement this method to return limits for the
  1515. * following fields:
  1516. *
  1517. * <pre>UCAL_ERA
  1518. * UCAL_YEAR
  1519. * UCAL_MONTH
  1520. * UCAL_WEEK_OF_YEAR
  1521. * UCAL_WEEK_OF_MONTH
  1522. * UCAL_DATE (DAY_OF_MONTH on Java)
  1523. * UCAL_DAY_OF_YEAR
  1524. * UCAL_DAY_OF_WEEK_IN_MONTH
  1525. * UCAL_YEAR_WOY
  1526. * UCAL_EXTENDED_YEAR</pre>
  1527. *
  1528. * @param field one of the above field numbers
  1529. * @param limitType one of <code>MINIMUM</code>, <code>GREATEST_MINIMUM</code>,
  1530. * <code>LEAST_MAXIMUM</code>, or <code>MAXIMUM</code>
  1531. * @internal
  1532. */
  1533. virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const = 0;
  1534. /**
  1535. * Return a limit for a field.
  1536. * @param field the field, from <code>0..UCAL_MAX_FIELD</code>
  1537. * @param limitType the type specifier for the limit
  1538. * @see #ELimitType
  1539. * @internal
  1540. */
  1541. virtual int32_t getLimit(UCalendarDateFields field, ELimitType limitType) const;
  1542. /**
  1543. * Return the Julian day number of day before the first day of the
  1544. * given month in the given extended year. Subclasses should override
  1545. * this method to implement their calendar system.
  1546. * @param eyear the extended year
  1547. * @param month the zero-based month, or 0 if useMonth is false
  1548. * @param useMonth if false, compute the day before the first day of
  1549. * the given year, otherwise, compute the day before the first day of
  1550. * the given month
  1551. * @return the Julian day number of the day before the first
  1552. * day of the given month and year
  1553. * @internal
  1554. */
  1555. virtual int32_t handleComputeMonthStart(int32_t eyear, int32_t month,
  1556. UBool useMonth) const = 0;
  1557. /**
  1558. * Return the number of days in the given month of the given extended
  1559. * year of this calendar system. Subclasses should override this
  1560. * method if they can provide a more correct or more efficient
  1561. * implementation than the default implementation in Calendar.
  1562. * @internal
  1563. */
  1564. virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month) const ;
  1565. /**
  1566. * Return the number of days in the given extended year of this
  1567. * calendar system. Subclasses should override this method if they can
  1568. * provide a more correct or more efficient implementation than the
  1569. * default implementation in Calendar.
  1570. * @stable ICU 2.0
  1571. */
  1572. virtual int32_t handleGetYearLength(int32_t eyear) const;
  1573. /**
  1574. * Return the extended year defined by the current fields. This will
  1575. * use the UCAL_EXTENDED_YEAR field or the UCAL_YEAR and supra-year fields (such
  1576. * as UCAL_ERA) specific to the calendar system, depending on which set of
  1577. * fields is newer.
  1578. * @return the extended year
  1579. * @internal
  1580. */
  1581. virtual int32_t handleGetExtendedYear() = 0;
  1582. /**
  1583. * Subclasses may override this. This method calls
  1584. * handleGetMonthLength() to obtain the calendar-specific month
  1585. * length.
  1586. * @param bestField which field to use to calculate the date
  1587. * @return julian day specified by calendar fields.
  1588. * @internal
  1589. */
  1590. virtual int32_t handleComputeJulianDay(UCalendarDateFields bestField);
  1591. /**
  1592. * Subclasses must override this to convert from week fields
  1593. * (YEAR_WOY and WEEK_OF_YEAR) to an extended year in the case
  1594. * where YEAR, EXTENDED_YEAR are not set.
  1595. * The Calendar implementation assumes yearWoy is in extended gregorian form
  1596. * @return the extended year, UCAL_EXTENDED_YEAR
  1597. * @internal
  1598. */
  1599. virtual int32_t handleGetExtendedYearFromWeekFields(int32_t yearWoy, int32_t woy);
  1600. /**
  1601. * Validate a single field of this calendar. Subclasses should
  1602. * override this method to validate any calendar-specific fields.
  1603. * Generic fields can be handled by
  1604. * <code>Calendar::validateField()</code>.
  1605. * @see #validateField(int, int, int, int&)
  1606. * @internal
  1607. */
  1608. virtual void validateField(UCalendarDateFields field, UErrorCode &status);
  1609. #ifndef U_HIDE_INTERNAL_API
  1610. /**
  1611. * Compute the Julian day from fields. Will determine whether to use
  1612. * the JULIAN_DAY field directly, or other fields.
  1613. * @return the julian day
  1614. * @internal
  1615. */
  1616. int32_t computeJulianDay();
  1617. /**
  1618. * Compute the milliseconds in the day from the fields. This is a
  1619. * value from 0 to 23:59:59.999 inclusive, unless fields are out of
  1620. * range, in which case it can be an arbitrary value. This value
  1621. * reflects local zone wall time.
  1622. * @internal
  1623. */
  1624. int32_t computeMillisInDay();
  1625. /**
  1626. * This method can assume EXTENDED_YEAR has been set.
  1627. * @param millis milliseconds of the date fields
  1628. * @param millisInDay milliseconds of the time fields; may be out
  1629. * or range.
  1630. * @param ec Output param set to failure code on function return
  1631. * when this function fails.
  1632. * @internal
  1633. */
  1634. int32_t computeZoneOffset(double millis, int32_t millisInDay, UErrorCode &ec);
  1635. /**
  1636. * Determine the best stamp in a range.
  1637. * @param start first enum to look at
  1638. * @param end last enum to look at
  1639. * @param bestSoFar stamp prior to function call
  1640. * @return the stamp value of the best stamp
  1641. * @internal
  1642. */
  1643. int32_t newestStamp(UCalendarDateFields start, UCalendarDateFields end, int32_t bestSoFar) const;
  1644. /**
  1645. * Values for field resolution tables
  1646. * @see #resolveFields
  1647. * @internal
  1648. */
  1649. enum {
  1650. /** Marker for end of resolve set (row or group). */
  1651. kResolveSTOP = -1,
  1652. /** Value to be bitwised "ORed" against resolve table field values for remapping. Example: (UCAL_DATE | kResolveRemap) in 1st column will cause 'UCAL_DATE' to be returned, but will not examine the value of UCAL_DATE. */
  1653. kResolveRemap = 32
  1654. };
  1655. /**
  1656. * Precedence table for Dates
  1657. * @see #resolveFields
  1658. * @internal
  1659. */
  1660. static const UFieldResolutionTable kDatePrecedence[];
  1661. /**
  1662. * Precedence table for Year
  1663. * @see #resolveFields
  1664. * @internal
  1665. */
  1666. static const UFieldResolutionTable kYearPrecedence[];
  1667. /**
  1668. * Precedence table for Day of Week
  1669. * @see #resolveFields
  1670. * @internal
  1671. */
  1672. static const UFieldResolutionTable kDOWPrecedence[];
  1673. /**
  1674. * Given a precedence table, return the newest field combination in
  1675. * the table, or UCAL_FIELD_COUNT if none is found.
  1676. *
  1677. * <p>The precedence table is a 3-dimensional array of integers. It
  1678. * may be thought of as an array of groups. Each group is an array of
  1679. * lines. Each line is an array of field numbers. Within a line, if
  1680. * all fields are set, then the time stamp of the line is taken to be
  1681. * the stamp of the most recently set field. If any field of a line is
  1682. * unset, then the line fails to match. Within a group, the line with
  1683. * the newest time stamp is selected. The first field of the line is
  1684. * returned to indicate which line matched.
  1685. *
  1686. * <p>In some cases, it may be desirable to map a line to field that
  1687. * whose stamp is NOT examined. For example, if the best field is
  1688. * DAY_OF_WEEK then the DAY_OF_WEEK_IN_MONTH algorithm may be used. In
  1689. * order to do this, insert the value <code>kResolveRemap | F</code> at
  1690. * the start of the line, where <code>F</code> is the desired return
  1691. * field value. This field will NOT be examined; it only determines
  1692. * the return value if the other fields in the line are the newest.
  1693. *
  1694. * <p>If all lines of a group contain at least one unset field, then no
  1695. * line will match, and the group as a whole will fail to match. In
  1696. * that case, the next group will be processed. If all groups fail to
  1697. * match, then UCAL_FIELD_COUNT is returned.
  1698. * @internal
  1699. */
  1700. UCalendarDateFields resolveFields(const UFieldResolutionTable *precedenceTable);
  1701. #endif /* U_HIDE_INTERNAL_API */
  1702. /**
  1703. * @internal
  1704. */
  1705. virtual const UFieldResolutionTable* getFieldResolutionTable() const;
  1706. #ifndef U_HIDE_INTERNAL_API
  1707. /**
  1708. * Return the field that is newer, either defaultField, or
  1709. * alternateField. If neither is newer or neither is set, return defaultField.
  1710. * @internal
  1711. */
  1712. UCalendarDateFields newerField(UCalendarDateFields defaultField, UCalendarDateFields alternateField) const;
  1713. #endif /* U_HIDE_INTERNAL_API */
  1714. private:
  1715. /**
  1716. * Helper function for calculating limits by trial and error
  1717. * @param field The field being investigated
  1718. * @param startValue starting (least max) value of field
  1719. * @param endValue ending (greatest max) value of field
  1720. * @param status return type
  1721. * @internal
  1722. */
  1723. int32_t getActualHelper(UCalendarDateFields field, int32_t startValue, int32_t endValue, UErrorCode &status) const;
  1724. protected:
  1725. /**
  1726. * The flag which indicates if the current time is set in the calendar.
  1727. * @stable ICU 2.0
  1728. */
  1729. UBool fIsTimeSet;
  1730. /**
  1731. * True if the fields are in sync with the currently set time of this Calendar.
  1732. * If false, then the next attempt to get the value of a field will
  1733. * force a recomputation of all fields from the current value of the time
  1734. * field.
  1735. * <P>
  1736. * This should really be named areFieldsInSync, but the old name is retained
  1737. * for backward compatibility.
  1738. * @stable ICU 2.0
  1739. */
  1740. UBool fAreFieldsSet;
  1741. /**
  1742. * True if all of the fields have been set. This is initially false, and set to
  1743. * true by computeFields().
  1744. * @stable ICU 2.0
  1745. */
  1746. UBool fAreAllFieldsSet;
  1747. /**
  1748. * True if all fields have been virtually set, but have not yet been
  1749. * computed. This occurs only in setTimeInMillis(). A calendar set
  1750. * to this state will compute all fields from the time if it becomes
  1751. * necessary, but otherwise will delay such computation.
  1752. * @stable ICU 3.0
  1753. */
  1754. UBool fAreFieldsVirtuallySet;
  1755. /**
  1756. * Get the current time without recomputing.
  1757. *
  1758. * @return the current time without recomputing.
  1759. * @stable ICU 2.0
  1760. */
  1761. UDate internalGetTime(void) const { return fTime; }
  1762. /**
  1763. * Set the current time without affecting flags or fields.
  1764. *
  1765. * @param time The time to be set
  1766. * @return the current time without recomputing.
  1767. * @stable ICU 2.0
  1768. */
  1769. void internalSetTime(UDate time) { fTime = time; }
  1770. /**
  1771. * The time fields containing values into which the millis is computed.
  1772. * @stable ICU 2.0
  1773. */
  1774. int32_t fFields[UCAL_FIELD_COUNT];
  1775. /**
  1776. * The flags which tell if a specified time field for the calendar is set.
  1777. * @deprecated ICU 2.8 use (fStamp[n]!=kUnset)
  1778. */
  1779. UBool fIsSet[UCAL_FIELD_COUNT];
  1780. /** Special values of stamp[]
  1781. * @stable ICU 2.0
  1782. */
  1783. enum {
  1784. kUnset = 0,
  1785. kInternallySet,
  1786. kMinimumUserStamp
  1787. };
  1788. /**
  1789. * Pseudo-time-stamps which specify when each field was set. There
  1790. * are two special values, UNSET and INTERNALLY_SET. Values from
  1791. * MINIMUM_USER_SET to Integer.MAX_VALUE are legal user set values.
  1792. * @stable ICU 2.0
  1793. */
  1794. int32_t fStamp[UCAL_FIELD_COUNT];
  1795. /**
  1796. * Subclasses may override this method to compute several fields
  1797. * specific to each calendar system. These are:
  1798. *
  1799. * <ul><li>ERA
  1800. * <li>YEAR
  1801. * <li>MONTH
  1802. * <li>DAY_OF_MONTH
  1803. * <li>DAY_OF_YEAR
  1804. * <li>EXTENDED_YEAR</ul>
  1805. *
  1806. * Subclasses can refer to the DAY_OF_WEEK and DOW_LOCAL fields, which
  1807. * will be set when this method is called. Subclasses can also call
  1808. * the getGregorianXxx() methods to obtain Gregorian calendar
  1809. * equivalents for the given Julian day.
  1810. *
  1811. * <p>In addition, subclasses should compute any subclass-specific
  1812. * fields, that is, fields from BASE_FIELD_COUNT to
  1813. * getFieldCount() - 1.
  1814. *
  1815. * <p>The default implementation in <code>Calendar</code> implements
  1816. * a pure proleptic Gregorian calendar.
  1817. * @internal
  1818. */
  1819. virtual void handleComputeFields(int32_t julianDay, UErrorCode &status);
  1820. #ifndef U_HIDE_INTERNAL_API
  1821. /**
  1822. * Return the extended year on the Gregorian calendar as computed by
  1823. * <code>computeGregorianFields()</code>.
  1824. * @internal
  1825. */
  1826. int32_t getGregorianYear() const {
  1827. return fGregorianYear;
  1828. }
  1829. /**
  1830. * Return the month (0-based) on the Gregorian calendar as computed by
  1831. * <code>computeGregorianFields()</code>.
  1832. * @internal
  1833. */
  1834. int32_t getGregorianMonth() const {
  1835. return fGregorianMonth;
  1836. }
  1837. /**
  1838. * Return the day of year (1-based) on the Gregorian calendar as
  1839. * computed by <code>computeGregorianFields()</code>.
  1840. * @internal
  1841. */
  1842. int32_t getGregorianDayOfYear() const {
  1843. return fGregorianDayOfYear;
  1844. }
  1845. /**
  1846. * Return the day of month (1-based) on the Gregorian calendar as
  1847. * computed by <code>computeGregorianFields()</code>.
  1848. * @internal
  1849. */
  1850. int32_t getGregorianDayOfMonth() const {
  1851. return fGregorianDayOfMonth;
  1852. }
  1853. #endif /* U_HIDE_INTERNAL_API */
  1854. /**
  1855. * Called by computeJulianDay. Returns the default month (0-based) for the year,
  1856. * taking year and era into account. Defaults to 0 for Gregorian, which doesn't care.
  1857. * @param eyear The extended year
  1858. * @internal
  1859. */
  1860. virtual int32_t getDefaultMonthInYear(int32_t eyear) ;
  1861. /**
  1862. * Called by computeJulianDay. Returns the default day (1-based) for the month,
  1863. * taking currently-set year and era into account. Defaults to 1 for Gregorian.
  1864. * @param eyear the extended year
  1865. * @param month the month in the year
  1866. * @internal
  1867. */
  1868. virtual int32_t getDefaultDayInMonth(int32_t eyear, int32_t month);
  1869. //-------------------------------------------------------------------------
  1870. // Protected utility methods for use by subclasses. These are very handy
  1871. // for implementing add, roll, and computeFields.
  1872. //-------------------------------------------------------------------------
  1873. /**
  1874. * Adjust the specified field so that it is within
  1875. * the allowable range for the date to which this calendar is set.
  1876. * For example, in a Gregorian calendar pinning the {@link #UCalendarDateFields DAY_OF_MONTH}
  1877. * field for a calendar set to April 31 would cause it to be set
  1878. * to April 30.
  1879. * <p>
  1880. * <b>Subclassing:</b>
  1881. * <br>
  1882. * This utility method is intended for use by subclasses that need to implement
  1883. * their own overrides of {@link #roll roll} and {@link #add add}.
  1884. * <p>
  1885. * <b>Note:</b>
  1886. * <code>pinField</code> is implemented in terms of
  1887. * {@link #getActualMinimum getActualMinimum}
  1888. * and {@link #getActualMaximum getActualMaximum}. If either of those methods uses
  1889. * a slow, iterative algorithm for a particular field, it would be
  1890. * unwise to attempt to call <code>pinField</code> for that field. If you
  1891. * really do need to do so, you should override this method to do
  1892. * something more efficient for that field.
  1893. * <p>
  1894. * @param field The calendar field whose value should be pinned.
  1895. * @param status Output param set to failure code on function return
  1896. * when this function fails.
  1897. *
  1898. * @see #getActualMinimum
  1899. * @see #getActualMaximum
  1900. * @stable ICU 2.0
  1901. */
  1902. virtual void pinField(UCalendarDateFields field, UErrorCode& status);
  1903. /**
  1904. * Return the week number of a day, within a period. This may be the week number in
  1905. * a year or the week number in a month. Usually this will be a value >= 1, but if
  1906. * some initial days of the period are excluded from week 1, because
  1907. * {@link #getMinimalDaysInFirstWeek getMinimalDaysInFirstWeek} is > 1, then
  1908. * the week number will be zero for those
  1909. * initial days. This method requires the day number and day of week for some
  1910. * known date in the period in order to determine the day of week
  1911. * on the desired day.
  1912. * <p>
  1913. * <b>Subclassing:</b>
  1914. * <br>
  1915. * This method is intended for use by subclasses in implementing their
  1916. * {@link #computeTime computeTime} and/or {@link #computeFields computeFields} methods.
  1917. * It is often useful in {@link #getActualMinimum getActualMinimum} and
  1918. * {@link #getActualMaximum getActualMaximum} as well.
  1919. * <p>
  1920. * This variant is handy for computing the week number of some other
  1921. * day of a period (often the first or last day of the period) when its day
  1922. * of the week is not known but the day number and day of week for some other
  1923. * day in the period (e.g. the current date) <em>is</em> known.
  1924. * <p>
  1925. * @param desiredDay The {@link #UCalendarDateFields DAY_OF_YEAR} or
  1926. * {@link #UCalendarDateFields DAY_OF_MONTH} whose week number is desired.
  1927. * Should be 1 for the first day of the period.
  1928. *
  1929. * @param dayOfPeriod The {@link #UCalendarDateFields DAY_OF_YEAR}
  1930. * or {@link #UCalendarDateFields DAY_OF_MONTH} for a day in the period whose
  1931. * {@link #UCalendarDateFields DAY_OF_WEEK} is specified by the
  1932. * <code>knownDayOfWeek</code> parameter.
  1933. * Should be 1 for first day of period.
  1934. *
  1935. * @param dayOfWeek The {@link #UCalendarDateFields DAY_OF_WEEK} for the day
  1936. * corresponding to the <code>knownDayOfPeriod</code> parameter.
  1937. * 1-based with 1=Sunday.
  1938. *
  1939. * @return The week number (one-based), or zero if the day falls before
  1940. * the first week because
  1941. * {@link #getMinimalDaysInFirstWeek getMinimalDaysInFirstWeek}
  1942. * is more than one.
  1943. *
  1944. * @stable ICU 2.8
  1945. */
  1946. int32_t weekNumber(int32_t desiredDay, int32_t dayOfPeriod, int32_t dayOfWeek);
  1947. #ifndef U_HIDE_INTERNAL_API
  1948. /**
  1949. * Return the week number of a day, within a period. This may be the week number in
  1950. * a year, or the week number in a month. Usually this will be a value >= 1, but if
  1951. * some initial days of the period are excluded from week 1, because
  1952. * {@link #getMinimalDaysInFirstWeek getMinimalDaysInFirstWeek} is > 1,
  1953. * then the week number will be zero for those
  1954. * initial days. This method requires the day of week for the given date in order to
  1955. * determine the result.
  1956. * <p>
  1957. * <b>Subclassing:</b>
  1958. * <br>
  1959. * This method is intended for use by subclasses in implementing their
  1960. * {@link #computeTime computeTime} and/or {@link #computeFields computeFields} methods.
  1961. * It is often useful in {@link #getActualMinimum getActualMinimum} and
  1962. * {@link #getActualMaximum getActualMaximum} as well.
  1963. * <p>
  1964. * @param dayOfPeriod The {@link #UCalendarDateFields DAY_OF_YEAR} or
  1965. * {@link #UCalendarDateFields DAY_OF_MONTH} whose week number is desired.
  1966. * Should be 1 for the first day of the period.
  1967. *
  1968. * @param dayOfWeek The {@link #UCalendarDateFields DAY_OF_WEEK} for the day
  1969. * corresponding to the <code>dayOfPeriod</code> parameter.
  1970. * 1-based with 1=Sunday.
  1971. *
  1972. * @return The week number (one-based), or zero if the day falls before
  1973. * the first week because
  1974. * {@link #getMinimalDaysInFirstWeek getMinimalDaysInFirstWeek}
  1975. * is more than one.
  1976. * @internal
  1977. */
  1978. inline int32_t weekNumber(int32_t dayOfPeriod, int32_t dayOfWeek);
  1979. /**
  1980. * returns the local DOW, valid range 0..6
  1981. * @internal
  1982. */
  1983. int32_t getLocalDOW();
  1984. #endif /* U_HIDE_INTERNAL_API */
  1985. private:
  1986. /**
  1987. * The next available value for fStamp[]
  1988. */
  1989. int32_t fNextStamp;// = MINIMUM_USER_STAMP;
  1990. /**
  1991. * Recalculates the time stamp array (fStamp).
  1992. * Resets fNextStamp to lowest next stamp value.
  1993. */
  1994. void recalculateStamp();
  1995. /**
  1996. * The current time set for the calendar.
  1997. */
  1998. UDate fTime;
  1999. /**
  2000. * @see #setLenient
  2001. */
  2002. UBool fLenient;
  2003. /**
  2004. * Time zone affects the time calculation done by Calendar. Calendar subclasses use
  2005. * the time zone data to produce the local time. Always set; never NULL.
  2006. */
  2007. TimeZone* fZone;
  2008. /**
  2009. * Option for rpeated wall time
  2010. * @see #setRepeatedWallTimeOption
  2011. */
  2012. UCalendarWallTimeOption fRepeatedWallTime;
  2013. /**
  2014. * Option for skipped wall time
  2015. * @see #setSkippedWallTimeOption
  2016. */
  2017. UCalendarWallTimeOption fSkippedWallTime;
  2018. /**
  2019. * Both firstDayOfWeek and minimalDaysInFirstWeek are locale-dependent. They are
  2020. * used to figure out the week count for a specific date for a given locale. These
  2021. * must be set when a Calendar is constructed. For example, in US locale,
  2022. * firstDayOfWeek is SUNDAY; minimalDaysInFirstWeek is 1. They are used to figure
  2023. * out the week count for a specific date for a given locale. These must be set when
  2024. * a Calendar is constructed.
  2025. */
  2026. UCalendarDaysOfWeek fFirstDayOfWeek;
  2027. uint8_t fMinimalDaysInFirstWeek;
  2028. UCalendarDaysOfWeek fWeekendOnset;
  2029. int32_t fWeekendOnsetMillis;
  2030. UCalendarDaysOfWeek fWeekendCease;
  2031. int32_t fWeekendCeaseMillis;
  2032. /**
  2033. * Sets firstDayOfWeek and minimalDaysInFirstWeek. Called at Calendar construction
  2034. * time.
  2035. *
  2036. * @param desiredLocale The given locale.
  2037. * @param type The calendar type identifier, e.g: gregorian, buddhist, etc.
  2038. * @param success Indicates the status of setting the week count data from
  2039. * the resource for the given locale. Returns U_ZERO_ERROR if
  2040. * constructed successfully.
  2041. */
  2042. void setWeekData(const Locale& desiredLocale, const char *type, UErrorCode& success);
  2043. /**
  2044. * Recompute the time and update the status fields isTimeSet
  2045. * and areFieldsSet. Callers should check isTimeSet and only
  2046. * call this method if isTimeSet is false.
  2047. *
  2048. * @param status Output param set to success/failure code on exit. If any value
  2049. * previously set in the time field is invalid or restricted by
  2050. * leniency, this will be set to an error status.
  2051. */
  2052. void updateTime(UErrorCode& status);
  2053. /**
  2054. * The Gregorian year, as computed by computeGregorianFields() and
  2055. * returned by getGregorianYear().
  2056. * @see #computeGregorianFields
  2057. */
  2058. int32_t fGregorianYear;
  2059. /**
  2060. * The Gregorian month, as computed by computeGregorianFields() and
  2061. * returned by getGregorianMonth().
  2062. * @see #computeGregorianFields
  2063. */
  2064. int32_t fGregorianMonth;
  2065. /**
  2066. * The Gregorian day of the year, as computed by
  2067. * computeGregorianFields() and returned by getGregorianDayOfYear().
  2068. * @see #computeGregorianFields
  2069. */
  2070. int32_t fGregorianDayOfYear;
  2071. /**
  2072. * The Gregorian day of the month, as computed by
  2073. * computeGregorianFields() and returned by getGregorianDayOfMonth().
  2074. * @see #computeGregorianFields
  2075. */
  2076. int32_t fGregorianDayOfMonth;
  2077. /* calculations */
  2078. /**
  2079. * Compute the Gregorian calendar year, month, and day of month from
  2080. * the given Julian day. These values are not stored in fields, but in
  2081. * member variables gregorianXxx. Also compute the DAY_OF_WEEK and
  2082. * DOW_LOCAL fields.
  2083. */
  2084. void computeGregorianAndDOWFields(int32_t julianDay, UErrorCode &ec);
  2085. protected:
  2086. /**
  2087. * Compute the Gregorian calendar year, month, and day of month from the
  2088. * Julian day. These values are not stored in fields, but in member
  2089. * variables gregorianXxx. They are used for time zone computations and by
  2090. * subclasses that are Gregorian derivatives. Subclasses may call this
  2091. * method to perform a Gregorian calendar millis->fields computation.
  2092. */
  2093. void computeGregorianFields(int32_t julianDay, UErrorCode &ec);
  2094. private:
  2095. /**
  2096. * Compute the fields WEEK_OF_YEAR, YEAR_WOY, WEEK_OF_MONTH,
  2097. * DAY_OF_WEEK_IN_MONTH, and DOW_LOCAL from EXTENDED_YEAR, YEAR,
  2098. * DAY_OF_WEEK, and DAY_OF_YEAR. The latter fields are computed by the
  2099. * subclass based on the calendar system.
  2100. *
  2101. * <p>The YEAR_WOY field is computed simplistically. It is equal to YEAR
  2102. * most of the time, but at the year boundary it may be adjusted to YEAR-1
  2103. * or YEAR+1 to reflect the overlap of a week into an adjacent year. In
  2104. * this case, a simple increment or decrement is performed on YEAR, even
  2105. * though this may yield an invalid YEAR value. For instance, if the YEAR
  2106. * is part of a calendar system with an N-year cycle field CYCLE, then
  2107. * incrementing the YEAR may involve incrementing CYCLE and setting YEAR
  2108. * back to 0 or 1. This is not handled by this code, and in fact cannot be
  2109. * simply handled without having subclasses define an entire parallel set of
  2110. * fields for fields larger than or equal to a year. This additional
  2111. * complexity is not warranted, since the intention of the YEAR_WOY field is
  2112. * to support ISO 8601 notation, so it will typically be used with a
  2113. * proleptic Gregorian calendar, which has no field larger than a year.
  2114. */
  2115. void computeWeekFields(UErrorCode &ec);
  2116. /**
  2117. * Ensure that each field is within its valid range by calling {@link
  2118. * #validateField(int, int&)} on each field that has been set. This method
  2119. * should only be called if this calendar is not lenient.
  2120. * @see #isLenient
  2121. * @see #validateField(int, int&)
  2122. * @internal
  2123. */
  2124. void validateFields(UErrorCode &status);
  2125. /**
  2126. * Validate a single field of this calendar given its minimum and
  2127. * maximum allowed value. If the field is out of range,
  2128. * <code>U_ILLEGAL_ARGUMENT_ERROR</code> will be set. Subclasses may
  2129. * use this method in their implementation of {@link
  2130. * #validateField(int, int&)}.
  2131. * @internal
  2132. */
  2133. void validateField(UCalendarDateFields field, int32_t min, int32_t max, UErrorCode& status);
  2134. protected:
  2135. #ifndef U_HIDE_INTERNAL_API
  2136. /**
  2137. * Convert a quasi Julian date to the day of the week. The Julian date used here is
  2138. * not a true Julian date, since it is measured from midnight, not noon. Return
  2139. * value is one-based.
  2140. *
  2141. * @param julian The given Julian date number.
  2142. * @return Day number from 1..7 (SUN..SAT).
  2143. * @internal
  2144. */
  2145. static uint8_t julianDayToDayOfWeek(double julian);
  2146. #endif /* U_HIDE_INTERNAL_API */
  2147. private:
  2148. char validLocale[ULOC_FULLNAME_CAPACITY];
  2149. char actualLocale[ULOC_FULLNAME_CAPACITY];
  2150. public:
  2151. #if !UCONFIG_NO_SERVICE
  2152. /**
  2153. * INTERNAL FOR 2.6 -- Registration.
  2154. */
  2155. #ifndef U_HIDE_INTERNAL_API
  2156. /**
  2157. * Return a StringEnumeration over the locales available at the time of the call,
  2158. * including registered locales.
  2159. * @return a StringEnumeration over the locales available at the time of the call
  2160. * @internal
  2161. */
  2162. static StringEnumeration* getAvailableLocales(void);
  2163. /**
  2164. * Register a new Calendar factory. The factory will be adopted.
  2165. * INTERNAL in 2.6
  2166. *
  2167. * Because ICU may choose to cache Calendars internally, this must
  2168. * be called at application startup, prior to any calls to
  2169. * Calendar::createInstance to avoid undefined behavior.
  2170. *
  2171. * @param toAdopt the factory instance to be adopted
  2172. * @param status the in/out status code, no special meanings are assigned
  2173. * @return a registry key that can be used to unregister this factory
  2174. * @internal
  2175. */
  2176. static URegistryKey registerFactory(ICUServiceFactory* toAdopt, UErrorCode& status);
  2177. /**
  2178. * Unregister a previously-registered CalendarFactory using the key returned from the
  2179. * register call. Key becomes invalid after a successful call and should not be used again.
  2180. * The CalendarFactory corresponding to the key will be deleted.
  2181. * INTERNAL in 2.6
  2182. *
  2183. * Because ICU may choose to cache Calendars internally, this should
  2184. * be called during application shutdown, after all calls to
  2185. * Calendar::createInstance to avoid undefined behavior.
  2186. *
  2187. * @param key the registry key returned by a previous call to registerFactory
  2188. * @param status the in/out status code, no special meanings are assigned
  2189. * @return TRUE if the factory for the key was successfully unregistered
  2190. * @internal
  2191. */
  2192. static UBool unregister(URegistryKey key, UErrorCode& status);
  2193. #endif /* U_HIDE_INTERNAL_API */
  2194. /**
  2195. * Multiple Calendar Implementation
  2196. * @internal
  2197. */
  2198. friend class CalendarFactory;
  2199. /**
  2200. * Multiple Calendar Implementation
  2201. * @internal
  2202. */
  2203. friend class CalendarService;
  2204. /**
  2205. * Multiple Calendar Implementation
  2206. * @internal
  2207. */
  2208. friend class DefaultCalendarFactory;
  2209. #endif /* !UCONFIG_NO_SERVICE */
  2210. /**
  2211. * @return TRUE if this calendar has a default century (i.e. 03 -> 2003)
  2212. * @internal
  2213. */
  2214. virtual UBool haveDefaultCentury() const = 0;
  2215. /**
  2216. * @return the start of the default century, as a UDate
  2217. * @internal
  2218. */
  2219. virtual UDate defaultCenturyStart() const = 0;
  2220. /**
  2221. * @return the beginning year of the default century, as a year
  2222. * @internal
  2223. */
  2224. virtual int32_t defaultCenturyStartYear() const = 0;
  2225. /** Get the locale for this calendar object. You can choose between valid and actual locale.
  2226. * @param type type of the locale we're looking for (valid or actual)
  2227. * @param status error code for the operation
  2228. * @return the locale
  2229. * @stable ICU 2.8
  2230. */
  2231. Locale getLocale(ULocDataLocaleType type, UErrorCode &status) const;
  2232. /**
  2233. * @return The related Gregorian year; will be obtained by modifying the value
  2234. * obtained by get from UCAL_EXTENDED_YEAR field
  2235. * @internal
  2236. */
  2237. virtual int32_t getRelatedYear(UErrorCode &status) const;
  2238. /**
  2239. * @param year The related Gregorian year to set; will be modified as necessary then
  2240. * set in UCAL_EXTENDED_YEAR field
  2241. * @internal
  2242. */
  2243. virtual void setRelatedYear(int32_t year);
  2244. #ifndef U_HIDE_INTERNAL_API
  2245. /** Get the locale for this calendar object. You can choose between valid and actual locale.
  2246. * @param type type of the locale we're looking for (valid or actual)
  2247. * @param status error code for the operation
  2248. * @return the locale
  2249. * @internal
  2250. */
  2251. const char* getLocaleID(ULocDataLocaleType type, UErrorCode &status) const;
  2252. #endif /* U_HIDE_INTERNAL_API */
  2253. private:
  2254. /**
  2255. * Cast TimeZone used by this object to BasicTimeZone, or NULL if the TimeZone
  2256. * is not an instance of BasicTimeZone.
  2257. */
  2258. BasicTimeZone* getBasicTimeZone() const;
  2259. /**
  2260. * Find the previous zone transtion near the given time.
  2261. * @param base The base time, inclusive
  2262. * @param transitionTime Receives the result time
  2263. * @param status The error status
  2264. * @return TRUE if a transition is found.
  2265. */
  2266. UBool getImmediatePreviousZoneTransition(UDate base, UDate *transitionTime, UErrorCode& status) const;
  2267. public:
  2268. #ifndef U_HIDE_INTERNAL_API
  2269. /**
  2270. * Creates a new Calendar from a Locale for the cache.
  2271. * This method does not set the time or timezone in returned calendar.
  2272. * @param locale the locale.
  2273. * @param status any error returned here.
  2274. * @return the new Calendar object with no time or timezone set.
  2275. * @internal For ICU use only.
  2276. */
  2277. static Calendar * U_EXPORT2 makeInstance(
  2278. const Locale &locale, UErrorCode &status);
  2279. /**
  2280. * Get the calendar type for given locale.
  2281. * @param locale the locale
  2282. * @param typeBuffer calendar type returned here
  2283. * @param typeBufferSize The size of typeBuffer in bytes. If the type
  2284. * can't fit in the buffer, this method sets status to
  2285. * U_BUFFER_OVERFLOW_ERROR
  2286. * @param status error, if any, returned here.
  2287. * @internal For ICU use only.
  2288. */
  2289. static void U_EXPORT2 getCalendarTypeFromLocale(
  2290. const Locale &locale,
  2291. char *typeBuffer,
  2292. int32_t typeBufferSize,
  2293. UErrorCode &status);
  2294. #endif /* U_HIDE_INTERNAL_API */
  2295. };
  2296. // -------------------------------------
  2297. inline Calendar*
  2298. Calendar::createInstance(TimeZone* zone, UErrorCode& errorCode)
  2299. {
  2300. // since the Locale isn't specified, use the default locale
  2301. return createInstance(zone, Locale::getDefault(), errorCode);
  2302. }
  2303. // -------------------------------------
  2304. inline void
  2305. Calendar::roll(UCalendarDateFields field, UBool up, UErrorCode& status)
  2306. {
  2307. roll(field, (int32_t)(up ? +1 : -1), status);
  2308. }
  2309. #ifndef U_HIDE_DEPRECATED_API
  2310. inline void
  2311. Calendar::roll(EDateFields field, UBool up, UErrorCode& status)
  2312. {
  2313. roll((UCalendarDateFields) field, up, status);
  2314. }
  2315. #endif /* U_HIDE_DEPRECATED_API */
  2316. // -------------------------------------
  2317. /**
  2318. * Fast method for subclasses. The caller must maintain fUserSetDSTOffset and
  2319. * fUserSetZoneOffset, as well as the isSet[] array.
  2320. */
  2321. inline void
  2322. Calendar::internalSet(UCalendarDateFields field, int32_t value)
  2323. {
  2324. fFields[field] = value;
  2325. fStamp[field] = kInternallySet;
  2326. fIsSet[field] = TRUE; // Remove later
  2327. }
  2328. #ifndef U_HIDE_INTERNAL_API
  2329. inline int32_t Calendar::weekNumber(int32_t dayOfPeriod, int32_t dayOfWeek)
  2330. {
  2331. return weekNumber(dayOfPeriod, dayOfPeriod, dayOfWeek);
  2332. }
  2333. #endif /* U_HIDE_INTERNAL_API */
  2334. U_NAMESPACE_END
  2335. #endif /* #if !UCONFIG_NO_FORMATTING */
  2336. #endif // _CALENDAR