gregocal.h 31 KB

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