calendar.h 106 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551
  1. // © 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. #if U_SHOW_CPLUSPLUS_API
  30. /**
  31. * \file
  32. * \brief C++ API: Calendar object
  33. */
  34. #if !UCONFIG_NO_FORMATTING
  35. #include "unicode/uobject.h"
  36. #include "unicode/locid.h"
  37. #include "unicode/timezone.h"
  38. #include "unicode/ucal.h"
  39. #include "unicode/umisc.h"
  40. U_NAMESPACE_BEGIN
  41. class ICUServiceFactory;
  42. /**
  43. * @internal
  44. */
  45. typedef int32_t UFieldResolutionTable[12][8];
  46. class BasicTimeZone;
  47. /**
  48. * `Calendar` is an abstract base class for converting between
  49. * a `UDate` object and a set of integer fields such as
  50. * `YEAR`, `MONTH`, `DAY`, `HOUR`, and so on.
  51. * (A `UDate` object represents a specific instant in
  52. * time with millisecond precision. See UDate
  53. * for information about the `UDate` class.)
  54. *
  55. * Subclasses of `Calendar` interpret a `UDate`
  56. * according to the rules of a specific calendar system.
  57. * The most commonly used subclass of `Calendar` is
  58. * `GregorianCalendar`. Other subclasses could represent
  59. * the various types of lunar calendars in use in many parts of the world.
  60. *
  61. * **NOTE**: (ICU 2.6) The subclass interface should be considered unstable -
  62. * it WILL change.
  63. *
  64. * Like other locale-sensitive classes, `Calendar` provides a
  65. * static method, `createInstance`, for getting a generally useful
  66. * object of this type. `Calendar`'s `createInstance` method
  67. * returns the appropriate `Calendar` subclass whose
  68. * time fields have been initialized with the current date and time:
  69. *
  70. * Calendar *rightNow = Calendar::createInstance(errCode);
  71. *
  72. * A `Calendar` object can produce all the time field values
  73. * needed to implement the date-time formatting for a particular language
  74. * and calendar style (for example, Japanese-Gregorian, Japanese-Traditional).
  75. *
  76. * When computing a `UDate` from time fields, some special circumstances
  77. * may arise: there may be insufficient information to compute the
  78. * `UDate` (such as only year and month but no day in the month),
  79. * there may be inconsistent information (such as "Tuesday, July 15, 1996"
  80. * -- July 15, 1996 is actually a Monday), or the input time might be ambiguous
  81. * because of time zone transition.
  82. *
  83. * **Insufficient information.** The calendar will use default
  84. * information to specify the missing fields. This may vary by calendar; for
  85. * the Gregorian calendar, the default for a field is the same as that of the
  86. * start of the epoch: i.e., YEAR = 1970, MONTH = JANUARY, DATE = 1, etc.
  87. *
  88. * **Inconsistent information.** If fields conflict, the calendar
  89. * will give preference to fields set more recently. For example, when
  90. * determining the day, the calendar will look for one of the following
  91. * combinations of fields. The most recent combination, as determined by the
  92. * most recently set single field, will be used.
  93. *
  94. * MONTH + DAY_OF_MONTH
  95. * MONTH + WEEK_OF_MONTH + DAY_OF_WEEK
  96. * MONTH + DAY_OF_WEEK_IN_MONTH + DAY_OF_WEEK
  97. * DAY_OF_YEAR
  98. * DAY_OF_WEEK + WEEK_OF_YEAR
  99. *
  100. * For the time of day:
  101. *
  102. * HOUR_OF_DAY
  103. * AM_PM + HOUR
  104. *
  105. * **Ambiguous Wall Clock Time.** When time offset from UTC has
  106. * changed, it produces an ambiguous time slot around the transition. For example,
  107. * many US locations observe daylight saving time. On the date switching to daylight
  108. * saving time in US, wall clock time jumps from 12:59 AM (standard) to 2:00 AM
  109. * (daylight). Therefore, wall clock time from 1:00 AM to 1:59 AM do not exist on
  110. * the date. When the input wall time fall into this missing time slot, the ICU
  111. * Calendar resolves the time using the UTC offset before the transition by default.
  112. * In this example, 1:30 AM is interpreted as 1:30 AM standard time (non-exist),
  113. * so the final result will be 2:30 AM daylight time.
  114. *
  115. * On the date switching back to standard time, wall clock time is moved back one
  116. * hour at 2:00 AM. So wall clock time from 1:00 AM to 1:59 AM occur twice. In this
  117. * case, the ICU Calendar resolves the time using the UTC offset after the transition
  118. * by default. For example, 1:30 AM on the date is resolved as 1:30 AM standard time.
  119. *
  120. * Ambiguous wall clock time resolution behaviors can be customized by Calendar APIs
  121. * {@link #setRepeatedWallTimeOption} and {@link #setSkippedWallTimeOption}.
  122. * These methods are available in ICU 49 or later versions.
  123. *
  124. * **Note:** for some non-Gregorian calendars, different
  125. * fields may be necessary for complete disambiguation. For example, a full
  126. * specification of the historical Arabic astronomical calendar requires year,
  127. * month, day-of-month *and* day-of-week in some cases.
  128. *
  129. * **Note:** There are certain possible ambiguities in
  130. * interpretation of certain singular times, which are resolved in the
  131. * following ways:
  132. *
  133. * 1. 24:00:00 "belongs" to the following day. That is,
  134. * 23:59 on Dec 31, 1969 < 24:00 on Jan 1, 1970 < 24:01:00 on Jan 1, 1970
  135. * 2. Although historically not precise, midnight also belongs to "am",
  136. * and noon belongs to "pm", so on the same day,
  137. * 12:00 am (midnight) < 12:01 am, and 12:00 pm (noon) < 12:01 pm
  138. *
  139. * The date or time format strings are not part of the definition of a
  140. * calendar, as those must be modifiable or overridable by the user at
  141. * runtime. Use `DateFormat` to format dates.
  142. *
  143. * `Calendar` provides an API for field "rolling", where fields
  144. * can be incremented or decremented, but wrap around. For example, rolling the
  145. * month up in the date December 12, **1996** results in
  146. * January 12, **1996**.
  147. *
  148. * `Calendar` also provides a date arithmetic function for
  149. * adding the specified (signed) amount of time to a particular time field.
  150. * For example, subtracting 5 days from the date `September 12, 1996`
  151. * results in `September 7, 1996`.
  152. *
  153. * ***Supported range***
  154. *
  155. * The allowable range of `Calendar` has been narrowed. `GregorianCalendar` used
  156. * to attempt to support the range of dates with millisecond values from
  157. * `Long.MIN_VALUE` to `Long.MAX_VALUE`. The new `Calendar` protocol specifies the
  158. * maximum range of supportable dates as those having Julian day numbers
  159. * of `-0x7F000000` to `+0x7F000000`. This corresponds to years from ~5,800,000 BCE
  160. * to ~5,800,000 CE. Programmers should use the protected constants in `Calendar` to
  161. * specify an extremely early or extremely late date.
  162. *
  163. * <p>
  164. * The Japanese calendar uses a combination of era name and year number.
  165. * When an emperor of Japan abdicates and a new emperor ascends the throne,
  166. * a new era is declared and year number is reset to 1. Even if the date of
  167. * abdication is scheduled ahead of time, the new era name might not be
  168. * announced until just before the date. In such case, ICU4C may include
  169. * a start date of future era without actual era name, but not enabled
  170. * by default. ICU4C users who want to test the behavior of the future era
  171. * can enable the tentative era by:
  172. * <ul>
  173. * <li>Environment variable <code>ICU_ENABLE_TENTATIVE_ERA=true</code>.</li>
  174. * </ul>
  175. *
  176. * @stable ICU 2.0
  177. */
  178. class U_I18N_API Calendar : public UObject {
  179. public:
  180. #ifndef U_FORCE_HIDE_DEPRECATED_API
  181. /**
  182. * Field IDs for date and time. Used to specify date/time fields. ERA is calendar
  183. * specific. Example ranges given are for illustration only; see specific Calendar
  184. * subclasses for actual ranges.
  185. * @deprecated ICU 2.6. Use C enum UCalendarDateFields defined in ucal.h
  186. */
  187. enum EDateFields {
  188. #ifndef U_HIDE_DEPRECATED_API
  189. /*
  190. * ERA may be defined on other platforms. To avoid any potential problems undefined it here.
  191. */
  192. #ifdef ERA
  193. #undef ERA
  194. #endif
  195. ERA, // Example: 0..1
  196. YEAR, // Example: 1..big number
  197. MONTH, // Example: 0..11
  198. WEEK_OF_YEAR, // Example: 1..53
  199. WEEK_OF_MONTH, // Example: 1..4
  200. DATE, // Example: 1..31
  201. DAY_OF_YEAR, // Example: 1..365
  202. DAY_OF_WEEK, // Example: 1..7
  203. DAY_OF_WEEK_IN_MONTH, // Example: 1..4, may be specified as -1
  204. AM_PM, // Example: 0..1
  205. HOUR, // Example: 0..11
  206. HOUR_OF_DAY, // Example: 0..23
  207. MINUTE, // Example: 0..59
  208. SECOND, // Example: 0..59
  209. MILLISECOND, // Example: 0..999
  210. ZONE_OFFSET, // Example: -12*U_MILLIS_PER_HOUR..12*U_MILLIS_PER_HOUR
  211. DST_OFFSET, // Example: 0 or U_MILLIS_PER_HOUR
  212. YEAR_WOY, // 'Y' Example: 1..big number - Year of Week of Year
  213. DOW_LOCAL, // 'e' Example: 1..7 - Day of Week / Localized
  214. EXTENDED_YEAR,
  215. JULIAN_DAY,
  216. MILLISECONDS_IN_DAY,
  217. IS_LEAP_MONTH,
  218. FIELD_COUNT = UCAL_FIELD_COUNT // See ucal.h for other fields.
  219. #endif /* U_HIDE_DEPRECATED_API */
  220. };
  221. #endif // U_FORCE_HIDE_DEPRECATED_API
  222. #ifndef U_HIDE_DEPRECATED_API
  223. /**
  224. * Useful constant for days of week. Note: Calendar day-of-week is 1-based. Clients
  225. * who create locale resources for the field of first-day-of-week should be aware of
  226. * this. For instance, in US locale, first-day-of-week is set to 1, i.e., SUNDAY.
  227. * @deprecated ICU 2.6. Use C enum UCalendarDaysOfWeek defined in ucal.h
  228. */
  229. enum EDaysOfWeek {
  230. SUNDAY = 1,
  231. MONDAY,
  232. TUESDAY,
  233. WEDNESDAY,
  234. THURSDAY,
  235. FRIDAY,
  236. SATURDAY
  237. };
  238. /**
  239. * Useful constants for month. Note: Calendar month is 0-based.
  240. * @deprecated ICU 2.6. Use C enum UCalendarMonths defined in ucal.h
  241. */
  242. enum EMonths {
  243. JANUARY,
  244. FEBRUARY,
  245. MARCH,
  246. APRIL,
  247. MAY,
  248. JUNE,
  249. JULY,
  250. AUGUST,
  251. SEPTEMBER,
  252. OCTOBER,
  253. NOVEMBER,
  254. DECEMBER,
  255. UNDECIMBER
  256. };
  257. /**
  258. * Useful constants for hour in 12-hour clock. Used in GregorianCalendar.
  259. * @deprecated ICU 2.6. Use C enum UCalendarAMPMs defined in ucal.h
  260. */
  261. enum EAmpm {
  262. AM,
  263. PM
  264. };
  265. #endif /* U_HIDE_DEPRECATED_API */
  266. /**
  267. * destructor
  268. * @stable ICU 2.0
  269. */
  270. virtual ~Calendar();
  271. /**
  272. * Create and return a polymorphic copy of this calendar.
  273. *
  274. * @return a polymorphic copy of this calendar.
  275. * @stable ICU 2.0
  276. */
  277. virtual Calendar* clone() const = 0;
  278. /**
  279. * Creates a Calendar using the default timezone and locale. Clients are responsible
  280. * for deleting the object returned.
  281. *
  282. * @param success Indicates the success/failure of Calendar creation. Filled in
  283. * with U_ZERO_ERROR if created successfully, set to a failure result
  284. * otherwise. U_MISSING_RESOURCE_ERROR will be returned if the resource data
  285. * requests a calendar type which has not been installed.
  286. * @return A Calendar if created successfully. NULL otherwise.
  287. * @stable ICU 2.0
  288. */
  289. static Calendar* U_EXPORT2 createInstance(UErrorCode& success);
  290. /**
  291. * Creates a Calendar using the given timezone and the default locale.
  292. * The Calendar takes ownership of zoneToAdopt; the
  293. * client must not delete it.
  294. *
  295. * @param zoneToAdopt The given timezone to be adopted.
  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.
  299. * @return A Calendar if created successfully. NULL otherwise.
  300. * @stable ICU 2.0
  301. */
  302. static Calendar* U_EXPORT2 createInstance(TimeZone* zoneToAdopt, UErrorCode& success);
  303. /**
  304. * Creates a Calendar using the given timezone and the default locale. The TimeZone
  305. * is _not_ adopted; the client is still responsible for deleting it.
  306. *
  307. * @param zone The timezone.
  308. * @param success Indicates the success/failure of Calendar creation. Filled in
  309. * with U_ZERO_ERROR if created successfully, set to a failure result
  310. * otherwise.
  311. * @return A Calendar if created successfully. NULL otherwise.
  312. * @stable ICU 2.0
  313. */
  314. static Calendar* U_EXPORT2 createInstance(const TimeZone& zone, UErrorCode& success);
  315. /**
  316. * Creates a Calendar using the default timezone and the given locale.
  317. *
  318. * @param aLocale The given locale.
  319. * @param success Indicates the success/failure of Calendar creation. Filled in
  320. * with U_ZERO_ERROR if created successfully, set to a failure result
  321. * otherwise.
  322. * @return A Calendar if created successfully. NULL otherwise.
  323. * @stable ICU 2.0
  324. */
  325. static Calendar* U_EXPORT2 createInstance(const Locale& aLocale, UErrorCode& success);
  326. /**
  327. * Creates a Calendar using the given timezone and given locale.
  328. * The Calendar takes ownership of zoneToAdopt; the
  329. * client must not delete it.
  330. *
  331. * @param zoneToAdopt The given timezone to be adopted.
  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(TimeZone* zoneToAdopt, const Locale& aLocale, UErrorCode& success);
  340. /**
  341. * Gets a Calendar using the given timezone and given locale. The TimeZone
  342. * is _not_ adopted; the client is still responsible for deleting it.
  343. *
  344. * @param zone The given timezone.
  345. * @param aLocale The given locale.
  346. * @param success Indicates the success/failure of Calendar creation. Filled in
  347. * with U_ZERO_ERROR if created successfully, set to a failure result
  348. * otherwise.
  349. * @return A Calendar if created successfully. NULL otherwise.
  350. * @stable ICU 2.0
  351. */
  352. static Calendar* U_EXPORT2 createInstance(const TimeZone& zone, const Locale& aLocale, UErrorCode& success);
  353. /**
  354. * Returns a list of the locales for which Calendars are installed.
  355. *
  356. * @param count Number of locales returned.
  357. * @return An array of Locale objects representing the set of locales for which
  358. * Calendars are installed. The system retains ownership of this list;
  359. * the caller must NOT delete it. Does not include user-registered Calendars.
  360. * @stable ICU 2.0
  361. */
  362. static const Locale* U_EXPORT2 getAvailableLocales(int32_t& count);
  363. /**
  364. * Given a key and a locale, returns an array of string values in a preferred
  365. * order that would make a difference. These are all and only those values where
  366. * the open (creation) of the service with the locale formed from the input locale
  367. * plus input keyword and that value has different behavior than creation with the
  368. * input locale alone.
  369. * @param key one of the keys supported by this service. For now, only
  370. * "calendar" is supported.
  371. * @param locale the locale
  372. * @param commonlyUsed if set to true it will return only commonly used values
  373. * with the given locale in preferred order. Otherwise,
  374. * it will return all the available values for the locale.
  375. * @param status ICU Error Code
  376. * @return a string enumeration over keyword values for the given key and the locale.
  377. * @stable ICU 4.2
  378. */
  379. static StringEnumeration* U_EXPORT2 getKeywordValuesForLocale(const char* key,
  380. const Locale& locale, UBool commonlyUsed, UErrorCode& status);
  381. /**
  382. * Returns the current UTC (GMT) time measured in milliseconds since 0:00:00 on 1/1/70
  383. * (derived from the system time).
  384. *
  385. * @return The current UTC time in milliseconds.
  386. * @stable ICU 2.0
  387. */
  388. static UDate U_EXPORT2 getNow(void);
  389. /**
  390. * Gets this Calendar's time as milliseconds. May involve recalculation of time due
  391. * to previous calls to set time field values. The time specified is non-local UTC
  392. * (GMT) time. Although this method is const, this object may actually be changed
  393. * (semantically const).
  394. *
  395. * @param status Output param set to success/failure code on exit. If any value
  396. * previously set in the time field is invalid or restricted by
  397. * leniency, this will be set to an error status.
  398. * @return The current time in UTC (GMT) time, or zero if the operation
  399. * failed.
  400. * @stable ICU 2.0
  401. */
  402. inline UDate getTime(UErrorCode& status) const { return getTimeInMillis(status); }
  403. /**
  404. * Sets this Calendar's current time with the given UDate. The time specified should
  405. * be in non-local UTC (GMT) time.
  406. *
  407. * @param date The given UDate in UTC (GMT) time.
  408. * @param status Output param set to success/failure code on exit. If any value
  409. * set in the time field is invalid or restricted by
  410. * leniency, this will be set to an error status.
  411. * @stable ICU 2.0
  412. */
  413. inline void setTime(UDate date, UErrorCode& status) { setTimeInMillis(date, status); }
  414. /**
  415. * Compares the equality of two Calendar objects. Objects of different subclasses
  416. * are considered unequal. This comparison is very exacting; two Calendar objects
  417. * must be in exactly the same state to be considered equal. To compare based on the
  418. * represented time, use equals() instead.
  419. *
  420. * @param that The Calendar object to be compared with.
  421. * @return True if the given Calendar is the same as this Calendar; false
  422. * otherwise.
  423. * @stable ICU 2.0
  424. */
  425. virtual UBool operator==(const Calendar& that) const;
  426. /**
  427. * Compares the inequality of two Calendar objects.
  428. *
  429. * @param that The Calendar object to be compared with.
  430. * @return True if the given Calendar is not the same as this Calendar; false
  431. * otherwise.
  432. * @stable ICU 2.0
  433. */
  434. UBool operator!=(const Calendar& that) const {return !operator==(that);}
  435. /**
  436. * Returns TRUE if the given Calendar object is equivalent to this
  437. * one. An equivalent Calendar will behave exactly as this one
  438. * does, but it may be set to a different time. By contrast, for
  439. * the operator==() method to return TRUE, the other Calendar must
  440. * be set to the same time.
  441. *
  442. * @param other the Calendar to be compared with this Calendar
  443. * @stable ICU 2.4
  444. */
  445. virtual UBool isEquivalentTo(const Calendar& other) const;
  446. /**
  447. * Compares the Calendar time, whereas Calendar::operator== compares the equality of
  448. * Calendar objects.
  449. *
  450. * @param when The Calendar to be compared with this Calendar. Although this is a
  451. * const parameter, the object may be modified physically
  452. * (semantically const).
  453. * @param status Output param set to success/failure code on exit. If any value
  454. * previously set in the time field is invalid or restricted by
  455. * leniency, this will be set to an error status.
  456. * @return True if the current time of this Calendar is equal to the time of
  457. * Calendar when; false otherwise.
  458. * @stable ICU 2.0
  459. */
  460. UBool equals(const Calendar& when, UErrorCode& status) const;
  461. /**
  462. * Returns true if this Calendar's current time is before "when"'s current time.
  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 before the time of
  471. * Calendar when; false otherwise.
  472. * @stable ICU 2.0
  473. */
  474. UBool before(const Calendar& when, UErrorCode& status) const;
  475. /**
  476. * Returns true if this Calendar's current time is after "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 after the time of
  485. * Calendar when; false otherwise.
  486. * @stable ICU 2.0
  487. */
  488. UBool after(const Calendar& when, UErrorCode& status) const;
  489. #ifndef U_FORCE_HIDE_DEPRECATED_API
  490. /**
  491. * UDate Arithmetic function. Adds the specified (signed) amount of time to the given
  492. * time field, based on the calendar's rules. For example, to subtract 5 days from
  493. * the current time of the calendar, call add(Calendar::DATE, -5). When adding on
  494. * the month or Calendar::MONTH field, other fields like date might conflict and
  495. * need to be changed. For instance, adding 1 month on the date 01/31/96 will result
  496. * in 02/29/96.
  497. * Adding a positive value always means moving forward in time, so for the Gregorian calendar,
  498. * starting with 100 BC and adding +1 to year results in 99 BC (even though this actually reduces
  499. * the numeric value of the field itself).
  500. *
  501. * @param field Specifies which date field to modify.
  502. * @param amount The amount of time to be added to the field, in the natural unit
  503. * for that field (e.g., days for the day fields, hours for the hour
  504. * field.)
  505. * @param status Output param set to success/failure code on exit. If any value
  506. * previously set in the time field is invalid or restricted by
  507. * leniency, this will be set to an error status.
  508. * @deprecated ICU 2.6. use add(UCalendarDateFields field, int32_t amount, UErrorCode& status) instead.
  509. */
  510. virtual void add(EDateFields field, int32_t amount, UErrorCode& status);
  511. #endif // U_FORCE_HIDE_DEPRECATED_API
  512. /**
  513. * UDate Arithmetic function. Adds the specified (signed) amount of time to the given
  514. * time field, based on the calendar's rules. For example, to subtract 5 days from
  515. * the current time of the calendar, call add(Calendar::DATE, -5). When adding on
  516. * the month or Calendar::MONTH field, other fields like date might conflict and
  517. * need to be changed. For instance, adding 1 month on the date 01/31/96 will result
  518. * in 02/29/96.
  519. * Adding a positive value always means moving forward in time, so for the Gregorian calendar,
  520. * starting with 100 BC and adding +1 to year results in 99 BC (even though this actually reduces
  521. * the numeric value of the field itself).
  522. *
  523. * @param field Specifies which date field to modify.
  524. * @param amount The amount of time to be added to the field, in the natural unit
  525. * for that field (e.g., days for the day fields, hours for the hour
  526. * field.)
  527. * @param status Output param set to success/failure code on exit. If any value
  528. * previously set in the time field is invalid or restricted by
  529. * leniency, this will be set to an error status.
  530. * @stable ICU 2.6.
  531. */
  532. virtual void add(UCalendarDateFields field, int32_t amount, UErrorCode& status);
  533. #ifndef U_HIDE_DEPRECATED_API
  534. /**
  535. * Time Field Rolling function. Rolls (up/down) a single unit of time on the given
  536. * time field. For example, to roll the current date up by one day, call
  537. * roll(Calendar::DATE, true). When rolling on the year or Calendar::YEAR field, it
  538. * will roll the year value in the range between getMinimum(Calendar::YEAR) and the
  539. * value returned by getMaximum(Calendar::YEAR). When rolling on the month or
  540. * Calendar::MONTH field, other fields like date might conflict and, need to be
  541. * changed. For instance, rolling the month up on the date 01/31/96 will result in
  542. * 02/29/96. Rolling up always means rolling forward in time (unless the limit of the
  543. * field is reached, in which case it may pin or wrap), so for Gregorian calendar,
  544. * starting with 100 BC and rolling the year up results in 99 BC.
  545. * When eras have a definite beginning and end (as in the Chinese calendar, or as in
  546. * most eras in the Japanese calendar) then rolling the year past either limit of the
  547. * era will cause the year to wrap around. When eras only have a limit at one end,
  548. * then attempting to roll the year past that limit will result in pinning the year
  549. * at that limit. Note that for most calendars in which era 0 years move forward in
  550. * time (such as Buddhist, Hebrew, or Islamic), it is possible for add or roll to
  551. * result in negative years for era 0 (that is the only way to represent years before
  552. * the calendar epoch).
  553. * When rolling on the hour-in-day or Calendar::HOUR_OF_DAY field, it will roll the
  554. * hour value in the range between 0 and 23, which is zero-based.
  555. * <P>
  556. * NOTE: Do not use this method -- use roll(EDateFields, int, UErrorCode&) instead.
  557. *
  558. * @param field The time field.
  559. * @param up Indicates if the value of the specified time field is to be rolled
  560. * up or rolled down. Use true if rolling up, false otherwise.
  561. * @param status Output param set to success/failure code on exit. If any value
  562. * previously set in the time field is invalid or restricted by
  563. * leniency, this will be set to an error status.
  564. * @deprecated ICU 2.6. Use roll(UCalendarDateFields field, UBool up, UErrorCode& status) instead.
  565. */
  566. inline void roll(EDateFields field, UBool up, UErrorCode& status);
  567. #endif /* U_HIDE_DEPRECATED_API */
  568. /**
  569. * Time Field Rolling function. Rolls (up/down) a single unit of time on the given
  570. * time field. For example, to roll the current date up by one day, call
  571. * roll(Calendar::DATE, true). When rolling on the year or Calendar::YEAR field, it
  572. * will roll the year value in the range between getMinimum(Calendar::YEAR) and the
  573. * value returned by getMaximum(Calendar::YEAR). When rolling on the month or
  574. * Calendar::MONTH field, other fields like date might conflict and, need to be
  575. * changed. For instance, rolling the month up on the date 01/31/96 will result in
  576. * 02/29/96. Rolling up always means rolling forward in time (unless the limit of the
  577. * field is reached, in which case it may pin or wrap), so for Gregorian calendar,
  578. * starting with 100 BC and rolling the year up results in 99 BC.
  579. * When eras have a definite beginning and end (as in the Chinese calendar, or as in
  580. * most eras in the Japanese calendar) then rolling the year past either limit of the
  581. * era will cause the year to wrap around. When eras only have a limit at one end,
  582. * then attempting to roll the year past that limit will result in pinning the year
  583. * at that limit. Note that for most calendars in which era 0 years move forward in
  584. * time (such as Buddhist, Hebrew, or Islamic), it is possible for add or roll to
  585. * result in negative years for era 0 (that is the only way to represent years before
  586. * the calendar epoch).
  587. * When rolling on the hour-in-day or Calendar::HOUR_OF_DAY field, it will roll the
  588. * hour value in the range between 0 and 23, which is zero-based.
  589. * <P>
  590. * NOTE: Do not use this method -- use roll(UCalendarDateFields, int, UErrorCode&) instead.
  591. *
  592. * @param field The time field.
  593. * @param up Indicates if the value of the specified time field is to be rolled
  594. * up or rolled down. Use true if rolling up, false otherwise.
  595. * @param status Output param set to success/failure code on exit. If any value
  596. * previously set in the time field is invalid or restricted by
  597. * leniency, this will be set to an error status.
  598. * @stable ICU 2.6.
  599. */
  600. inline void roll(UCalendarDateFields field, UBool up, UErrorCode& status);
  601. #ifndef U_FORCE_HIDE_DEPRECATED_API
  602. /**
  603. * Time Field Rolling function. Rolls by the given amount on the given
  604. * time field. For example, to roll the current date up by one day, call
  605. * roll(Calendar::DATE, +1, status). When rolling on the month or
  606. * Calendar::MONTH field, other fields like date might conflict and, need to be
  607. * changed. For instance, rolling the month up on the date 01/31/96 will result in
  608. * 02/29/96. Rolling by a positive value always means rolling forward in time (unless
  609. * the limit of the field is reached, in which case it may pin or wrap), so for
  610. * Gregorian calendar, starting with 100 BC and rolling the year by + 1 results in 99 BC.
  611. * When eras have a definite beginning and end (as in the Chinese calendar, or as in
  612. * most eras in the Japanese calendar) then rolling the year past either limit of the
  613. * era will cause the year to wrap around. When eras only have a limit at one end,
  614. * then attempting to roll the year past that limit will result in pinning the year
  615. * at that limit. Note that for most calendars in which era 0 years move forward in
  616. * time (such as Buddhist, Hebrew, or Islamic), it is possible for add or roll to
  617. * result in negative years for era 0 (that is the only way to represent years before
  618. * the calendar epoch).
  619. * When rolling on the hour-in-day or Calendar::HOUR_OF_DAY field, it will roll the
  620. * hour value in the range between 0 and 23, which is zero-based.
  621. * <P>
  622. * The only difference between roll() and add() is that roll() does not change
  623. * the value of more significant fields when it reaches the minimum or maximum
  624. * of its range, whereas add() does.
  625. *
  626. * @param field The time field.
  627. * @param amount Indicates amount to roll.
  628. * @param status Output param set to success/failure code on exit. If any value
  629. * previously set in the time field is invalid, this will be set to
  630. * an error status.
  631. * @deprecated ICU 2.6. Use roll(UCalendarDateFields field, int32_t amount, UErrorCode& status) instead.
  632. */
  633. virtual void roll(EDateFields field, int32_t amount, UErrorCode& status);
  634. #endif // U_FORCE_HIDE_DEPRECATED_API
  635. /**
  636. * Time Field Rolling function. Rolls by the given amount on the given
  637. * time field. For example, to roll the current date up by one day, call
  638. * roll(Calendar::DATE, +1, status). When rolling on the month or
  639. * Calendar::MONTH field, other fields like date might conflict and, need to be
  640. * changed. For instance, rolling the month up on the date 01/31/96 will result in
  641. * 02/29/96. Rolling by a positive value always means rolling forward in time (unless
  642. * the limit of the field is reached, in which case it may pin or wrap), so for
  643. * Gregorian calendar, starting with 100 BC and rolling the year by + 1 results in 99 BC.
  644. * When eras have a definite beginning and end (as in the Chinese calendar, or as in
  645. * most eras in the Japanese calendar) then rolling the year past either limit of the
  646. * era will cause the year to wrap around. When eras only have a limit at one end,
  647. * then attempting to roll the year past that limit will result in pinning the year
  648. * at that limit. Note that for most calendars in which era 0 years move forward in
  649. * time (such as Buddhist, Hebrew, or Islamic), it is possible for add or roll to
  650. * result in negative years for era 0 (that is the only way to represent years before
  651. * the calendar epoch).
  652. * When rolling on the hour-in-day or Calendar::HOUR_OF_DAY field, it will roll the
  653. * hour value in the range between 0 and 23, which is zero-based.
  654. * <P>
  655. * The only difference between roll() and add() is that roll() does not change
  656. * the value of more significant fields when it reaches the minimum or maximum
  657. * of its range, whereas add() does.
  658. *
  659. * @param field The time field.
  660. * @param amount Indicates amount to roll.
  661. * @param status Output param set to success/failure code on exit. If any value
  662. * previously set in the time field is invalid, this will be set to
  663. * an error status.
  664. * @stable ICU 2.6.
  665. */
  666. virtual void roll(UCalendarDateFields field, int32_t amount, UErrorCode& status);
  667. #ifndef U_FORCE_HIDE_DEPRECATED_API
  668. /**
  669. * Return the difference between the given time and the time this
  670. * calendar object is set to. If this calendar is set
  671. * <em>before</em> the given time, the returned value will be
  672. * positive. If this calendar is set <em>after</em> the given
  673. * time, the returned value will be negative. The
  674. * <code>field</code> parameter specifies the units of the return
  675. * value. For example, if <code>fieldDifference(when,
  676. * Calendar::MONTH)</code> returns 3, then this calendar is set to
  677. * 3 months before <code>when</code>, and possibly some addition
  678. * time less than one month.
  679. *
  680. * <p>As a side effect of this call, this calendar is advanced
  681. * toward <code>when</code> by the given amount. That is, calling
  682. * this method has the side effect of calling <code>add(field,
  683. * n)</code>, where <code>n</code> is the return value.
  684. *
  685. * <p>Usage: To use this method, call it first with the largest
  686. * field of interest, then with progressively smaller fields. For
  687. * example:
  688. *
  689. * <pre>
  690. * int y = cal->fieldDifference(when, Calendar::YEAR, err);
  691. * int m = cal->fieldDifference(when, Calendar::MONTH, err);
  692. * int d = cal->fieldDifference(when, Calendar::DATE, err);</pre>
  693. *
  694. * computes the difference between <code>cal</code> and
  695. * <code>when</code> in years, months, and days.
  696. *
  697. * <p>Note: <code>fieldDifference()</code> is
  698. * <em>asymmetrical</em>. That is, in the following code:
  699. *
  700. * <pre>
  701. * cal->setTime(date1, err);
  702. * int m1 = cal->fieldDifference(date2, Calendar::MONTH, err);
  703. * int d1 = cal->fieldDifference(date2, Calendar::DATE, err);
  704. * cal->setTime(date2, err);
  705. * int m2 = cal->fieldDifference(date1, Calendar::MONTH, err);
  706. * int d2 = cal->fieldDifference(date1, Calendar::DATE, err);</pre>
  707. *
  708. * one might expect that <code>m1 == -m2 && d1 == -d2</code>.
  709. * However, this is not generally the case, because of
  710. * irregularities in the underlying calendar system (e.g., the
  711. * Gregorian calendar has a varying number of days per month).
  712. *
  713. * @param when the date to compare this calendar's time to
  714. * @param field the field in which to compute the result
  715. * @param status Output param set to success/failure code on exit. If any value
  716. * previously set in the time field is invalid, this will be set to
  717. * an error status.
  718. * @return the difference, either positive or negative, between
  719. * this calendar's time and <code>when</code>, in terms of
  720. * <code>field</code>.
  721. * @deprecated ICU 2.6. Use fieldDifference(UDate when, UCalendarDateFields field, UErrorCode& status).
  722. */
  723. virtual int32_t fieldDifference(UDate when, EDateFields field, UErrorCode& status);
  724. #endif // U_FORCE_HIDE_DEPRECATED_API
  725. /**
  726. * Return the difference between the given time and the time this
  727. * calendar object is set to. If this calendar is set
  728. * <em>before</em> the given time, the returned value will be
  729. * positive. If this calendar is set <em>after</em> the given
  730. * time, the returned value will be negative. The
  731. * <code>field</code> parameter specifies the units of the return
  732. * value. For example, if <code>fieldDifference(when,
  733. * Calendar::MONTH)</code> returns 3, then this calendar is set to
  734. * 3 months before <code>when</code>, and possibly some addition
  735. * time less than one month.
  736. *
  737. * <p>As a side effect of this call, this calendar is advanced
  738. * toward <code>when</code> by the given amount. That is, calling
  739. * this method has the side effect of calling <code>add(field,
  740. * n)</code>, where <code>n</code> is the return value.
  741. *
  742. * <p>Usage: To use this method, call it first with the largest
  743. * field of interest, then with progressively smaller fields. For
  744. * example:
  745. *
  746. * <pre>
  747. * int y = cal->fieldDifference(when, Calendar::YEAR, err);
  748. * int m = cal->fieldDifference(when, Calendar::MONTH, err);
  749. * int d = cal->fieldDifference(when, Calendar::DATE, err);</pre>
  750. *
  751. * computes the difference between <code>cal</code> and
  752. * <code>when</code> in years, months, and days.
  753. *
  754. * <p>Note: <code>fieldDifference()</code> is
  755. * <em>asymmetrical</em>. That is, in the following code:
  756. *
  757. * <pre>
  758. * cal->setTime(date1, err);
  759. * int m1 = cal->fieldDifference(date2, Calendar::MONTH, err);
  760. * int d1 = cal->fieldDifference(date2, Calendar::DATE, err);
  761. * cal->setTime(date2, err);
  762. * int m2 = cal->fieldDifference(date1, Calendar::MONTH, err);
  763. * int d2 = cal->fieldDifference(date1, Calendar::DATE, err);</pre>
  764. *
  765. * one might expect that <code>m1 == -m2 && d1 == -d2</code>.
  766. * However, this is not generally the case, because of
  767. * irregularities in the underlying calendar system (e.g., the
  768. * Gregorian calendar has a varying number of days per month).
  769. *
  770. * @param when the date to compare this calendar's time to
  771. * @param field the field in which to compute the result
  772. * @param status Output param set to success/failure code on exit. If any value
  773. * previously set in the time field is invalid, this will be set to
  774. * an error status.
  775. * @return the difference, either positive or negative, between
  776. * this calendar's time and <code>when</code>, in terms of
  777. * <code>field</code>.
  778. * @stable ICU 2.6.
  779. */
  780. virtual int32_t fieldDifference(UDate when, UCalendarDateFields field, UErrorCode& status);
  781. /**
  782. * Sets the calendar's time zone to be the one passed in. The Calendar takes ownership
  783. * of the TimeZone; the caller is no longer responsible for deleting it. If the
  784. * given time zone is NULL, this function has no effect.
  785. *
  786. * @param value The given time zone.
  787. * @stable ICU 2.0
  788. */
  789. void adoptTimeZone(TimeZone* value);
  790. /**
  791. * Sets the calendar's time zone to be the same as the one passed in. The TimeZone
  792. * passed in is _not_ adopted; the client is still responsible for deleting it.
  793. *
  794. * @param zone The given time zone.
  795. * @stable ICU 2.0
  796. */
  797. void setTimeZone(const TimeZone& zone);
  798. /**
  799. * Returns a reference to the time zone owned by this calendar. The returned reference
  800. * is only valid until clients make another call to adoptTimeZone or setTimeZone,
  801. * or this Calendar is destroyed.
  802. *
  803. * @return The time zone object associated with this calendar.
  804. * @stable ICU 2.0
  805. */
  806. const TimeZone& getTimeZone(void) const;
  807. /**
  808. * Returns the time zone owned by this calendar. The caller owns the returned object
  809. * and must delete it when done. After this call, the new time zone associated
  810. * with this Calendar is the default TimeZone as returned by TimeZone::createDefault().
  811. *
  812. * @return The time zone object which was associated with this calendar.
  813. * @stable ICU 2.0
  814. */
  815. TimeZone* orphanTimeZone(void);
  816. /**
  817. * Queries if the current date for this Calendar is in Daylight Savings Time.
  818. *
  819. * @param status Fill-in parameter which receives the status of this operation.
  820. * @return True if the current date for this Calendar is in Daylight Savings Time,
  821. * false, otherwise.
  822. * @stable ICU 2.0
  823. */
  824. virtual UBool inDaylightTime(UErrorCode& status) const = 0;
  825. /**
  826. * Specifies whether or not date/time interpretation is to be lenient. With lenient
  827. * interpretation, a date such as "February 942, 1996" will be treated as being
  828. * equivalent to the 941st day after February 1, 1996. With strict interpretation,
  829. * such dates will cause an error when computing time from the time field values
  830. * representing the dates.
  831. *
  832. * @param lenient True specifies date/time interpretation to be lenient.
  833. *
  834. * @see DateFormat#setLenient
  835. * @stable ICU 2.0
  836. */
  837. void setLenient(UBool lenient);
  838. /**
  839. * Tells whether date/time interpretation is to be lenient.
  840. *
  841. * @return True tells that date/time interpretation is to be lenient.
  842. * @stable ICU 2.0
  843. */
  844. UBool isLenient(void) const;
  845. /**
  846. * Sets the behavior for handling wall time repeating multiple times
  847. * at negative time zone offset transitions. For example, 1:30 AM on
  848. * November 6, 2011 in US Eastern time (America/New_York) occurs twice;
  849. * 1:30 AM EDT, then 1:30 AM EST one hour later. When <code>UCAL_WALLTIME_FIRST</code>
  850. * is used, the wall time 1:30AM in this example will be interpreted as 1:30 AM EDT
  851. * (first occurrence). When <code>UCAL_WALLTIME_LAST</code> is used, it will be
  852. * interpreted as 1:30 AM EST (last occurrence). The default value is
  853. * <code>UCAL_WALLTIME_LAST</code>.
  854. * <p>
  855. * <b>Note:</b>When <code>UCAL_WALLTIME_NEXT_VALID</code> is not a valid
  856. * option for this. When the argument is neither <code>UCAL_WALLTIME_FIRST</code>
  857. * nor <code>UCAL_WALLTIME_LAST</code>, this method has no effect and will keep
  858. * the current setting.
  859. *
  860. * @param option the behavior for handling repeating wall time, either
  861. * <code>UCAL_WALLTIME_FIRST</code> or <code>UCAL_WALLTIME_LAST</code>.
  862. * @see #getRepeatedWallTimeOption
  863. * @stable ICU 49
  864. */
  865. void setRepeatedWallTimeOption(UCalendarWallTimeOption option);
  866. /**
  867. * Gets the behavior for handling wall time repeating multiple times
  868. * at negative time zone offset transitions.
  869. *
  870. * @return the behavior for handling repeating wall time, either
  871. * <code>UCAL_WALLTIME_FIRST</code> or <code>UCAL_WALLTIME_LAST</code>.
  872. * @see #setRepeatedWallTimeOption
  873. * @stable ICU 49
  874. */
  875. UCalendarWallTimeOption getRepeatedWallTimeOption(void) const;
  876. /**
  877. * Sets the behavior for handling skipped wall time at positive time zone offset
  878. * transitions. For example, 2:30 AM on March 13, 2011 in US Eastern time (America/New_York)
  879. * does not exist because the wall time jump from 1:59 AM EST to 3:00 AM EDT. When
  880. * <code>UCAL_WALLTIME_FIRST</code> is used, 2:30 AM is interpreted as 30 minutes before 3:00 AM
  881. * EDT, therefore, it will be resolved as 1:30 AM EST. When <code>UCAL_WALLTIME_LAST</code>
  882. * is used, 2:30 AM is interpreted as 31 minutes after 1:59 AM EST, therefore, it will be
  883. * resolved as 3:30 AM EDT. When <code>UCAL_WALLTIME_NEXT_VALID</code> is used, 2:30 AM will
  884. * be resolved as next valid wall time, that is 3:00 AM EDT. The default value is
  885. * <code>UCAL_WALLTIME_LAST</code>.
  886. * <p>
  887. * <b>Note:</b>This option is effective only when this calendar is lenient.
  888. * When the calendar is strict, such non-existing wall time will cause an error.
  889. *
  890. * @param option the behavior for handling skipped wall time at positive time zone
  891. * offset transitions, one of <code>UCAL_WALLTIME_FIRST</code>, <code>UCAL_WALLTIME_LAST</code> and
  892. * <code>UCAL_WALLTIME_NEXT_VALID</code>.
  893. * @see #getSkippedWallTimeOption
  894. *
  895. * @stable ICU 49
  896. */
  897. void setSkippedWallTimeOption(UCalendarWallTimeOption option);
  898. /**
  899. * Gets the behavior for handling skipped wall time at positive time zone offset
  900. * transitions.
  901. *
  902. * @return the behavior for handling skipped wall time, one of
  903. * <code>UCAL_WALLTIME_FIRST</code>, <code>UCAL_WALLTIME_LAST</code>
  904. * and <code>UCAL_WALLTIME_NEXT_VALID</code>.
  905. * @see #setSkippedWallTimeOption
  906. * @stable ICU 49
  907. */
  908. UCalendarWallTimeOption getSkippedWallTimeOption(void) const;
  909. #ifndef U_HIDE_DEPRECATED_API
  910. /**
  911. * Sets what the first day of the week is; e.g., Sunday in US, Monday in France.
  912. *
  913. * @param value The given first day of the week.
  914. * @deprecated ICU 2.6. Use setFirstDayOfWeek(UCalendarDaysOfWeek value) instead.
  915. */
  916. void setFirstDayOfWeek(EDaysOfWeek value);
  917. #endif /* 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. * @stable ICU 2.6.
  923. */
  924. void setFirstDayOfWeek(UCalendarDaysOfWeek value);
  925. #ifndef U_HIDE_DEPRECATED_API
  926. /**
  927. * Gets what the first day of the week is; e.g., Sunday in US, Monday in France.
  928. *
  929. * @return The first day of the week.
  930. * @deprecated ICU 2.6 use the overload with error code
  931. */
  932. EDaysOfWeek getFirstDayOfWeek(void) const;
  933. #endif /* 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. * @param status error code
  938. * @return The first day of the week.
  939. * @stable ICU 2.6
  940. */
  941. UCalendarDaysOfWeek getFirstDayOfWeek(UErrorCode &status) const;
  942. /**
  943. * Sets what the minimal days required in the first week of the year are; For
  944. * example, if the first week is defined as one that contains the first day of the
  945. * first month of a year, call the method with value 1. If it must be a full week,
  946. * use value 7.
  947. *
  948. * @param value The given minimal days required in the first week of the year.
  949. * @stable ICU 2.0
  950. */
  951. void setMinimalDaysInFirstWeek(uint8_t value);
  952. /**
  953. * Gets what the minimal days required in the first week of the year are; e.g., if
  954. * the first week is defined as one that contains the first day of the first month
  955. * of a year, getMinimalDaysInFirstWeek returns 1. If the minimal days required must
  956. * be a full week, getMinimalDaysInFirstWeek returns 7.
  957. *
  958. * @return The minimal days required in the first week of the year.
  959. * @stable ICU 2.0
  960. */
  961. uint8_t getMinimalDaysInFirstWeek(void) const;
  962. #ifndef U_FORCE_HIDE_DEPRECATED_API
  963. /**
  964. * Gets the minimum value for the given time field. e.g., for Gregorian
  965. * DAY_OF_MONTH, 1.
  966. *
  967. * @param field The given time field.
  968. * @return The minimum value for the given time field.
  969. * @deprecated ICU 2.6. Use getMinimum(UCalendarDateFields field) instead.
  970. */
  971. virtual int32_t getMinimum(EDateFields field) const;
  972. #endif // U_FORCE_HIDE_DEPRECATED_API
  973. /**
  974. * Gets the minimum value for the given time field. e.g., for Gregorian
  975. * DAY_OF_MONTH, 1.
  976. *
  977. * @param field The given time field.
  978. * @return The minimum value for the given time field.
  979. * @stable ICU 2.6.
  980. */
  981. virtual int32_t getMinimum(UCalendarDateFields field) const;
  982. #ifndef U_FORCE_HIDE_DEPRECATED_API
  983. /**
  984. * Gets the maximum value for the given time field. e.g. for Gregorian DAY_OF_MONTH,
  985. * 31.
  986. *
  987. * @param field The given time field.
  988. * @return The maximum value for the given time field.
  989. * @deprecated ICU 2.6. Use getMaximum(UCalendarDateFields field) instead.
  990. */
  991. virtual int32_t getMaximum(EDateFields field) const;
  992. #endif // U_FORCE_HIDE_DEPRECATED_API
  993. /**
  994. * Gets the maximum value for the given time field. e.g. for Gregorian DAY_OF_MONTH,
  995. * 31.
  996. *
  997. * @param field The given time field.
  998. * @return The maximum value for the given time field.
  999. * @stable ICU 2.6.
  1000. */
  1001. virtual int32_t getMaximum(UCalendarDateFields field) const;
  1002. #ifndef U_FORCE_HIDE_DEPRECATED_API
  1003. /**
  1004. * Gets the highest minimum value for the given field if varies. Otherwise same as
  1005. * getMinimum(). For Gregorian, no difference.
  1006. *
  1007. * @param field The given time field.
  1008. * @return The highest minimum value for the given time field.
  1009. * @deprecated ICU 2.6. Use getGreatestMinimum(UCalendarDateFields field) instead.
  1010. */
  1011. virtual int32_t getGreatestMinimum(EDateFields field) const;
  1012. #endif // U_FORCE_HIDE_DEPRECATED_API
  1013. /**
  1014. * Gets the highest minimum value for the given field if varies. Otherwise same as
  1015. * getMinimum(). For Gregorian, no difference.
  1016. *
  1017. * @param field The given time field.
  1018. * @return The highest minimum value for the given time field.
  1019. * @stable ICU 2.6.
  1020. */
  1021. virtual int32_t getGreatestMinimum(UCalendarDateFields field) const;
  1022. #ifndef U_FORCE_HIDE_DEPRECATED_API
  1023. /**
  1024. * Gets the lowest maximum value for the given field if varies. Otherwise same as
  1025. * getMaximum(). e.g., for Gregorian DAY_OF_MONTH, 28.
  1026. *
  1027. * @param field The given time field.
  1028. * @return The lowest maximum value for the given time field.
  1029. * @deprecated ICU 2.6. Use getLeastMaximum(UCalendarDateFields field) instead.
  1030. */
  1031. virtual int32_t getLeastMaximum(EDateFields field) const;
  1032. #endif // U_FORCE_HIDE_DEPRECATED_API
  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 `Calendar::validateField()`.
  1604. * @internal
  1605. */
  1606. virtual void validateField(UCalendarDateFields field, UErrorCode &status);
  1607. #ifndef U_HIDE_INTERNAL_API
  1608. /**
  1609. * Compute the Julian day from fields. Will determine whether to use
  1610. * the JULIAN_DAY field directly, or other fields.
  1611. * @return the julian day
  1612. * @internal
  1613. */
  1614. int32_t computeJulianDay();
  1615. /**
  1616. * Compute the milliseconds in the day from the fields. This is a
  1617. * value from 0 to 23:59:59.999 inclusive, unless fields are out of
  1618. * range, in which case it can be an arbitrary value. This value
  1619. * reflects local zone wall time.
  1620. * @internal
  1621. */
  1622. double computeMillisInDay();
  1623. /**
  1624. * This method can assume EXTENDED_YEAR has been set.
  1625. * @param millis milliseconds of the date fields
  1626. * @param millisInDay milliseconds of the time fields; may be out
  1627. * or range.
  1628. * @param ec Output param set to failure code on function return
  1629. * when this function fails.
  1630. * @internal
  1631. */
  1632. int32_t computeZoneOffset(double millis, double millisInDay, UErrorCode &ec);
  1633. /**
  1634. * Determine the best stamp in a range.
  1635. * @param start first enum to look at
  1636. * @param end last enum to look at
  1637. * @param bestSoFar stamp prior to function call
  1638. * @return the stamp value of the best stamp
  1639. * @internal
  1640. */
  1641. int32_t newestStamp(UCalendarDateFields start, UCalendarDateFields end, int32_t bestSoFar) const;
  1642. /**
  1643. * Values for field resolution tables
  1644. * @see #resolveFields
  1645. * @internal
  1646. */
  1647. enum {
  1648. /** Marker for end of resolve set (row or group). */
  1649. kResolveSTOP = -1,
  1650. /** 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. */
  1651. kResolveRemap = 32
  1652. };
  1653. /**
  1654. * Precedence table for Dates
  1655. * @see #resolveFields
  1656. * @internal
  1657. */
  1658. static const UFieldResolutionTable kDatePrecedence[];
  1659. /**
  1660. * Precedence table for Year
  1661. * @see #resolveFields
  1662. * @internal
  1663. */
  1664. static const UFieldResolutionTable kYearPrecedence[];
  1665. /**
  1666. * Precedence table for Day of Week
  1667. * @see #resolveFields
  1668. * @internal
  1669. */
  1670. static const UFieldResolutionTable kDOWPrecedence[];
  1671. /**
  1672. * Given a precedence table, return the newest field combination in
  1673. * the table, or UCAL_FIELD_COUNT if none is found.
  1674. *
  1675. * <p>The precedence table is a 3-dimensional array of integers. It
  1676. * may be thought of as an array of groups. Each group is an array of
  1677. * lines. Each line is an array of field numbers. Within a line, if
  1678. * all fields are set, then the time stamp of the line is taken to be
  1679. * the stamp of the most recently set field. If any field of a line is
  1680. * unset, then the line fails to match. Within a group, the line with
  1681. * the newest time stamp is selected. The first field of the line is
  1682. * returned to indicate which line matched.
  1683. *
  1684. * <p>In some cases, it may be desirable to map a line to field that
  1685. * whose stamp is NOT examined. For example, if the best field is
  1686. * DAY_OF_WEEK then the DAY_OF_WEEK_IN_MONTH algorithm may be used. In
  1687. * order to do this, insert the value <code>kResolveRemap | F</code> at
  1688. * the start of the line, where <code>F</code> is the desired return
  1689. * field value. This field will NOT be examined; it only determines
  1690. * the return value if the other fields in the line are the newest.
  1691. *
  1692. * <p>If all lines of a group contain at least one unset field, then no
  1693. * line will match, and the group as a whole will fail to match. In
  1694. * that case, the next group will be processed. If all groups fail to
  1695. * match, then UCAL_FIELD_COUNT is returned.
  1696. * @internal
  1697. */
  1698. UCalendarDateFields resolveFields(const UFieldResolutionTable *precedenceTable);
  1699. #endif /* U_HIDE_INTERNAL_API */
  1700. /**
  1701. * @internal
  1702. */
  1703. virtual const UFieldResolutionTable* getFieldResolutionTable() const;
  1704. #ifndef U_HIDE_INTERNAL_API
  1705. /**
  1706. * Return the field that is newer, either defaultField, or
  1707. * alternateField. If neither is newer or neither is set, return defaultField.
  1708. * @internal
  1709. */
  1710. UCalendarDateFields newerField(UCalendarDateFields defaultField, UCalendarDateFields alternateField) const;
  1711. #endif /* U_HIDE_INTERNAL_API */
  1712. private:
  1713. /**
  1714. * Helper function for calculating limits by trial and error
  1715. * @param field The field being investigated
  1716. * @param startValue starting (least max) value of field
  1717. * @param endValue ending (greatest max) value of field
  1718. * @param status return type
  1719. * @internal
  1720. */
  1721. int32_t getActualHelper(UCalendarDateFields field, int32_t startValue, int32_t endValue, UErrorCode &status) const;
  1722. protected:
  1723. /**
  1724. * The flag which indicates if the current time is set in the calendar.
  1725. * @stable ICU 2.0
  1726. */
  1727. UBool fIsTimeSet;
  1728. /**
  1729. * True if the fields are in sync with the currently set time of this Calendar.
  1730. * If false, then the next attempt to get the value of a field will
  1731. * force a recomputation of all fields from the current value of the time
  1732. * field.
  1733. * <P>
  1734. * This should really be named areFieldsInSync, but the old name is retained
  1735. * for backward compatibility.
  1736. * @stable ICU 2.0
  1737. */
  1738. UBool fAreFieldsSet;
  1739. /**
  1740. * True if all of the fields have been set. This is initially false, and set to
  1741. * true by computeFields().
  1742. * @stable ICU 2.0
  1743. */
  1744. UBool fAreAllFieldsSet;
  1745. /**
  1746. * True if all fields have been virtually set, but have not yet been
  1747. * computed. This occurs only in setTimeInMillis(). A calendar set
  1748. * to this state will compute all fields from the time if it becomes
  1749. * necessary, but otherwise will delay such computation.
  1750. * @stable ICU 3.0
  1751. */
  1752. UBool fAreFieldsVirtuallySet;
  1753. /**
  1754. * Get the current time without recomputing.
  1755. *
  1756. * @return the current time without recomputing.
  1757. * @stable ICU 2.0
  1758. */
  1759. UDate internalGetTime(void) const { return fTime; }
  1760. /**
  1761. * Set the current time without affecting flags or fields.
  1762. *
  1763. * @param time The time to be set
  1764. * @return the current time without recomputing.
  1765. * @stable ICU 2.0
  1766. */
  1767. void internalSetTime(UDate time) { fTime = time; }
  1768. /**
  1769. * The time fields containing values into which the millis is computed.
  1770. * @stable ICU 2.0
  1771. */
  1772. int32_t fFields[UCAL_FIELD_COUNT];
  1773. #ifndef U_FORCE_HIDE_DEPRECATED_API
  1774. /**
  1775. * The flags which tell if a specified time field for the calendar is set.
  1776. * @deprecated ICU 2.8 use (fStamp[n]!=kUnset)
  1777. */
  1778. UBool fIsSet[UCAL_FIELD_COUNT];
  1779. #endif // U_FORCE_HIDE_DEPRECATED_API
  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 repeated 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. */
  2123. void validateFields(UErrorCode &status);
  2124. /**
  2125. * Validate a single field of this calendar given its minimum and
  2126. * maximum allowed value. If the field is out of range,
  2127. * <code>U_ILLEGAL_ARGUMENT_ERROR</code> will be set. Subclasses may
  2128. * use this method in their implementation of {@link
  2129. * #validateField(int, int&)}.
  2130. */
  2131. void validateField(UCalendarDateFields field, int32_t min, int32_t max, UErrorCode& status);
  2132. protected:
  2133. #ifndef U_HIDE_INTERNAL_API
  2134. /**
  2135. * Convert a quasi Julian date to the day of the week. The Julian date used here is
  2136. * not a true Julian date, since it is measured from midnight, not noon. Return
  2137. * value is one-based.
  2138. *
  2139. * @param julian The given Julian date number.
  2140. * @return Day number from 1..7 (SUN..SAT).
  2141. * @internal
  2142. */
  2143. static uint8_t julianDayToDayOfWeek(double julian);
  2144. #endif /* U_HIDE_INTERNAL_API */
  2145. private:
  2146. char validLocale[ULOC_FULLNAME_CAPACITY];
  2147. char actualLocale[ULOC_FULLNAME_CAPACITY];
  2148. public:
  2149. #if !UCONFIG_NO_SERVICE
  2150. /**
  2151. * INTERNAL FOR 2.6 -- Registration.
  2152. */
  2153. #ifndef U_HIDE_INTERNAL_API
  2154. /**
  2155. * Return a StringEnumeration over the locales available at the time of the call,
  2156. * including registered locales.
  2157. * @return a StringEnumeration over the locales available at the time of the call
  2158. * @internal
  2159. */
  2160. static StringEnumeration* getAvailableLocales(void);
  2161. /**
  2162. * Register a new Calendar factory. The factory will be adopted.
  2163. * INTERNAL in 2.6
  2164. *
  2165. * Because ICU may choose to cache Calendars internally, this must
  2166. * be called at application startup, prior to any calls to
  2167. * Calendar::createInstance to avoid undefined behavior.
  2168. *
  2169. * @param toAdopt the factory instance to be adopted
  2170. * @param status the in/out status code, no special meanings are assigned
  2171. * @return a registry key that can be used to unregister this factory
  2172. * @internal
  2173. */
  2174. static URegistryKey registerFactory(ICUServiceFactory* toAdopt, UErrorCode& status);
  2175. /**
  2176. * Unregister a previously-registered CalendarFactory using the key returned from the
  2177. * register call. Key becomes invalid after a successful call and should not be used again.
  2178. * The CalendarFactory corresponding to the key will be deleted.
  2179. * INTERNAL in 2.6
  2180. *
  2181. * Because ICU may choose to cache Calendars internally, this should
  2182. * be called during application shutdown, after all calls to
  2183. * Calendar::createInstance to avoid undefined behavior.
  2184. *
  2185. * @param key the registry key returned by a previous call to registerFactory
  2186. * @param status the in/out status code, no special meanings are assigned
  2187. * @return TRUE if the factory for the key was successfully unregistered
  2188. * @internal
  2189. */
  2190. static UBool unregister(URegistryKey key, UErrorCode& status);
  2191. #endif /* U_HIDE_INTERNAL_API */
  2192. /**
  2193. * Multiple Calendar Implementation
  2194. * @internal
  2195. */
  2196. friend class CalendarFactory;
  2197. /**
  2198. * Multiple Calendar Implementation
  2199. * @internal
  2200. */
  2201. friend class CalendarService;
  2202. /**
  2203. * Multiple Calendar Implementation
  2204. * @internal
  2205. */
  2206. friend class DefaultCalendarFactory;
  2207. #endif /* !UCONFIG_NO_SERVICE */
  2208. /**
  2209. * @return TRUE if this calendar has a default century (i.e. 03 -> 2003)
  2210. * @internal
  2211. */
  2212. virtual UBool haveDefaultCentury() const = 0;
  2213. /**
  2214. * @return the start of the default century, as a UDate
  2215. * @internal
  2216. */
  2217. virtual UDate defaultCenturyStart() const = 0;
  2218. /**
  2219. * @return the beginning year of the default century, as a year
  2220. * @internal
  2221. */
  2222. virtual int32_t defaultCenturyStartYear() const = 0;
  2223. /** Get the locale for this calendar object. You can choose between valid and actual locale.
  2224. * @param type type of the locale we're looking for (valid or actual)
  2225. * @param status error code for the operation
  2226. * @return the locale
  2227. * @stable ICU 2.8
  2228. */
  2229. Locale getLocale(ULocDataLocaleType type, UErrorCode &status) const;
  2230. /**
  2231. * @return The related Gregorian year; will be obtained by modifying the value
  2232. * obtained by get from UCAL_EXTENDED_YEAR field
  2233. * @internal
  2234. */
  2235. virtual int32_t getRelatedYear(UErrorCode &status) const;
  2236. /**
  2237. * @param year The related Gregorian year to set; will be modified as necessary then
  2238. * set in UCAL_EXTENDED_YEAR field
  2239. * @internal
  2240. */
  2241. virtual void setRelatedYear(int32_t year);
  2242. #ifndef U_HIDE_INTERNAL_API
  2243. /** Get the locale for this calendar object. You can choose between valid and actual locale.
  2244. * @param type type of the locale we're looking for (valid or actual)
  2245. * @param status error code for the operation
  2246. * @return the locale
  2247. * @internal
  2248. */
  2249. const char* getLocaleID(ULocDataLocaleType type, UErrorCode &status) const;
  2250. #endif /* U_HIDE_INTERNAL_API */
  2251. private:
  2252. /**
  2253. * Cast TimeZone used by this object to BasicTimeZone, or NULL if the TimeZone
  2254. * is not an instance of BasicTimeZone.
  2255. */
  2256. BasicTimeZone* getBasicTimeZone() const;
  2257. /**
  2258. * Find the previous zone transition near the given time.
  2259. * @param base The base time, inclusive
  2260. * @param transitionTime Receives the result time
  2261. * @param status The error status
  2262. * @return TRUE if a transition is found.
  2263. */
  2264. UBool getImmediatePreviousZoneTransition(UDate base, UDate *transitionTime, UErrorCode& status) const;
  2265. public:
  2266. #ifndef U_HIDE_INTERNAL_API
  2267. /**
  2268. * Creates a new Calendar from a Locale for the cache.
  2269. * This method does not set the time or timezone in returned calendar.
  2270. * @param locale the locale.
  2271. * @param status any error returned here.
  2272. * @return the new Calendar object with no time or timezone set.
  2273. * @internal For ICU use only.
  2274. */
  2275. static Calendar * U_EXPORT2 makeInstance(
  2276. const Locale &locale, UErrorCode &status);
  2277. /**
  2278. * Get the calendar type for given locale.
  2279. * @param locale the locale
  2280. * @param typeBuffer calendar type returned here
  2281. * @param typeBufferSize The size of typeBuffer in bytes. If the type
  2282. * can't fit in the buffer, this method sets status to
  2283. * U_BUFFER_OVERFLOW_ERROR
  2284. * @param status error, if any, returned here.
  2285. * @internal For ICU use only.
  2286. */
  2287. static void U_EXPORT2 getCalendarTypeFromLocale(
  2288. const Locale &locale,
  2289. char *typeBuffer,
  2290. int32_t typeBufferSize,
  2291. UErrorCode &status);
  2292. #endif /* U_HIDE_INTERNAL_API */
  2293. };
  2294. // -------------------------------------
  2295. inline Calendar*
  2296. Calendar::createInstance(TimeZone* zone, UErrorCode& errorCode)
  2297. {
  2298. // since the Locale isn't specified, use the default locale
  2299. return createInstance(zone, Locale::getDefault(), errorCode);
  2300. }
  2301. // -------------------------------------
  2302. inline void
  2303. Calendar::roll(UCalendarDateFields field, UBool up, UErrorCode& status)
  2304. {
  2305. roll(field, (int32_t)(up ? +1 : -1), status);
  2306. }
  2307. #ifndef U_HIDE_DEPRECATED_API
  2308. inline void
  2309. Calendar::roll(EDateFields field, UBool up, UErrorCode& status)
  2310. {
  2311. roll((UCalendarDateFields) field, up, status);
  2312. }
  2313. #endif /* U_HIDE_DEPRECATED_API */
  2314. // -------------------------------------
  2315. /**
  2316. * Fast method for subclasses. The caller must maintain fUserSetDSTOffset and
  2317. * fUserSetZoneOffset, as well as the isSet[] array.
  2318. */
  2319. inline void
  2320. Calendar::internalSet(UCalendarDateFields field, int32_t value)
  2321. {
  2322. fFields[field] = value;
  2323. fStamp[field] = kInternallySet;
  2324. fIsSet[field] = TRUE; // Remove later
  2325. }
  2326. #ifndef U_HIDE_INTERNAL_API
  2327. inline int32_t Calendar::weekNumber(int32_t dayOfPeriod, int32_t dayOfWeek)
  2328. {
  2329. return weekNumber(dayOfPeriod, dayOfPeriod, dayOfWeek);
  2330. }
  2331. #endif /* U_HIDE_INTERNAL_API */
  2332. U_NAMESPACE_END
  2333. #endif /* #if !UCONFIG_NO_FORMATTING */
  2334. #endif /* U_SHOW_CPLUSPLUS_API */
  2335. #endif // _CALENDAR