1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 ******************************************************************************
5 * Copyright (C) 2003-2013, International Business Machines Corporation
6 * and others. All Rights Reserved.
7 ******************************************************************************
11 * Modification History:
13 * Date Name Description
14 * 05/13/2003 srl copied from gregocal.h
15 * 11/26/2003 srl copied from buddhcal.h
16 ******************************************************************************
22 #include "unicode/utypes.h"
24 #if !UCONFIG_NO_FORMATTING
26 #include "unicode/calendar.h"
27 #include "unicode/gregocal.h"
32 * <code>HebrewCalendar</code> is a subclass of <code>Calendar</code>
33 * that that implements the traditional Hebrew calendar.
34 * This is the civil calendar in Israel and the liturgical calendar
35 * of the Jewish faith worldwide.
37 * The Hebrew calendar is lunisolar and thus has a number of interesting
38 * properties that distinguish it from the Gregorian. Months start
39 * on the day of (an arithmetic approximation of) each new moon. Since the
40 * solar year (approximately 365.24 days) is not an even multiple of
41 * the lunar month (approximately 29.53 days) an extra "leap month" is
42 * inserted in 7 out of every 19 years. To make matters even more
43 * interesting, the start of a year can be delayed by up to three days
44 * in order to prevent certain holidays from falling on the Sabbath and
45 * to prevent certain illegal year lengths. Finally, the lengths of certain
46 * months can vary depending on the number of days in the year.
48 * The leap month is known as "Adar 1" and is inserted between the
49 * months of Shevat and Adar in leap years. Since the leap month does
50 * not come at the end of the year, calculations involving
51 * month numbers are particularly complex. Users of this class should
52 * make sure to use the {@link #roll roll} and {@link #add add} methods
53 * rather than attempting to perform date arithmetic by manipulating
54 * the fields directly.
56 * <b>Note:</b> In the traditional Hebrew calendar, days start at sunset.
57 * However, in order to keep the time fields in this class
58 * synchronized with those of the other calendars and with local clock time,
59 * we treat days and months as beginning at midnight,
60 * roughly 6 hours after the corresponding sunset.
62 * If you are interested in more information on the rules behind the Hebrew
63 * calendar, see one of the following references:
65 * <li>"<a href="http://www.amazon.com/exec/obidos/ASIN/0521564743">Calendrical Calculations</a>",
66 * by Nachum Dershowitz & Edward Reingold, Cambridge University Press, 1997, pages 85-91.
68 * <li>Hebrew Calendar Science and Myths,
69 * <a href="http://www.geocities.com/Athens/1584/">
70 * http://www.geocities.com/Athens/1584/</a>
72 * <li>The Calendar FAQ,
73 * <a href="http://www.faqs.org/faqs/calendars/faq/">
74 * http://www.faqs.org/faqs/calendars/faq/</a>
77 * @see com.ibm.icu.util.GregorianCalendar
79 * @author Laura Werner
81 * @author Steven R. Loomis
85 class U_I18N_API HebrewCalendar
: public Calendar
{
88 * Useful constants for HebrewCalendar.
93 * Constant for Tishri, the 1st month of the Hebrew year.
97 * Constant for Heshvan, the 2nd month of the Hebrew year.
101 * Constant for Kislev, the 3rd month of the Hebrew year.
106 * Constant for Tevet, the 4th month of the Hebrew year.
111 * Constant for Shevat, the 5th month of the Hebrew year.
116 * Constant for Adar I, the 6th month of the Hebrew year
117 * (present in leap years only). In non-leap years, the calendar
118 * jumps from Shevat (5th month) to Adar (7th month).
123 * Constant for the Adar, the 7th month of the Hebrew year.
128 * Constant for Nisan, the 8th month of the Hebrew year.
133 * Constant for Iyar, the 9th month of the Hebrew year.
138 * Constant for Sivan, the 10th month of the Hebrew year.
143 * Constant for Tammuz, the 11th month of the Hebrew year.
148 * Constant for Av, the 12th month of the Hebrew year.
153 * Constant for Elul, the 13th month of the Hebrew year.
159 * Constructs a HebrewCalendar based on the current time in the default time zone
160 * with the given locale.
162 * @param aLocale The given locale.
163 * @param success Indicates the status of HebrewCalendar object construction.
164 * Returns U_ZERO_ERROR if constructed successfully.
167 HebrewCalendar(const Locale
& aLocale
, UErrorCode
& success
);
174 virtual ~HebrewCalendar();
178 * @param source the object to be copied.
181 HebrewCalendar(const HebrewCalendar
& source
);
184 * Default assignment operator
185 * @param right the object to be copied.
188 HebrewCalendar
& operator=(const HebrewCalendar
& right
);
191 * Create and return a polymorphic copy of this calendar.
192 * @return return a polymorphic copy of this calendar.
195 virtual Calendar
* clone(void) const;
199 * Override Calendar Returns a unique class ID POLYMORPHICALLY. Pure virtual
200 * override. This method is to implement a simple version of RTTI, since not all C++
201 * compilers support genuine RTTI. Polymorphic operator==() and clone() methods call
204 * @return The class ID for this object. All objects of a given class have the
205 * same class ID. Objects of other classes have different class IDs.
208 virtual UClassID
getDynamicClassID(void) const;
211 * Return the class ID for this class. This is useful only for comparing to a return
212 * value from getDynamicClassID(). For example:
214 * Base* polymorphic_pointer = createPolymorphicObject();
215 * if (polymorphic_pointer->getDynamicClassID() ==
216 * Derived::getStaticClassID()) ...
218 * @return The class ID for all objects of this class.
221 static UClassID U_EXPORT2
getStaticClassID(void);
224 * return the calendar type, "hebrew".
226 * @return calendar type
229 virtual const char * getType() const;
235 * (Overrides Calendar) UDate Arithmetic function. Adds the specified (signed) amount
236 * of time to the given time field, based on the calendar's rules. For more
237 * information, see the documentation for Calendar::add().
239 * @param field The time field.
240 * @param amount The amount of date or time to be added to the field.
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
245 virtual void add(UCalendarDateFields field
, int32_t amount
, UErrorCode
& status
);
247 * @deprecated ICU 2.6 use UCalendarDateFields instead of EDateFields
249 virtual void add(EDateFields field
, int32_t amount
, UErrorCode
& status
);
253 * (Overrides Calendar) Rolls up or down by the given amount in the specified field.
254 * For more information, see the documentation for Calendar::roll().
256 * @param field The time field.
257 * @param amount Indicates amount to roll.
258 * @param status Output param set to success/failure code on exit. If any value
259 * previously set in the time field is invalid, this will be set to
263 virtual void roll(UCalendarDateFields field
, int32_t amount
, UErrorCode
& status
);
266 * (Overrides Calendar) Rolls up or down by the given amount in the specified field.
267 * For more information, see the documentation for Calendar::roll().
269 * @param field The time field.
270 * @param amount Indicates amount to roll.
271 * @param status Output param set to success/failure code on exit. If any value
272 * previously set in the time field is invalid, this will be set to
274 * @deprecated ICU 2.6. Use roll(UCalendarDateFields field, int32_t amount, UErrorCode& status) instead.
276 virtual void roll(EDateFields field
, int32_t amount
, UErrorCode
& status
);
281 static UBool
isLeapYear(int32_t year
) ;
286 * Subclass API for defining limits of different types.
287 * Subclasses must implement this method to return limits for the
295 * UCAL_DATE (DAY_OF_MONTH on Java)
297 * UCAL_DAY_OF_WEEK_IN_MONTH
299 * UCAL_EXTENDED_YEAR</pre>
301 * @param field one of the above field numbers
302 * @param limitType one of <code>MINIMUM</code>, <code>GREATEST_MINIMUM</code>,
303 * <code>LEAST_MAXIMUM</code>, or <code>MAXIMUM</code>
306 virtual int32_t handleGetLimit(UCalendarDateFields field
, ELimitType limitType
) const;
309 * Return the number of days in the given month of the given extended
310 * year of this calendar system. Subclasses should override this
311 * method if they can provide a more correct or more efficient
312 * implementation than the default implementation in Calendar.
315 virtual int32_t handleGetMonthLength(int32_t extendedYear
, int32_t month
) const;
318 * Return the number of days in the given extended year of this
319 * calendar system. Subclasses should override this method if they can
320 * provide a more correct or more efficient implementation than the
321 * default implementation in Calendar.
324 virtual int32_t handleGetYearLength(int32_t eyear
) const;
326 * Subclasses may override this method to compute several fields
327 * specific to each calendar system. These are:
334 * <li>EXTENDED_YEAR</ul>
336 * <p>The GregorianCalendar implementation implements
337 * a calendar with the specified Julian/Gregorian cutover date.
340 virtual void handleComputeFields(int32_t julianDay
, UErrorCode
&status
);
342 * Return the extended year defined by the current fields. This will
343 * use the UCAL_EXTENDED_YEAR field or the UCAL_YEAR and supra-year fields (such
344 * as UCAL_ERA) specific to the calendar system, depending on which set of
346 * @return the extended year
349 virtual int32_t handleGetExtendedYear();
351 * Return the Julian day number of day before the first day of the
352 * given month in the given extended year. Subclasses should override
353 * this method to implement their calendar system.
354 * @param eyear the extended year
355 * @param month the zero-based month, or 0 if useMonth is false
356 * @param useMonth if false, compute the day before the first day of
357 * the given year, otherwise, compute the day before the first day of
359 * @param return the Julian day number of the day before the first
360 * day of the given month and year
363 virtual int32_t handleComputeMonthStart(int32_t eyear
, int32_t month
,
364 UBool useMonth
) const;
368 * Validate a single field of this calendar.
369 * Overrides Calendar::validateField(int) to provide
370 * special handling for month validation for Hebrew calendar.
373 virtual void validateField(UCalendarDateFields field
, UErrorCode
&status
);
378 * (Overrides Calendar) Return true if the current date for this Calendar is in
379 * Daylight Savings Time. Recognizes DST_OFFSET, if it is set.
381 * @param status Fill-in parameter which receives the status of this operation.
382 * @return True if the current date for this Calendar is in Daylight Savings Time,
386 virtual UBool
inDaylightTime(UErrorCode
& status
) const;
389 * Returns TRUE because the Hebrew Calendar does have a default century
392 virtual UBool
haveDefaultCentury() const;
395 * Returns the date of the start of the default century
396 * @return start of century - in milliseconds since epoch, 1970
399 virtual UDate
defaultCenturyStart() const;
402 * Returns the year in which the default century begins
405 virtual int32_t defaultCenturyStartYear() const;
407 private: // Calendar-specific implementation
409 * Finds the day # of the first day in the given Hebrew year.
410 * To do this, we want to calculate the time of the Tishri 1 new moon
413 * The algorithm here is similar to ones described in a number of
414 * references, including:
416 * <li>"Calendrical Calculations", by Nachum Dershowitz & Edward Reingold,
417 * Cambridge University Press, 1997, pages 85-91.
419 * <li>Hebrew Calendar Science and Myths,
420 * <a href="http://www.geocities.com/Athens/1584/">
421 * http://www.geocities.com/Athens/1584/</a>
423 * <li>The Calendar FAQ,
424 * <a href="http://www.faqs.org/faqs/calendars/faq/">
425 * http://www.faqs.org/faqs/calendars/faq/</a>
427 * @param year extended year
428 * @return day number (JD)
431 static int32_t startOfYear(int32_t year
, UErrorCode
& status
);
433 static int32_t absoluteDayToDayOfWeek(int32_t day
) ;
438 int32_t yearType(int32_t year
) const;
443 static int32_t monthsInYear(int32_t year
) ;
448 #endif /* #if !UCONFIG_NO_FORMATTING */