intl/icu/source/i18n/hebrwcal.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial