hebrwcal.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. ******************************************************************************
  5. * Copyright (C) 2003-2013, International Business Machines Corporation
  6. * and others. All Rights Reserved.
  7. ******************************************************************************
  8. *
  9. * File HEBRWCAL.H
  10. *
  11. * Modification History:
  12. *
  13. * Date Name Description
  14. * 05/13/2003 srl copied from gregocal.h
  15. * 11/26/2003 srl copied from buddhcal.h
  16. ******************************************************************************
  17. */
  18. #ifndef HEBRWCAL_H
  19. #define HEBRWCAL_H
  20. #include "unicode/utypes.h"
  21. #if !UCONFIG_NO_FORMATTING
  22. #include "unicode/calendar.h"
  23. #include "unicode/gregocal.h"
  24. U_NAMESPACE_BEGIN
  25. /**
  26. * <code>HebrewCalendar</code> is a subclass of <code>Calendar</code>
  27. * that that implements the traditional Hebrew calendar.
  28. * This is the civil calendar in Israel and the liturgical calendar
  29. * of the Jewish faith worldwide.
  30. * <p>
  31. * The Hebrew calendar is lunisolar and thus has a number of interesting
  32. * properties that distinguish it from the Gregorian. Months start
  33. * on the day of (an arithmetic approximation of) each new moon. Since the
  34. * solar year (approximately 365.24 days) is not an even multiple of
  35. * the lunar month (approximately 29.53 days) an extra "leap month" is
  36. * inserted in 7 out of every 19 years. To make matters even more
  37. * interesting, the start of a year can be delayed by up to three days
  38. * in order to prevent certain holidays from falling on the Sabbath and
  39. * to prevent certain illegal year lengths. Finally, the lengths of certain
  40. * months can vary depending on the number of days in the year.
  41. * <p>
  42. * The leap month is known as "Adar 1" and is inserted between the
  43. * months of Shevat and Adar in leap years. Since the leap month does
  44. * not come at the end of the year, calculations involving
  45. * month numbers are particularly complex. Users of this class should
  46. * make sure to use the {@link #roll roll} and {@link #add add} methods
  47. * rather than attempting to perform date arithmetic by manipulating
  48. * the fields directly.
  49. * <p>
  50. * <b>Note:</b> In the traditional Hebrew calendar, days start at sunset.
  51. * However, in order to keep the time fields in this class
  52. * synchronized with those of the other calendars and with local clock time,
  53. * we treat days and months as beginning at midnight,
  54. * roughly 6 hours after the corresponding sunset.
  55. * <p>
  56. * If you are interested in more information on the rules behind the Hebrew
  57. * calendar, see one of the following references:
  58. * <ul>
  59. * <li>"<a href="http://www.amazon.com/exec/obidos/ASIN/0521564743">Calendrical Calculations</a>",
  60. * by Nachum Dershowitz & Edward Reingold, Cambridge University Press, 1997, pages 85-91.
  61. *
  62. * <li>Hebrew Calendar Science and Myths,
  63. * <a href="http://www.geocities.com/Athens/1584/">
  64. * http://www.geocities.com/Athens/1584/</a>
  65. *
  66. * <li>The Calendar FAQ,
  67. * <a href="http://www.faqs.org/faqs/calendars/faq/">
  68. * http://www.faqs.org/faqs/calendars/faq/</a>
  69. * </ul>
  70. * <p>
  71. * @see com.ibm.icu.util.GregorianCalendar
  72. *
  73. * @author Laura Werner
  74. * @author Alan Liu
  75. * @author Steven R. Loomis
  76. * <p>
  77. * @internal
  78. */
  79. class U_I18N_API HebrewCalendar : public Calendar {
  80. public:
  81. /**
  82. * Useful constants for HebrewCalendar.
  83. * @internal
  84. */
  85. enum EEras {
  86. /**
  87. * Constant for Tishri, the 1st month of the Hebrew year.
  88. */
  89. TISHRI,
  90. /**
  91. * Constant for Heshvan, the 2nd month of the Hebrew year.
  92. */
  93. HESHVAN,
  94. /**
  95. * Constant for Kislev, the 3rd month of the Hebrew year.
  96. */
  97. KISLEV,
  98. /**
  99. * Constant for Tevet, the 4th month of the Hebrew year.
  100. */
  101. TEVET,
  102. /**
  103. * Constant for Shevat, the 5th month of the Hebrew year.
  104. */
  105. SHEVAT,
  106. /**
  107. * Constant for Adar I, the 6th month of the Hebrew year
  108. * (present in leap years only). In non-leap years, the calendar
  109. * jumps from Shevat (5th month) to Adar (7th month).
  110. */
  111. ADAR_1,
  112. /**
  113. * Constant for the Adar, the 7th month of the Hebrew year.
  114. */
  115. ADAR,
  116. /**
  117. * Constant for Nisan, the 8th month of the Hebrew year.
  118. */
  119. NISAN,
  120. /**
  121. * Constant for Iyar, the 9th month of the Hebrew year.
  122. */
  123. IYAR,
  124. /**
  125. * Constant for Sivan, the 10th month of the Hebrew year.
  126. */
  127. SIVAN,
  128. /**
  129. * Constant for Tammuz, the 11th month of the Hebrew year.
  130. */
  131. TAMUZ,
  132. /**
  133. * Constant for Av, the 12th month of the Hebrew year.
  134. */
  135. AV,
  136. /**
  137. * Constant for Elul, the 13th month of the Hebrew year.
  138. */
  139. ELUL
  140. };
  141. /**
  142. * Constructs a HebrewCalendar based on the current time in the default time zone
  143. * with the given locale.
  144. *
  145. * @param aLocale The given locale.
  146. * @param success Indicates the status of HebrewCalendar object construction.
  147. * Returns U_ZERO_ERROR if constructed successfully.
  148. * @internal
  149. */
  150. HebrewCalendar(const Locale& aLocale, UErrorCode& success);
  151. /**
  152. * Destructor
  153. * @internal
  154. */
  155. virtual ~HebrewCalendar();
  156. /**
  157. * Copy constructor
  158. * @param source the object to be copied.
  159. * @internal
  160. */
  161. HebrewCalendar(const HebrewCalendar& source);
  162. /**
  163. * Default assignment operator
  164. * @param right the object to be copied.
  165. * @internal
  166. */
  167. HebrewCalendar& operator=(const HebrewCalendar& right);
  168. /**
  169. * Create and return a polymorphic copy of this calendar.
  170. * @return return a polymorphic copy of this calendar.
  171. * @internal
  172. */
  173. virtual HebrewCalendar* clone() const;
  174. public:
  175. /**
  176. * Override Calendar Returns a unique class ID POLYMORPHICALLY. Pure virtual
  177. * override. This method is to implement a simple version of RTTI, since not all C++
  178. * compilers support genuine RTTI. Polymorphic operator==() and clone() methods call
  179. * this method.
  180. *
  181. * @return The class ID for this object. All objects of a given class have the
  182. * same class ID. Objects of other classes have different class IDs.
  183. * @internal
  184. */
  185. virtual UClassID getDynamicClassID(void) const;
  186. /**
  187. * Return the class ID for this class. This is useful only for comparing to a return
  188. * value from getDynamicClassID(). For example:
  189. *
  190. * Base* polymorphic_pointer = createPolymorphicObject();
  191. * if (polymorphic_pointer->getDynamicClassID() ==
  192. * Derived::getStaticClassID()) ...
  193. *
  194. * @return The class ID for all objects of this class.
  195. * @internal
  196. */
  197. static UClassID U_EXPORT2 getStaticClassID(void);
  198. /**
  199. * return the calendar type, "hebrew".
  200. *
  201. * @return calendar type
  202. * @internal
  203. */
  204. virtual const char * getType() const;
  205. // Calendar API
  206. public:
  207. /**
  208. * (Overrides Calendar) UDate Arithmetic function. Adds the specified (signed) amount
  209. * of time to the given time field, based on the calendar's rules. For more
  210. * information, see the documentation for Calendar::add().
  211. *
  212. * @param field The time field.
  213. * @param amount The amount of date or time to be added to the field.
  214. * @param status Output param set to success/failure code on exit. If any value
  215. * previously set in the time field is invalid, this will be set to
  216. * an error status.
  217. */
  218. virtual void add(UCalendarDateFields field, int32_t amount, UErrorCode& status);
  219. /**
  220. * @deprecated ICU 2.6 use UCalendarDateFields instead of EDateFields
  221. */
  222. virtual void add(EDateFields field, int32_t amount, UErrorCode& status);
  223. /**
  224. * (Overrides Calendar) Rolls up or down by the given amount in the specified field.
  225. * For more information, see the documentation for Calendar::roll().
  226. *
  227. * @param field The time field.
  228. * @param amount Indicates amount to roll.
  229. * @param status Output param set to success/failure code on exit. If any value
  230. * previously set in the time field is invalid, this will be set to
  231. * an error status.
  232. * @internal
  233. */
  234. virtual void roll(UCalendarDateFields field, int32_t amount, UErrorCode& status);
  235. /**
  236. * (Overrides Calendar) Rolls up or down by the given amount in the specified field.
  237. * For more information, see the documentation for Calendar::roll().
  238. *
  239. * @param field The time field.
  240. * @param amount Indicates amount to roll.
  241. * @param status Output param set to success/failure code on exit. If any value
  242. * previously set in the time field is invalid, this will be set to
  243. * an error status.
  244. * @deprecated ICU 2.6. Use roll(UCalendarDateFields field, int32_t amount, UErrorCode& status) instead.
  245. ` */
  246. virtual void roll(EDateFields field, int32_t amount, UErrorCode& status);
  247. /**
  248. * @internal
  249. */
  250. static UBool isLeapYear(int32_t year) ;
  251. protected:
  252. /**
  253. * Subclass API for defining limits of different types.
  254. * Subclasses must implement this method to return limits for the
  255. * following fields:
  256. *
  257. * <pre>UCAL_ERA
  258. * UCAL_YEAR
  259. * UCAL_MONTH
  260. * UCAL_WEEK_OF_YEAR
  261. * UCAL_WEEK_OF_MONTH
  262. * UCAL_DATE (DAY_OF_MONTH on Java)
  263. * UCAL_DAY_OF_YEAR
  264. * UCAL_DAY_OF_WEEK_IN_MONTH
  265. * UCAL_YEAR_WOY
  266. * UCAL_EXTENDED_YEAR</pre>
  267. *
  268. * @param field one of the above field numbers
  269. * @param limitType one of <code>MINIMUM</code>, <code>GREATEST_MINIMUM</code>,
  270. * <code>LEAST_MAXIMUM</code>, or <code>MAXIMUM</code>
  271. * @internal
  272. */
  273. virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const;
  274. /**
  275. * Return the number of days in the given month of the given extended
  276. * year of this calendar system. Subclasses should override this
  277. * method if they can provide a more correct or more efficient
  278. * implementation than the default implementation in Calendar.
  279. * @internal
  280. */
  281. virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month) const;
  282. /**
  283. * Return the number of days in the given extended year of this
  284. * calendar system. Subclasses should override this method if they can
  285. * provide a more correct or more efficient implementation than the
  286. * default implementation in Calendar.
  287. * @stable ICU 2.0
  288. */
  289. virtual int32_t handleGetYearLength(int32_t eyear) const;
  290. /**
  291. * Subclasses may override this method to compute several fields
  292. * specific to each calendar system. These are:
  293. *
  294. * <ul><li>ERA
  295. * <li>YEAR
  296. * <li>MONTH
  297. * <li>DAY_OF_MONTH
  298. * <li>DAY_OF_YEAR
  299. * <li>EXTENDED_YEAR</ul>
  300. *
  301. * <p>The GregorianCalendar implementation implements
  302. * a calendar with the specified Julian/Gregorian cutover date.
  303. * @internal
  304. */
  305. virtual void handleComputeFields(int32_t julianDay, UErrorCode &status);
  306. /**
  307. * Return the extended year defined by the current fields. This will
  308. * use the UCAL_EXTENDED_YEAR field or the UCAL_YEAR and supra-year fields (such
  309. * as UCAL_ERA) specific to the calendar system, depending on which set of
  310. * fields is newer.
  311. * @return the extended year
  312. * @internal
  313. */
  314. virtual int32_t handleGetExtendedYear();
  315. /**
  316. * Return the Julian day number of day before the first day of the
  317. * given month in the given extended year. Subclasses should override
  318. * this method to implement their calendar system.
  319. * @param eyear the extended year
  320. * @param month the zero-based month, or 0 if useMonth is false
  321. * @param useMonth if false, compute the day before the first day of
  322. * the given year, otherwise, compute the day before the first day of
  323. * the given month
  324. * @param return the Julian day number of the day before the first
  325. * day of the given month and year
  326. * @internal
  327. */
  328. virtual int32_t handleComputeMonthStart(int32_t eyear, int32_t month,
  329. UBool useMonth) const;
  330. /**
  331. * Validate a single field of this calendar.
  332. * Overrides Calendar::validateField(int) to provide
  333. * special handling for month validation for Hebrew calendar.
  334. * @internal
  335. */
  336. virtual void validateField(UCalendarDateFields field, UErrorCode &status);
  337. protected:
  338. /**
  339. * (Overrides Calendar) Return true if the current date for this Calendar is in
  340. * Daylight Savings Time. Recognizes DST_OFFSET, if it is set.
  341. *
  342. * @param status Fill-in parameter which receives the status of this operation.
  343. * @return True if the current date for this Calendar is in Daylight Savings Time,
  344. * false, otherwise.
  345. * @internal
  346. */
  347. virtual UBool inDaylightTime(UErrorCode& status) const;
  348. /**
  349. * Returns TRUE because the Hebrew Calendar does have a default century
  350. * @internal
  351. */
  352. virtual UBool haveDefaultCentury() const;
  353. /**
  354. * Returns the date of the start of the default century
  355. * @return start of century - in milliseconds since epoch, 1970
  356. * @internal
  357. */
  358. virtual UDate defaultCenturyStart() const;
  359. /**
  360. * Returns the year in which the default century begins
  361. * @internal
  362. */
  363. virtual int32_t defaultCenturyStartYear() const;
  364. private: // Calendar-specific implementation
  365. /**
  366. * Finds the day # of the first day in the given Hebrew year.
  367. * To do this, we want to calculate the time of the Tishri 1 new moon
  368. * in that year.
  369. * <p>
  370. * The algorithm here is similar to ones described in a number of
  371. * references, including:
  372. * <ul>
  373. * <li>"Calendrical Calculations", by Nachum Dershowitz & Edward Reingold,
  374. * Cambridge University Press, 1997, pages 85-91.
  375. *
  376. * <li>Hebrew Calendar Science and Myths,
  377. * <a href="http://www.geocities.com/Athens/1584/">
  378. * http://www.geocities.com/Athens/1584/</a>
  379. *
  380. * <li>The Calendar FAQ,
  381. * <a href="http://www.faqs.org/faqs/calendars/faq/">
  382. * http://www.faqs.org/faqs/calendars/faq/</a>
  383. * </ul>
  384. * @param year extended year
  385. * @return day number (JD)
  386. * @internal
  387. */
  388. static int32_t startOfYear(int32_t year, UErrorCode& status);
  389. static int32_t absoluteDayToDayOfWeek(int32_t day) ;
  390. /**
  391. * @internal
  392. */
  393. int32_t yearType(int32_t year) const;
  394. /**
  395. * @internal
  396. */
  397. static int32_t monthsInYear(int32_t year) ;
  398. };
  399. U_NAMESPACE_END
  400. #endif /* #if !UCONFIG_NO_FORMATTING */
  401. #endif
  402. //eof