2 * Copyright (C) 2003-2004, International Business Machines Corporation and others. All Rights Reserved.
3 ********************************************************************************
7 * Modification History:
9 * Date Name Description
10 * 05/13/2003 srl copied from gregocal.h
11 * 11/26/2003 srl copied from buddhcal.h
12 ********************************************************************************
18 #include "unicode/utypes.h"
20 #if !UCONFIG_NO_FORMATTING
22 #include "unicode/calendar.h"
23 #include "unicode/gregocal.h"
28 * <code>HebrewCalendar</code> is a subclass of <code>Calendar</code>
29 * that that implements the traditional Hebrew calendar.
30 * This is the civil calendar in Israel and the liturgical calendar
31 * of the Jewish faith worldwide.
33 * The Hebrew calendar is lunisolar and thus has a number of interesting
34 * properties that distinguish it from the Gregorian. Months start
35 * on the day of (an arithmetic approximation of) each new moon. Since the
36 * solar year (approximately 365.24 days) is not an even multiple of
37 * the lunar month (approximately 29.53 days) an extra "leap month" is
38 * inserted in 7 out of every 19 years. To make matters even more
39 * interesting, the start of a year can be delayed by up to three days
40 * in order to prevent certain holidays from falling on the Sabbath and
41 * to prevent certain illegal year lengths. Finally, the lengths of certain
42 * months can vary depending on the number of days in the year.
44 * The leap month is known as "Adar 1" and is inserted between the
45 * months of Shevat and Adar in leap years. Since the leap month does
46 * not come at the end of the year, calculations involving
47 * month numbers are particularly complex. Users of this class should
48 * make sure to use the {@link #roll roll} and {@link #add add} methods
49 * rather than attempting to perform date arithmetic by manipulating
50 * the fields directly.
52 * <b>Note:</b> In the traditional Hebrew calendar, days start at sunset.
53 * However, in order to keep the time fields in this class
54 * synchronized with those of the other calendars and with local clock time,
55 * we treat days and months as beginning at midnight,
56 * roughly 6 hours after the corresponding sunset.
58 * If you are interested in more information on the rules behind the Hebrew
59 * calendar, see one of the following references:
61 * <li>"<a href="http://www.amazon.com/exec/obidos/ASIN/0521564743">Calendrical Calculations</a>",
62 * by Nachum Dershowitz & Edward Reingold, Cambridge University Press, 1997, pages 85-91.
64 * <li>Hebrew Calendar Science and Myths,
65 * <a href="http://www.geocities.com/Athens/1584/">
66 * http://www.geocities.com/Athens/1584/</a>
68 * <li>The Calendar FAQ,
69 * <a href="http://www.faqs.org/faqs/calendars/faq/">
70 * http://www.faqs.org/faqs/calendars/faq/</a>
73 * @see com.ibm.icu.util.GregorianCalendar
75 * @author Laura Werner
77 * @author Steven R. Loomis
81 class U_I18N_API HebrewCalendar
: public Calendar
{
84 * Useful constants for HebrewCalendar.
89 * Constant for Tishri, the 1st month of the Hebrew year.
93 * Constant for Heshvan, the 2nd month of the Hebrew year.
97 * Constant for Kislev, the 3rd month of the Hebrew year.
102 * Constant for Tevet, the 4th month of the Hebrew year.
107 * Constant for Shevat, the 5th month of the Hebrew year.
112 * Constant for Adar I, the 6th month of the Hebrew year
113 * (present in leap years only). In non-leap years, the calendar
114 * jumps from Shevat (5th month) to Adar (7th month).
119 * Constant for the Adar, the 7th month of the Hebrew year.
124 * Constant for Nisan, the 8th month of the Hebrew year.
129 * Constant for Iyar, the 9th month of the Hebrew year.
134 * Constant for Sivan, the 10th month of the Hebrew year.
139 * Constant for Tammuz, the 11th month of the Hebrew year.
144 * Constant for Av, the 12th month of the Hebrew year.
149 * Constant for Elul, the 13th month of the Hebrew year.
155 * Constructs a HebrewCalendar based on the current time in the default time zone
156 * with the given locale.
158 * @param aLocale The given locale.
159 * @param success Indicates the status of HebrewCalendar object construction.
160 * Returns U_ZERO_ERROR if constructed successfully.
163 HebrewCalendar(const Locale
& aLocale
, UErrorCode
& success
);
170 virtual ~HebrewCalendar();
174 * @param source the object to be copied.
177 HebrewCalendar(const HebrewCalendar
& source
);
180 * Default assignment operator
181 * @param right the object to be copied.
184 HebrewCalendar
& operator=(const HebrewCalendar
& right
);
187 * Create and return a polymorphic copy of this calendar.
188 * @return return a polymorphic copy of this calendar.
191 virtual Calendar
* clone(void) const;
195 * Override Calendar Returns a unique class ID POLYMORPHICALLY. Pure virtual
196 * override. This method is to implement a simple version of RTTI, since not all C++
197 * compilers support genuine RTTI. Polymorphic operator==() and clone() methods call
200 * @return The class ID for this object. All objects of a given class have the
201 * same class ID. Objects of other classes have different class IDs.
204 virtual UClassID
getDynamicClassID(void) const;
207 * Return the class ID for this class. This is useful only for comparing to a return
208 * value from getDynamicClassID(). For example:
210 * Base* polymorphic_pointer = createPolymorphicObject();
211 * if (polymorphic_pointer->getDynamicClassID() ==
212 * Derived::getStaticClassID()) ...
214 * @return The class ID for all objects of this class.
217 static UClassID U_EXPORT2
getStaticClassID(void);
220 * return the calendar type, "hebrew".
222 * @return calendar type
225 virtual const char * getType() const;
231 * (Overrides Calendar) UDate Arithmetic function. Adds the specified (signed) amount
232 * of time to the given time field, based on the calendar's rules. For more
233 * information, see the documentation for Calendar::add().
235 * @param field The time field.
236 * @param amount The amount of date or time to be added to the field.
237 * @param status Output param set to success/failure code on exit. If any value
238 * previously set in the time field is invalid, this will be set to
241 virtual void add(UCalendarDateFields field
, int32_t amount
, UErrorCode
& status
);
243 * @deprecated ICU 2.6 use UCalendarDateFields instead of EDateFields
245 inline virtual void add(EDateFields field
, int32_t amount
, UErrorCode
& status
) { add((UCalendarDateFields
)field
, amount
, status
); }
249 * (Overrides Calendar) Rolls up or down by the given amount in the specified field.
250 * For more information, see the documentation for Calendar::roll().
252 * @param field The time field.
253 * @param amount Indicates amount to roll.
254 * @param status Output param set to success/failure code on exit. If any value
255 * previously set in the time field is invalid, this will be set to
259 virtual void roll(UCalendarDateFields field
, int32_t amount
, UErrorCode
& status
);
262 * (Overrides Calendar) Rolls up or down by the given amount in the specified field.
263 * For more information, see the documentation for Calendar::roll().
265 * @param field The time field.
266 * @param amount Indicates amount to roll.
267 * @param status Output param set to success/failure code on exit. If any value
268 * previously set in the time field is invalid, this will be set to
270 * @deprecated ICU 2.6. Use roll(UCalendarDateFields field, int32_t amount, UErrorCode& status) instead.
272 virtual void roll(EDateFields field
, int32_t amount
, UErrorCode
& status
);
278 * Subclass API for defining limits of different types.
279 * Subclasses must implement this method to return limits for the
287 * UCAL_DATE (DAY_OF_MONTH on Java)
289 * UCAL_DAY_OF_WEEK_IN_MONTH
291 * UCAL_EXTENDED_YEAR</pre>
293 * @param field one of the above field numbers
294 * @param limitType one of <code>MINIMUM</code>, <code>GREATEST_MINIMUM</code>,
295 * <code>LEAST_MAXIMUM</code>, or <code>MAXIMUM</code>
298 virtual int32_t handleGetLimit(UCalendarDateFields field
, ELimitType limitType
) const;
301 * Return the number of days in the given month of the given extended
302 * year of this calendar system. Subclasses should override this
303 * method if they can provide a more correct or more efficient
304 * implementation than the default implementation in Calendar.
307 virtual int32_t handleGetMonthLength(int32_t extendedYear
, int32_t month
) const;
310 * Return the number of days in the given extended year of this
311 * calendar system. Subclasses should override this method if they can
312 * provide a more correct or more efficient implementation than the
313 * default implementation in Calendar.
316 virtual int32_t handleGetYearLength(int32_t eyear
) const;
318 * Subclasses may override this method to compute several fields
319 * specific to each calendar system. These are:
326 * <li>EXTENDED_YEAR</ul>
328 * <p>The GregorianCalendar implementation implements
329 * a calendar with the specified Julian/Gregorian cutover date.
332 virtual void handleComputeFields(int32_t julianDay
, UErrorCode
&status
);
334 * Return the extended year defined by the current fields. This will
335 * use the UCAL_EXTENDED_YEAR field or the UCAL_YEAR and supra-year fields (such
336 * as UCAL_ERA) specific to the calendar system, depending on which set of
338 * @return the extended year
341 virtual int32_t handleGetExtendedYear();
343 * Return the Julian day number of day before the first day of the
344 * given month in the given extended year. Subclasses should override
345 * this method to implement their calendar system.
346 * @param eyear the extended year
347 * @param month the zero-based month, or 0 if useMonth is false
348 * @param useMonth if false, compute the day before the first day of
349 * the given year, otherwise, compute the day before the first day of
351 * @param return the Julian day number of the day before the first
352 * day of the given month and year
355 virtual int32_t handleComputeMonthStart(int32_t eyear
, int32_t month
,
356 UBool useMonth
) const;
363 * (Overrides Calendar) Return true if the current date for this Calendar is in
364 * Daylight Savings Time. Recognizes DST_OFFSET, if it is set.
366 * @param status Fill-in parameter which receives the status of this operation.
367 * @return True if the current date for this Calendar is in Daylight Savings Time,
371 virtual UBool
inDaylightTime(UErrorCode
& status
) const;
374 * Returns TRUE because the Hebrew Calendar does have a default century
377 virtual UBool
haveDefaultCentury() const;
380 * Returns the date of the start of the default century
381 * @return start of century - in milliseconds since epoch, 1970
384 virtual UDate
defaultCenturyStart() const;
387 * Returns the year in which the default century begins
390 virtual int32_t defaultCenturyStartYear() const;
392 private: // default century stuff.
394 * The system maintains a static default century start date. This is initialized
395 * the first time it is used. Before then, it is set to SYSTEM_DEFAULT_CENTURY to
396 * indicate an uninitialized state. Once the system default century date and year
397 * are set, they do not change.
399 static UDate fgSystemDefaultCenturyStart
;
402 * See documentation for systemDefaultCenturyStart.
404 static int32_t fgSystemDefaultCenturyStartYear
;
407 * Default value that indicates the defaultCenturyStartYear is unitialized
409 static const int32_t fgSystemDefaultCenturyYear
;
412 * start of default century, as a date
414 static const UDate fgSystemDefaultCentury
;
417 * Returns the beginning date of the 100-year window that dates
418 * with 2-digit years are considered to fall within.
420 UDate
internalGetDefaultCenturyStart(void) const;
423 * Returns the first year of the 100-year window that dates with
424 * 2-digit years are considered to fall within.
426 int32_t internalGetDefaultCenturyStartYear(void) const;
429 * Initializes the 100-year window that dates with 2-digit years
430 * are considered to fall within so that its start date is 80 years
431 * before the current time.
433 static void initializeSystemDefaultCentury(void);
435 private: // Calendar-specific implementation
437 * Finds the day # of the first day in the given Hebrew year.
438 * To do this, we want to calculate the time of the Tishri 1 new moon
441 * The algorithm here is similar to ones described in a number of
442 * references, including:
444 * <li>"Calendrical Calculations", by Nachum Dershowitz & Edward Reingold,
445 * Cambridge University Press, 1997, pages 85-91.
447 * <li>Hebrew Calendar Science and Myths,
448 * <a href="http://www.geocities.com/Athens/1584/">
449 * http://www.geocities.com/Athens/1584/</a>
451 * <li>The Calendar FAQ,
452 * <a href="http://www.faqs.org/faqs/calendars/faq/">
453 * http://www.faqs.org/faqs/calendars/faq/</a>
455 * @param year extended year
456 * @return day number (JD)
459 static int32_t startOfYear(int32_t year
, UErrorCode
& status
);
461 static int32_t absoluteDayToDayOfWeek(int32_t day
) ;
466 int32_t yearType(int32_t year
) const;
471 static UBool
isLeapYear(int32_t year
) ;
475 static int32_t monthsInYear(int32_t year
) ;
480 #endif /* #if !UCONFIG_NO_FORMATTING */