calendar.h 105 KB

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