gregocal.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785
  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);
  74. * // if no ids were returned, something is wrong. get out.
  75. * if (ids == 0 || ids->count(success) == 0) {
  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(NULL, 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 occured. 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;
  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(void) 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;
  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);
  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);
  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;
  382. #ifndef U_HIDE_DEPRECATED_API
  383. /**
  384. * Return the maximum value that this field could have, given the current date.
  385. * For example, with the date "Feb 3, 1997" and the DAY_OF_MONTH field, the actual
  386. * maximum would be 28; for "Feb 3, 1996" it s 29. Similarly for a Hebrew calendar,
  387. * for some years the actual maximum for MONTH is 12, and for others 13.
  388. * @param field the time field.
  389. * @return the maximum value that this field could have, given the current date.
  390. * @deprecated ICU 2.6. Use getActualMaximum(UCalendarDateFields field) instead.
  391. */
  392. int32_t getActualMaximum(EDateFields field) const;
  393. #endif /* U_HIDE_DEPRECATED_API */
  394. /**
  395. * Return the maximum value that this field could have, given the current date.
  396. * For example, with the date "Feb 3, 1997" and the DAY_OF_MONTH field, the actual
  397. * maximum would be 28; for "Feb 3, 1996" it s 29. Similarly for a Hebrew calendar,
  398. * for some years the actual maximum for MONTH is 12, and for others 13.
  399. * @param field the time field.
  400. * @param status returns any errors that may result from this function call.
  401. * @return the maximum value that this field could have, given the current date.
  402. * @stable ICU 2.6
  403. */
  404. virtual int32_t getActualMaximum(UCalendarDateFields field, UErrorCode& status) const;
  405. /**
  406. * (Overrides Calendar) Return true if the current date for this Calendar is in
  407. * Daylight Savings Time. Recognizes DST_OFFSET, if it is set.
  408. *
  409. * @param status Fill-in parameter which receives the status of this operation.
  410. * @return True if the current date for this Calendar is in Daylight Savings Time,
  411. * false, otherwise.
  412. * @stable ICU 2.0
  413. */
  414. virtual UBool inDaylightTime(UErrorCode& status) const;
  415. public:
  416. /**
  417. * Override Calendar Returns a unique class ID POLYMORPHICALLY. Pure virtual
  418. * override. This method is to implement a simple version of RTTI, since not all C++
  419. * compilers support genuine RTTI. Polymorphic operator==() and clone() methods call
  420. * this method.
  421. *
  422. * @return The class ID for this object. All objects of a given class have the
  423. * same class ID. Objects of other classes have different class IDs.
  424. * @stable ICU 2.0
  425. */
  426. virtual UClassID getDynamicClassID(void) const;
  427. /**
  428. * Return the class ID for this class. This is useful only for comparing to a return
  429. * value from getDynamicClassID(). For example:
  430. *
  431. * Base* polymorphic_pointer = createPolymorphicObject();
  432. * if (polymorphic_pointer->getDynamicClassID() ==
  433. * Derived::getStaticClassID()) ...
  434. *
  435. * @return The class ID for all objects of this class.
  436. * @stable ICU 2.0
  437. */
  438. static UClassID U_EXPORT2 getStaticClassID(void);
  439. /**
  440. * Returns the calendar type name string for this Calendar object.
  441. * The returned string is the legacy ICU calendar attribute value,
  442. * for example, "gregorian" or "japanese".
  443. *
  444. * For more details see the Calendar::getType() documentation.
  445. *
  446. * @return legacy calendar type name string
  447. * @stable ICU 49
  448. */
  449. virtual const char * getType() const;
  450. private:
  451. GregorianCalendar(); // default constructor not implemented
  452. protected:
  453. /**
  454. * Return the ERA. We need a special method for this because the
  455. * default ERA is AD, but a zero (unset) ERA is BC.
  456. * @return the ERA.
  457. * @internal
  458. */
  459. virtual int32_t internalGetEra() const;
  460. /**
  461. * Return the Julian day number of day before the first day of the
  462. * given month in the given extended year. Subclasses should override
  463. * this method to implement their calendar system.
  464. * @param eyear the extended year
  465. * @param month the zero-based month, or 0 if useMonth is false
  466. * @param useMonth if false, compute the day before the first day of
  467. * the given year, otherwise, compute the day before the first day of
  468. * the given month
  469. * @return the Julian day number of the day before the first
  470. * day of the given month and year
  471. * @internal
  472. */
  473. virtual int32_t handleComputeMonthStart(int32_t eyear, int32_t month,
  474. UBool useMonth) const;
  475. /**
  476. * Subclasses may override this. This method calls
  477. * handleGetMonthLength() to obtain the calendar-specific month
  478. * length.
  479. * @param bestField which field to use to calculate the date
  480. * @return julian day specified by calendar fields.
  481. * @internal
  482. */
  483. virtual int32_t handleComputeJulianDay(UCalendarDateFields bestField) ;
  484. /**
  485. * Return the number of days in the given month of the given extended
  486. * year of this calendar system. Subclasses should override this
  487. * method if they can provide a more correct or more efficient
  488. * implementation than the default implementation in Calendar.
  489. * @internal
  490. */
  491. virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month) const;
  492. /**
  493. * Return the number of days in the given extended year of this
  494. * calendar system. Subclasses should override this method if they can
  495. * provide a more correct or more efficient implementation than the
  496. * default implementation in Calendar.
  497. * @stable ICU 2.0
  498. */
  499. virtual int32_t handleGetYearLength(int32_t eyear) const;
  500. /**
  501. * return the length of the given month.
  502. * @param month the given month.
  503. * @return the length of the given month.
  504. * @internal
  505. */
  506. virtual int32_t monthLength(int32_t month) const;
  507. /**
  508. * return the length of the month according to the given year.
  509. * @param month the given month.
  510. * @param year the given year.
  511. * @return the length of the month
  512. * @internal
  513. */
  514. virtual int32_t monthLength(int32_t month, int32_t year) const;
  515. #ifndef U_HIDE_INTERNAL_API
  516. /**
  517. * return the length of the given year.
  518. * @param year the given year.
  519. * @return the length of the given year.
  520. * @internal
  521. */
  522. int32_t yearLength(int32_t year) const;
  523. /**
  524. * return the length of the year field.
  525. * @return the length of the year field
  526. * @internal
  527. */
  528. int32_t yearLength(void) const;
  529. /**
  530. * After adjustments such as add(MONTH), add(YEAR), we don't want the
  531. * month to jump around. E.g., we don't want Jan 31 + 1 month to go to Mar
  532. * 3, we want it to go to Feb 28. Adjustments which might run into this
  533. * problem call this method to retain the proper month.
  534. * @internal
  535. */
  536. void pinDayOfMonth(void);
  537. #endif /* U_HIDE_INTERNAL_API */
  538. /**
  539. * Return the day number with respect to the epoch. January 1, 1970 (Gregorian)
  540. * is day zero.
  541. * @param status Fill-in parameter which receives the status of this operation.
  542. * @return the day number with respect to the epoch.
  543. * @internal
  544. */
  545. virtual UDate getEpochDay(UErrorCode& status);
  546. /**
  547. * Subclass API for defining limits of different types.
  548. * Subclasses must implement this method to return limits for the
  549. * following fields:
  550. *
  551. * <pre>UCAL_ERA
  552. * UCAL_YEAR
  553. * UCAL_MONTH
  554. * UCAL_WEEK_OF_YEAR
  555. * UCAL_WEEK_OF_MONTH
  556. * UCAL_DATE (DAY_OF_MONTH on Java)
  557. * UCAL_DAY_OF_YEAR
  558. * UCAL_DAY_OF_WEEK_IN_MONTH
  559. * UCAL_YEAR_WOY
  560. * UCAL_EXTENDED_YEAR</pre>
  561. *
  562. * @param field one of the above field numbers
  563. * @param limitType one of <code>MINIMUM</code>, <code>GREATEST_MINIMUM</code>,
  564. * <code>LEAST_MAXIMUM</code>, or <code>MAXIMUM</code>
  565. * @internal
  566. */
  567. virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const;
  568. /**
  569. * Return the extended year defined by the current fields. This will
  570. * use the UCAL_EXTENDED_YEAR field or the UCAL_YEAR and supra-year fields (such
  571. * as UCAL_ERA) specific to the calendar system, depending on which set of
  572. * fields is newer.
  573. * @return the extended year
  574. * @internal
  575. */
  576. virtual int32_t handleGetExtendedYear();
  577. /**
  578. * Subclasses may override this to convert from week fields
  579. * (YEAR_WOY and WEEK_OF_YEAR) to an extended year in the case
  580. * where YEAR, EXTENDED_YEAR are not set.
  581. * The Gregorian implementation assumes a yearWoy in gregorian format, according to the current era.
  582. * @return the extended year, UCAL_EXTENDED_YEAR
  583. * @internal
  584. */
  585. virtual int32_t handleGetExtendedYearFromWeekFields(int32_t yearWoy, int32_t woy);
  586. /**
  587. * Subclasses may override this method to compute several fields
  588. * specific to each calendar system. These are:
  589. *
  590. * <ul><li>ERA
  591. * <li>YEAR
  592. * <li>MONTH
  593. * <li>DAY_OF_MONTH
  594. * <li>DAY_OF_YEAR
  595. * <li>EXTENDED_YEAR</ul>
  596. *
  597. * <p>The GregorianCalendar implementation implements
  598. * a calendar with the specified Julian/Gregorian cutover date.
  599. * @internal
  600. */
  601. virtual void handleComputeFields(int32_t julianDay, UErrorCode &status);
  602. private:
  603. /**
  604. * Compute the julian day number of the given year.
  605. * @param isGregorian if true, using Gregorian calendar, otherwise using Julian calendar
  606. * @param year the given year.
  607. * @param isLeap true if the year is a leap year.
  608. * @return
  609. */
  610. static double computeJulianDayOfYear(UBool isGregorian, int32_t year,
  611. UBool& isLeap);
  612. /**
  613. * Validates the values of the set time fields. True if they're all valid.
  614. * @return True if the set time fields are all valid.
  615. */
  616. UBool validateFields(void) const;
  617. /**
  618. * Validates the value of the given time field. True if it's valid.
  619. */
  620. UBool boundsCheck(int32_t value, UCalendarDateFields field) const;
  621. /**
  622. * Return the pseudo-time-stamp for two fields, given their
  623. * individual pseudo-time-stamps. If either of the fields
  624. * is unset, then the aggregate is unset. Otherwise, the
  625. * aggregate is the later of the two stamps.
  626. * @param stamp_a One given field.
  627. * @param stamp_b Another given field.
  628. * @return the pseudo-time-stamp for two fields
  629. */
  630. int32_t aggregateStamp(int32_t stamp_a, int32_t stamp_b);
  631. /**
  632. * The point at which the Gregorian calendar rules are used, measured in
  633. * milliseconds from the standard epoch. Default is October 15, 1582
  634. * (Gregorian) 00:00:00 UTC, that is, October 4, 1582 (Julian) is followed
  635. * by October 15, 1582 (Gregorian). This corresponds to Julian day number
  636. * 2299161. This is measured from the standard epoch, not in Julian Days.
  637. */
  638. UDate fGregorianCutover;
  639. /**
  640. * Julian day number of the Gregorian cutover
  641. */
  642. int32_t fCutoverJulianDay;
  643. /**
  644. * Midnight, local time (using this Calendar's TimeZone) at or before the
  645. * gregorianCutover. This is a pure date value with no time of day or
  646. * timezone component.
  647. */
  648. UDate fNormalizedGregorianCutover;// = gregorianCutover;
  649. /**
  650. * The year of the gregorianCutover, with 0 representing
  651. * 1 BC, -1 representing 2 BC, etc.
  652. */
  653. int32_t fGregorianCutoverYear;// = 1582;
  654. /**
  655. * The year of the gregorianCutover, with 0 representing
  656. * 1 BC, -1 representing 2 BC, etc.
  657. */
  658. int32_t fGregorianCutoverJulianDay;// = 2299161;
  659. /**
  660. * Converts time as milliseconds to Julian date. The Julian date used here is not a
  661. * true Julian date, since it is measured from midnight, not noon.
  662. *
  663. * @param millis The given milliseconds.
  664. * @return The Julian date number.
  665. */
  666. static double millisToJulianDay(UDate millis);
  667. /**
  668. * Converts Julian date to time as milliseconds. The Julian date used here is not a
  669. * true Julian date, since it is measured from midnight, not noon.
  670. *
  671. * @param julian The given Julian date number.
  672. * @return Time as milliseconds.
  673. */
  674. static UDate julianDayToMillis(double julian);
  675. /**
  676. * Used by handleComputeJulianDay() and handleComputeMonthStart().
  677. * Temporary field indicating whether the calendar is currently Gregorian as opposed to Julian.
  678. */
  679. UBool fIsGregorian;
  680. /**
  681. * Used by handleComputeJulianDay() and handleComputeMonthStart().
  682. * Temporary field indicating that the sense of the gregorian cutover should be inverted
  683. * to handle certain calculations on and around the cutover date.
  684. */
  685. UBool fInvertGregorian;
  686. public: // internal implementation
  687. /**
  688. * @return TRUE if this calendar has the notion of a default century
  689. * @internal
  690. */
  691. virtual UBool haveDefaultCentury() const;
  692. /**
  693. * @return the start of the default century
  694. * @internal
  695. */
  696. virtual UDate defaultCenturyStart() const;
  697. /**
  698. * @return the beginning year of the default century
  699. * @internal
  700. */
  701. virtual int32_t defaultCenturyStartYear() const;
  702. };
  703. U_NAMESPACE_END
  704. #endif /* #if !UCONFIG_NO_FORMATTING */
  705. #endif /* U_SHOW_CPLUSPLUS_API */
  706. #endif // _GREGOCAL
  707. //eof