gregocal.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. * Copyright (C) 1997-2013, International Business Machines Corporation and others.
  5. * All Rights Reserved.
  6. ********************************************************************************
  7. *
  8. * File GREGOCAL.H
  9. *
  10. * Modification History:
  11. *
  12. * Date Name Description
  13. * 04/22/97 aliu Overhauled header.
  14. * 07/28/98 stephen Sync with JDK 1.2
  15. * 09/04/98 stephen Re-sync with JDK 8/31 putback
  16. * 09/14/98 stephen Changed type of kOneDay, kOneWeek to double.
  17. * Fixed bug in roll()
  18. * 10/15/99 aliu Fixed j31, incorrect WEEK_OF_YEAR computation.
  19. * Added documentation of WEEK_OF_YEAR computation.
  20. * 10/15/99 aliu Fixed j32, cannot set date to Feb 29 2000 AD.
  21. * {JDK bug 4210209 4209272}
  22. * 11/07/2003 srl Update, clean up documentation.
  23. ********************************************************************************
  24. */
  25. #ifndef GREGOCAL_H
  26. #define GREGOCAL_H
  27. #include "unicode/utypes.h"
  28. #if U_SHOW_CPLUSPLUS_API
  29. #if !UCONFIG_NO_FORMATTING
  30. #include "unicode/calendar.h"
  31. /**
  32. * \file
  33. * \brief C++ API: Concrete class which provides the standard calendar.
  34. */
  35. U_NAMESPACE_BEGIN
  36. /**
  37. * Concrete class which provides the standard calendar used by most of the world.
  38. * <P>
  39. * The standard (Gregorian) calendar has 2 eras, BC and AD.
  40. * <P>
  41. * This implementation handles a single discontinuity, which corresponds by default to
  42. * the date the Gregorian calendar was originally instituted (October 15, 1582). Not all
  43. * countries adopted the Gregorian calendar then, so this cutover date may be changed by
  44. * the caller.
  45. * <P>
  46. * Prior to the institution of the Gregorian Calendar, New Year's Day was March 25. To
  47. * avoid confusion, this Calendar always uses January 1. A manual adjustment may be made
  48. * if desired for dates that are prior to the Gregorian changeover and which fall
  49. * between January 1 and March 24.
  50. *
  51. * <p>Values calculated for the <code>WEEK_OF_YEAR</code> field range from 1 to
  52. * 53. Week 1 for a year is the first week that contains at least
  53. * <code>getMinimalDaysInFirstWeek()</code> days from that year. It thus
  54. * depends on the values of <code>getMinimalDaysInFirstWeek()</code>,
  55. * <code>getFirstDayOfWeek()</code>, and the day of the week of January 1.
  56. * Weeks between week 1 of one year and week 1 of the following year are
  57. * numbered sequentially from 2 to 52 or 53 (as needed).
  58. *
  59. * <p>For example, January 1, 1998 was a Thursday. If
  60. * <code>getFirstDayOfWeek()</code> is <code>MONDAY</code> and
  61. * <code>getMinimalDaysInFirstWeek()</code> is 4 (these are the values
  62. * reflecting ISO 8601 and many national standards), then week 1 of 1998 starts
  63. * on December 29, 1997, and ends on January 4, 1998. If, however,
  64. * <code>getFirstDayOfWeek()</code> is <code>SUNDAY</code>, then week 1 of 1998
  65. * starts on January 4, 1998, and ends on January 10, 1998; the first three days
  66. * of 1998 then are part of week 53 of 1997.
  67. *
  68. * <p>Example for using GregorianCalendar:
  69. * <pre>
  70. * \code
  71. * // get the supported ids for GMT-08:00 (Pacific Standard Time)
  72. * UErrorCode success = U_ZERO_ERROR;
  73. * const StringEnumeration *ids = TimeZone::createEnumeration(-8 * 60 * 60 * 1000, success);
  74. * // if no ids were returned, something is wrong. get out.
  75. * if (U_FAILURE(success)) {
  76. * return;
  77. * }
  78. *
  79. * // begin output
  80. * cout << "Current Time" << endl;
  81. *
  82. * // create a Pacific Standard Time time zone
  83. * SimpleTimeZone* pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids->unext(nullptr, success)));
  84. *
  85. * // set up rules for daylight savings time
  86. * pdt->setStartRule(UCAL_MARCH, 1, UCAL_SUNDAY, 2 * 60 * 60 * 1000);
  87. * pdt->setEndRule(UCAL_NOVEMBER, 2, UCAL_SUNDAY, 2 * 60 * 60 * 1000);
  88. *
  89. * // create a GregorianCalendar with the Pacific Daylight time zone
  90. * // and the current date and time
  91. * Calendar* calendar = new GregorianCalendar( pdt, success );
  92. *
  93. * // print out a bunch of interesting things
  94. * cout << "ERA: " << calendar->get( UCAL_ERA, success ) << endl;
  95. * cout << "YEAR: " << calendar->get( UCAL_YEAR, success ) << endl;
  96. * cout << "MONTH: " << calendar->get( UCAL_MONTH, success ) << endl;
  97. * cout << "WEEK_OF_YEAR: " << calendar->get( UCAL_WEEK_OF_YEAR, success ) << endl;
  98. * cout << "WEEK_OF_MONTH: " << calendar->get( UCAL_WEEK_OF_MONTH, success ) << endl;
  99. * cout << "DATE: " << calendar->get( UCAL_DATE, success ) << endl;
  100. * cout << "DAY_OF_MONTH: " << calendar->get( UCAL_DAY_OF_MONTH, success ) << endl;
  101. * cout << "DAY_OF_YEAR: " << calendar->get( UCAL_DAY_OF_YEAR, success ) << endl;
  102. * cout << "DAY_OF_WEEK: " << calendar->get( UCAL_DAY_OF_WEEK, success ) << endl;
  103. * cout << "DAY_OF_WEEK_IN_MONTH: " << calendar->get( UCAL_DAY_OF_WEEK_IN_MONTH, success ) << endl;
  104. * cout << "AM_PM: " << calendar->get( UCAL_AM_PM, success ) << endl;
  105. * cout << "HOUR: " << calendar->get( UCAL_HOUR, success ) << endl;
  106. * cout << "HOUR_OF_DAY: " << calendar->get( UCAL_HOUR_OF_DAY, success ) << endl;
  107. * cout << "MINUTE: " << calendar->get( UCAL_MINUTE, success ) << endl;
  108. * cout << "SECOND: " << calendar->get( UCAL_SECOND, success ) << endl;
  109. * cout << "MILLISECOND: " << calendar->get( UCAL_MILLISECOND, success ) << endl;
  110. * cout << "ZONE_OFFSET: " << (calendar->get( UCAL_ZONE_OFFSET, success )/(60*60*1000)) << endl;
  111. * cout << "DST_OFFSET: " << (calendar->get( UCAL_DST_OFFSET, success )/(60*60*1000)) << endl;
  112. *
  113. * cout << "Current Time, with hour reset to 3" << endl;
  114. * calendar->clear(UCAL_HOUR_OF_DAY); // so doesn't override
  115. * calendar->set(UCAL_HOUR, 3);
  116. * cout << "ERA: " << calendar->get( UCAL_ERA, success ) << endl;
  117. * cout << "YEAR: " << calendar->get( UCAL_YEAR, success ) << endl;
  118. * cout << "MONTH: " << calendar->get( UCAL_MONTH, success ) << endl;
  119. * cout << "WEEK_OF_YEAR: " << calendar->get( UCAL_WEEK_OF_YEAR, success ) << endl;
  120. * cout << "WEEK_OF_MONTH: " << calendar->get( UCAL_WEEK_OF_MONTH, success ) << endl;
  121. * cout << "DATE: " << calendar->get( UCAL_DATE, success ) << endl;
  122. * cout << "DAY_OF_MONTH: " << calendar->get( UCAL_DAY_OF_MONTH, success ) << endl;
  123. * cout << "DAY_OF_YEAR: " << calendar->get( UCAL_DAY_OF_YEAR, success ) << endl;
  124. * cout << "DAY_OF_WEEK: " << calendar->get( UCAL_DAY_OF_WEEK, success ) << endl;
  125. * cout << "DAY_OF_WEEK_IN_MONTH: " << calendar->get( UCAL_DAY_OF_WEEK_IN_MONTH, success ) << endl;
  126. * cout << "AM_PM: " << calendar->get( UCAL_AM_PM, success ) << endl;
  127. * cout << "HOUR: " << calendar->get( UCAL_HOUR, success ) << endl;
  128. * cout << "HOUR_OF_DAY: " << calendar->get( UCAL_HOUR_OF_DAY, success ) << endl;
  129. * cout << "MINUTE: " << calendar->get( UCAL_MINUTE, success ) << endl;
  130. * cout << "SECOND: " << calendar->get( UCAL_SECOND, success ) << endl;
  131. * cout << "MILLISECOND: " << calendar->get( UCAL_MILLISECOND, success ) << endl;
  132. * cout << "ZONE_OFFSET: " << (calendar->get( UCAL_ZONE_OFFSET, success )/(60*60*1000)) << endl; // in hours
  133. * cout << "DST_OFFSET: " << (calendar->get( UCAL_DST_OFFSET, success )/(60*60*1000)) << endl; // in hours
  134. *
  135. * if (U_FAILURE(success)) {
  136. * cout << "An error occurred. success=" << u_errorName(success) << endl;
  137. * }
  138. *
  139. * delete ids;
  140. * delete calendar; // also deletes pdt
  141. * \endcode
  142. * </pre>
  143. * @stable ICU 2.0
  144. */
  145. class U_I18N_API GregorianCalendar: public Calendar {
  146. public:
  147. /**
  148. * Useful constants for GregorianCalendar and TimeZone.
  149. * @stable ICU 2.0
  150. */
  151. enum EEras {
  152. BC,
  153. AD
  154. };
  155. /**
  156. * Constructs a default GregorianCalendar using the current time in the default time
  157. * zone with the default locale.
  158. *
  159. * @param success Indicates the status of GregorianCalendar object construction.
  160. * Returns U_ZERO_ERROR if constructed successfully.
  161. * @stable ICU 2.0
  162. */
  163. GregorianCalendar(UErrorCode& success);
  164. /**
  165. * Constructs a GregorianCalendar based on the current time in the given time zone
  166. * with the default locale. Clients are no longer responsible for deleting the given
  167. * time zone object after it's adopted.
  168. *
  169. * @param zoneToAdopt The given timezone.
  170. * @param success Indicates the status of GregorianCalendar object construction.
  171. * Returns U_ZERO_ERROR if constructed successfully.
  172. * @stable ICU 2.0
  173. */
  174. GregorianCalendar(TimeZone* zoneToAdopt, UErrorCode& success);
  175. /**
  176. * Constructs a GregorianCalendar based on the current time in the given time zone
  177. * with the default locale.
  178. *
  179. * @param zone The given timezone.
  180. * @param success Indicates the status of GregorianCalendar object construction.
  181. * Returns U_ZERO_ERROR if constructed successfully.
  182. * @stable ICU 2.0
  183. */
  184. GregorianCalendar(const TimeZone& zone, UErrorCode& success);
  185. /**
  186. * Constructs a GregorianCalendar based on the current time in the default time zone
  187. * with the given locale.
  188. *
  189. * @param aLocale The given locale.
  190. * @param success Indicates the status of GregorianCalendar object construction.
  191. * Returns U_ZERO_ERROR if constructed successfully.
  192. * @stable ICU 2.0
  193. */
  194. GregorianCalendar(const Locale& aLocale, UErrorCode& success);
  195. /**
  196. * Constructs a GregorianCalendar based on the current time in the given time zone
  197. * with the given locale. Clients are no longer responsible for deleting the given
  198. * time zone object after it's adopted.
  199. *
  200. * @param zoneToAdopt The given timezone.
  201. * @param aLocale The given locale.
  202. * @param success Indicates the status of GregorianCalendar object construction.
  203. * Returns U_ZERO_ERROR if constructed successfully.
  204. * @stable ICU 2.0
  205. */
  206. GregorianCalendar(TimeZone* zoneToAdopt, const Locale& aLocale, UErrorCode& success);
  207. /**
  208. * Constructs a GregorianCalendar based on the current time in the given time zone
  209. * with the given locale.
  210. *
  211. * @param zone The given timezone.
  212. * @param aLocale The given locale.
  213. * @param success Indicates the status of GregorianCalendar object construction.
  214. * Returns U_ZERO_ERROR if constructed successfully.
  215. * @stable ICU 2.0
  216. */
  217. GregorianCalendar(const TimeZone& zone, const Locale& aLocale, UErrorCode& success);
  218. /**
  219. * Constructs a GregorianCalendar with the given AD date set in the default time
  220. * zone with the default locale.
  221. *
  222. * @param year The value used to set the YEAR time field in the calendar.
  223. * @param month The value used to set the MONTH time field in the calendar. Month
  224. * value is 0-based. e.g., 0 for January.
  225. * @param date The value used to set the DATE time field in the calendar.
  226. * @param success Indicates the status of GregorianCalendar object construction.
  227. * Returns U_ZERO_ERROR if constructed successfully.
  228. * @stable ICU 2.0
  229. */
  230. GregorianCalendar(int32_t year, int32_t month, int32_t date, UErrorCode& success);
  231. /**
  232. * Constructs a GregorianCalendar with the given AD date and time set for the
  233. * default time zone with the default locale.
  234. *
  235. * @param year The value used to set the YEAR time field in the calendar.
  236. * @param month The value used to set the MONTH time field in the calendar. Month
  237. * value is 0-based. e.g., 0 for January.
  238. * @param date The value used to set the DATE time field in the calendar.
  239. * @param hour The value used to set the HOUR_OF_DAY time field in the calendar.
  240. * @param minute The value used to set the MINUTE time field in the calendar.
  241. * @param success Indicates the status of GregorianCalendar object construction.
  242. * Returns U_ZERO_ERROR if constructed successfully.
  243. * @stable ICU 2.0
  244. */
  245. GregorianCalendar(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, UErrorCode& success);
  246. /**
  247. * Constructs a GregorianCalendar with the given AD date and time set for the
  248. * default time zone with the default locale.
  249. *
  250. * @param year The value used to set the YEAR time field in the calendar.
  251. * @param month The value used to set the MONTH time field in the calendar. Month
  252. * value is 0-based. e.g., 0 for January.
  253. * @param date The value used to set the DATE time field in the calendar.
  254. * @param hour The value used to set the HOUR_OF_DAY time field in the calendar.
  255. * @param minute The value used to set the MINUTE time field in the calendar.
  256. * @param second The value used to set the SECOND time field in the calendar.
  257. * @param success Indicates the status of GregorianCalendar object construction.
  258. * Returns U_ZERO_ERROR if constructed successfully.
  259. * @stable ICU 2.0
  260. */
  261. GregorianCalendar(int32_t year, int32_t month, int32_t date, int32_t hour, int32_t minute, int32_t second, UErrorCode& success);
  262. /**
  263. * Destructor
  264. * @stable ICU 2.0
  265. */
  266. virtual ~GregorianCalendar();
  267. /**
  268. * Copy constructor
  269. * @param source the object to be copied.
  270. * @stable ICU 2.0
  271. */
  272. GregorianCalendar(const GregorianCalendar& source);
  273. /**
  274. * Default assignment operator
  275. * @param right the object to be copied.
  276. * @stable ICU 2.0
  277. */
  278. GregorianCalendar& operator=(const GregorianCalendar& right);
  279. /**
  280. * Create and return a polymorphic copy of this calendar.
  281. * @return return a polymorphic copy of this calendar.
  282. * @stable ICU 2.0
  283. */
  284. virtual GregorianCalendar* clone() const override;
  285. /**
  286. * Sets the GregorianCalendar change date. This is the point when the switch from
  287. * Julian dates to Gregorian dates occurred. Default is 00:00:00 local time, October
  288. * 15, 1582. Previous to this time and date will be Julian dates.
  289. *
  290. * @param date The given Gregorian cutover date.
  291. * @param success Output param set to success/failure code on exit.
  292. * @stable ICU 2.0
  293. */
  294. void setGregorianChange(UDate date, UErrorCode& success);
  295. /**
  296. * Gets the Gregorian Calendar change date. This is the point when the switch from
  297. * Julian dates to Gregorian dates occurred. Default is 00:00:00 local time, October
  298. * 15, 1582. Previous to this time and date will be Julian dates.
  299. *
  300. * @return The Gregorian cutover time for this calendar.
  301. * @stable ICU 2.0
  302. */
  303. UDate getGregorianChange() const;
  304. /**
  305. * Return true if the given year is a leap year. Determination of whether a year is
  306. * a leap year is actually very complicated. We do something crude and mostly
  307. * correct here, but for a real determination you need a lot of contextual
  308. * information. For example, in Sweden, the change from Julian to Gregorian happened
  309. * in a complex way resulting in missed leap years and double leap years between
  310. * 1700 and 1753. Another example is that after the start of the Julian calendar in
  311. * 45 B.C., the leap years did not regularize until 8 A.D. This method ignores these
  312. * quirks, and pays attention only to the Julian onset date and the Gregorian
  313. * cutover (which can be changed).
  314. *
  315. * @param year The given year.
  316. * @return True if the given year is a leap year; false otherwise.
  317. * @stable ICU 2.0
  318. */
  319. UBool isLeapYear(int32_t year) const;
  320. /**
  321. * Returns true if the given Calendar object is equivalent to this
  322. * one. Calendar override.
  323. *
  324. * @param other the Calendar to be compared with this Calendar
  325. * @stable ICU 2.4
  326. */
  327. virtual UBool isEquivalentTo(const Calendar& other) const override;
  328. #ifndef U_FORCE_HIDE_DEPRECATED_API
  329. /**
  330. * (Overrides Calendar) Rolls up or down by the given amount in the specified field.
  331. * For more information, see the documentation for Calendar::roll().
  332. *
  333. * @param field The time field.
  334. * @param amount Indicates amount to roll.
  335. * @param status Output param set to success/failure code on exit. If any value
  336. * previously set in the time field is invalid, this will be set to
  337. * an error status.
  338. * @deprecated ICU 2.6. Use roll(UCalendarDateFields field, int32_t amount, UErrorCode& status) instead.
  339. */
  340. virtual void roll(EDateFields field, int32_t amount, UErrorCode& status) override;
  341. #endif // U_FORCE_HIDE_DEPRECATED_API
  342. /**
  343. * (Overrides Calendar) Rolls up or down by the given amount in the specified field.
  344. * For more information, see the documentation for Calendar::roll().
  345. *
  346. * @param field The time field.
  347. * @param amount Indicates amount to roll.
  348. * @param status Output param set to success/failure code on exit. If any value
  349. * previously set in the time field is invalid, this will be set to
  350. * an error status.
  351. * @stable ICU 2.6.
  352. */
  353. virtual void roll(UCalendarDateFields field, int32_t amount, UErrorCode& status) override;
  354. #ifndef U_HIDE_DEPRECATED_API
  355. /**
  356. * Return the minimum value that this field could have, given the current date.
  357. * For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum().
  358. * @param field the time field.
  359. * @return the minimum value that this field could have, given the current date.
  360. * @deprecated ICU 2.6. Use getActualMinimum(UCalendarDateFields field) instead.
  361. */
  362. int32_t getActualMinimum(EDateFields field) const;
  363. /**
  364. * Return the minimum value that this field could have, given the current date.
  365. * For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum().
  366. * @param field the time field.
  367. * @param status
  368. * @return the minimum value that this field could have, given the current date.
  369. * @deprecated ICU 2.6. Use getActualMinimum(UCalendarDateFields field) instead. (Added to ICU 3.0 for signature consistency)
  370. */
  371. int32_t getActualMinimum(EDateFields field, UErrorCode& status) const;
  372. #endif /* U_HIDE_DEPRECATED_API */
  373. /**
  374. * Return the minimum value that this field could have, given the current date.
  375. * For the Gregorian calendar, this is the same as getMinimum() and getGreatestMinimum().
  376. * @param field the time field.
  377. * @param status error result.
  378. * @return the minimum value that this field could have, given the current date.
  379. * @stable ICU 3.0
  380. */
  381. int32_t getActualMinimum(UCalendarDateFields field, UErrorCode &status) const override;
  382. /**
  383. * Return the maximum value that this field could have, given the current date.
  384. * For example, with the date "Feb 3, 1997" and the DAY_OF_MONTH field, the actual
  385. * maximum would be 28; for "Feb 3, 1996" it s 29. Similarly for a Hebrew calendar,
  386. * for some years the actual maximum for MONTH is 12, and for others 13.
  387. * @param field the time field.
  388. * @param status returns any errors that may result from this function call.
  389. * @return the maximum value that this field could have, given the current date.
  390. * @stable ICU 2.6
  391. */
  392. virtual int32_t getActualMaximum(UCalendarDateFields field, UErrorCode& status) const override;
  393. public:
  394. /**
  395. * Override Calendar Returns a unique class ID POLYMORPHICALLY. Pure virtual
  396. * override. This method is to implement a simple version of RTTI, since not all C++
  397. * compilers support genuine RTTI. Polymorphic operator==() and clone() methods call
  398. * this method.
  399. *
  400. * @return The class ID for this object. All objects of a given class have the
  401. * same class ID. Objects of other classes have different class IDs.
  402. * @stable ICU 2.0
  403. */
  404. virtual UClassID getDynamicClassID() const override;
  405. /**
  406. * Return the class ID for this class. This is useful only for comparing to a return
  407. * value from getDynamicClassID(). For example:
  408. *
  409. * Base* polymorphic_pointer = createPolymorphicObject();
  410. * if (polymorphic_pointer->getDynamicClassID() ==
  411. * Derived::getStaticClassID()) ...
  412. *
  413. * @return The class ID for all objects of this class.
  414. * @stable ICU 2.0
  415. */
  416. static UClassID U_EXPORT2 getStaticClassID();
  417. /**
  418. * Returns the calendar type name string for this Calendar object.
  419. * The returned string is the legacy ICU calendar attribute value,
  420. * for example, "gregorian" or "japanese".
  421. *
  422. * For more details see the Calendar::getType() documentation.
  423. *
  424. * @return legacy calendar type name string
  425. * @stable ICU 49
  426. */
  427. virtual const char * getType() const override;
  428. private:
  429. GregorianCalendar() = delete; // default constructor not implemented
  430. protected:
  431. /**
  432. * Return the ERA. We need a special method for this because the
  433. * default ERA is AD, but a zero (unset) ERA is BC.
  434. * @return the ERA.
  435. * @internal
  436. */
  437. virtual int32_t internalGetEra() const;
  438. /**
  439. * Return the Julian day number of day before the first day of the
  440. * given month in the given extended year. Subclasses should override
  441. * this method to implement their calendar system.
  442. * @param eyear the extended year
  443. * @param month the zero-based month, or 0 if useMonth is false
  444. * @param useMonth if false, compute the day before the first day of
  445. * the given year, otherwise, compute the day before the first day of
  446. * the given month
  447. * @param status Fill-in parameter which receives the status of this operation.
  448. * @return the Julian day number of the day before the first
  449. * day of the given month and year
  450. * @internal
  451. */
  452. virtual int64_t handleComputeMonthStart(int32_t eyear, int32_t month,
  453. UBool useMonth, UErrorCode& status) const override;
  454. /**
  455. * Subclasses may override this. This method calls
  456. * handleGetMonthLength() to obtain the calendar-specific month
  457. * length.
  458. * @param bestField which field to use to calculate the date
  459. * @param status Fill-in parameter which receives the status of this operation.
  460. * @return julian day specified by calendar fields.
  461. * @internal
  462. */
  463. virtual int32_t handleComputeJulianDay(UCalendarDateFields bestField, UErrorCode& status) override;
  464. /**
  465. * Return the number of days in the given month of the given extended
  466. * year of this calendar system. Subclasses should override this
  467. * method if they can provide a more correct or more efficient
  468. * implementation than the default implementation in Calendar.
  469. * @internal
  470. */
  471. virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month, UErrorCode& status) const override;
  472. /**
  473. * Return the number of days in the given extended year of this
  474. * calendar system. Subclasses should override this method if they can
  475. * provide a more correct or more efficient implementation than the
  476. * default implementation in Calendar.
  477. * @stable ICU 2.0
  478. */
  479. virtual int32_t handleGetYearLength(int32_t eyear) const override;
  480. /**
  481. * return the length of the given month.
  482. * @param month the given month.
  483. * @param status Fill-in parameter which receives the status of this operation.
  484. * @return the length of the given month.
  485. * @internal
  486. */
  487. virtual int32_t monthLength(int32_t month, UErrorCode& status) const;
  488. /**
  489. * return the length of the month according to the given year.
  490. * @param month the given month.
  491. * @param year the given year.
  492. * @return the length of the month
  493. * @internal
  494. */
  495. virtual int32_t monthLength(int32_t month, int32_t year) const;
  496. #ifndef U_HIDE_INTERNAL_API
  497. /**
  498. * return the length of the year field.
  499. * @return the length of the year field
  500. * @internal
  501. */
  502. int32_t yearLength() const;
  503. #endif /* U_HIDE_INTERNAL_API */
  504. /**
  505. * Return the day number with respect to the epoch. January 1, 1970 (Gregorian)
  506. * is day zero.
  507. * @param status Fill-in parameter which receives the status of this operation.
  508. * @return the day number with respect to the epoch.
  509. * @internal
  510. */
  511. virtual UDate getEpochDay(UErrorCode& status);
  512. /**
  513. * Subclass API for defining limits of different types.
  514. * Subclasses must implement this method to return limits for the
  515. * following fields:
  516. *
  517. * <pre>UCAL_ERA
  518. * UCAL_YEAR
  519. * UCAL_MONTH
  520. * UCAL_WEEK_OF_YEAR
  521. * UCAL_WEEK_OF_MONTH
  522. * UCAL_DATE (DAY_OF_MONTH on Java)
  523. * UCAL_DAY_OF_YEAR
  524. * UCAL_DAY_OF_WEEK_IN_MONTH
  525. * UCAL_YEAR_WOY
  526. * UCAL_EXTENDED_YEAR</pre>
  527. *
  528. * @param field one of the above field numbers
  529. * @param limitType one of <code>MINIMUM</code>, <code>GREATEST_MINIMUM</code>,
  530. * <code>LEAST_MAXIMUM</code>, or <code>MAXIMUM</code>
  531. * @internal
  532. */
  533. virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const override;
  534. /**
  535. * Return the extended year defined by the current fields. This will
  536. * use the UCAL_EXTENDED_YEAR field or the UCAL_YEAR and supra-year fields (such
  537. * as UCAL_ERA) specific to the calendar system, depending on which set of
  538. * fields is newer.
  539. * @param status
  540. * @return the extended year
  541. * @internal
  542. */
  543. virtual int32_t handleGetExtendedYear(UErrorCode& status) override;
  544. /**
  545. * Subclasses may override this to convert from week fields
  546. * (YEAR_WOY and WEEK_OF_YEAR) to an extended year in the case
  547. * where YEAR, EXTENDED_YEAR are not set.
  548. * The Gregorian implementation assumes a yearWoy in gregorian format, according to the current era.
  549. * @return the extended year, UCAL_EXTENDED_YEAR
  550. * @internal
  551. */
  552. virtual int32_t handleGetExtendedYearFromWeekFields(int32_t yearWoy, int32_t woy, UErrorCode& status) override;
  553. /**
  554. * Subclasses may override this method to compute several fields
  555. * specific to each calendar system. These are:
  556. *
  557. * <ul><li>ERA
  558. * <li>YEAR
  559. * <li>MONTH
  560. * <li>DAY_OF_MONTH
  561. * <li>DAY_OF_YEAR
  562. * <li>EXTENDED_YEAR</ul>
  563. *
  564. * <p>The GregorianCalendar implementation implements
  565. * a calendar with the specified Julian/Gregorian cutover date.
  566. * @internal
  567. */
  568. virtual void handleComputeFields(int32_t julianDay, UErrorCode &status) override;
  569. #ifndef U_HIDE_INTERNAL_API
  570. /**
  571. * The year in this calendar is counting from 1 backward if the era is 0.
  572. * @return The year in era 0 of this calendar is counting backward from 1.
  573. * @internal
  574. */
  575. virtual bool isEra0CountingBackward() const override { return true; }
  576. #endif // U_HIDE_INTERNAL_API
  577. private:
  578. /**
  579. * Compute the julian day number of the given year.
  580. * @param isGregorian if true, using Gregorian calendar, otherwise using Julian calendar
  581. * @param year the given year.
  582. * @param isLeap true if the year is a leap year.
  583. * @return
  584. */
  585. static double computeJulianDayOfYear(UBool isGregorian, int32_t year,
  586. UBool& isLeap);
  587. /**
  588. * Validates the values of the set time fields. True if they're all valid.
  589. * @return True if the set time fields are all valid.
  590. */
  591. UBool validateFields() const;
  592. /**
  593. * Validates the value of the given time field. True if it's valid.
  594. */
  595. UBool boundsCheck(int32_t value, UCalendarDateFields field) const;
  596. /**
  597. * Return the pseudo-time-stamp for two fields, given their
  598. * individual pseudo-time-stamps. If either of the fields
  599. * is unset, then the aggregate is unset. Otherwise, the
  600. * aggregate is the later of the two stamps.
  601. * @param stamp_a One given field.
  602. * @param stamp_b Another given field.
  603. * @return the pseudo-time-stamp for two fields
  604. */
  605. int32_t aggregateStamp(int32_t stamp_a, int32_t stamp_b);
  606. /**
  607. * The point at which the Gregorian calendar rules are used, measured in
  608. * milliseconds from the standard epoch. Default is October 15, 1582
  609. * (Gregorian) 00:00:00 UTC, that is, October 4, 1582 (Julian) is followed
  610. * by October 15, 1582 (Gregorian). This corresponds to Julian day number
  611. * 2299161. This is measured from the standard epoch, not in Julian Days.
  612. */
  613. UDate fGregorianCutover;
  614. /**
  615. * Julian day number of the Gregorian cutover
  616. */
  617. int32_t fCutoverJulianDay;
  618. /**
  619. * Midnight, local time (using this Calendar's TimeZone) at or before the
  620. * gregorianCutover. This is a pure date value with no time of day or
  621. * timezone component.
  622. */
  623. UDate fNormalizedGregorianCutover;// = gregorianCutover;
  624. /**
  625. * The year of the gregorianCutover, with 0 representing
  626. * 1 BC, -1 representing 2 BC, etc.
  627. */
  628. int32_t fGregorianCutoverYear;// = 1582;
  629. /**
  630. * Converts time as milliseconds to Julian date. The Julian date used here is not a
  631. * true Julian date, since it is measured from midnight, not noon.
  632. *
  633. * @param millis The given milliseconds.
  634. * @return The Julian date number.
  635. */
  636. static double millisToJulianDay(UDate millis);
  637. /**
  638. * Converts Julian date to time as milliseconds. The Julian date used here is not a
  639. * true Julian date, since it is measured from midnight, not noon.
  640. *
  641. * @param julian The given Julian date number.
  642. * @return Time as milliseconds.
  643. */
  644. static UDate julianDayToMillis(double julian);
  645. /**
  646. * Used by handleComputeJulianDay() and handleComputeMonthStart().
  647. * Temporary field indicating whether the calendar is currently Gregorian as opposed to Julian.
  648. */
  649. UBool fIsGregorian;
  650. /**
  651. * Used by handleComputeJulianDay() and handleComputeMonthStart().
  652. * Temporary field indicating that the sense of the gregorian cutover should be inverted
  653. * to handle certain calculations on and around the cutover date.
  654. */
  655. UBool fInvertGregorian;
  656. public: // internal implementation
  657. DECLARE_OVERRIDE_SYSTEM_DEFAULT_CENTURY
  658. };
  659. U_NAMESPACE_END
  660. #endif /* #if !UCONFIG_NO_FORMATTING */
  661. #endif /* U_SHOW_CPLUSPLUS_API */
  662. #endif // _GREGOCAL
  663. //eof