intl/icu/source/i18n/hebrwcal.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/icu/source/i18n/hebrwcal.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,443 @@
     1.4 +/*
     1.5 +******************************************************************************
     1.6 +* Copyright (C) 2003-2013, International Business Machines Corporation
     1.7 +* and others. All Rights Reserved.
     1.8 +******************************************************************************
     1.9 +*
    1.10 +* File HEBRWCAL.H
    1.11 +*
    1.12 +* Modification History:
    1.13 +*
    1.14 +*   Date        Name        Description
    1.15 +*   05/13/2003  srl          copied from gregocal.h
    1.16 +*   11/26/2003  srl          copied from buddhcal.h
    1.17 +******************************************************************************
    1.18 +*/
    1.19 +
    1.20 +#ifndef HEBRWCAL_H
    1.21 +#define HEBRWCAL_H
    1.22 +
    1.23 +#include "unicode/utypes.h"
    1.24 +
    1.25 +#if !UCONFIG_NO_FORMATTING
    1.26 +
    1.27 +#include "unicode/calendar.h"
    1.28 +#include "unicode/gregocal.h"
    1.29 +
    1.30 +U_NAMESPACE_BEGIN
    1.31 +
    1.32 +/**
    1.33 + * <code>HebrewCalendar</code> is a subclass of <code>Calendar</code>
    1.34 + * that that implements the traditional Hebrew calendar.
    1.35 + * This is the civil calendar in Israel and the liturgical calendar
    1.36 + * of the Jewish faith worldwide.
    1.37 + * <p>
    1.38 + * The Hebrew calendar is lunisolar and thus has a number of interesting
    1.39 + * properties that distinguish it from the Gregorian.  Months start
    1.40 + * on the day of (an arithmetic approximation of) each new moon.  Since the
    1.41 + * solar year (approximately 365.24 days) is not an even multiple of
    1.42 + * the lunar month (approximately 29.53 days) an extra "leap month" is
    1.43 + * inserted in 7 out of every 19 years.  To make matters even more
    1.44 + * interesting, the start of a year can be delayed by up to three days
    1.45 + * in order to prevent certain holidays from falling on the Sabbath and
    1.46 + * to prevent certain illegal year lengths.  Finally, the lengths of certain
    1.47 + * months can vary depending on the number of days in the year.
    1.48 + * <p>
    1.49 + * The leap month is known as "Adar 1" and is inserted between the
    1.50 + * months of Shevat and Adar in leap years.  Since the leap month does
    1.51 + * not come at the end of the year, calculations involving
    1.52 + * month numbers are particularly complex.  Users of this class should
    1.53 + * make sure to use the {@link #roll roll} and {@link #add add} methods
    1.54 + * rather than attempting to perform date arithmetic by manipulating
    1.55 + * the fields directly.
    1.56 + * <p>
    1.57 + * <b>Note:</b> In the traditional Hebrew calendar, days start at sunset.
    1.58 + * However, in order to keep the time fields in this class
    1.59 + * synchronized with those of the other calendars and with local clock time,
    1.60 + * we treat days and months as beginning at midnight,
    1.61 + * roughly 6 hours after the corresponding sunset.
    1.62 + * <p>
    1.63 + * If you are interested in more information on the rules behind the Hebrew
    1.64 + * calendar, see one of the following references:
    1.65 + * <ul>
    1.66 + * <li>"<a href="http://www.amazon.com/exec/obidos/ASIN/0521564743">Calendrical Calculations</a>",
    1.67 + *      by Nachum Dershowitz & Edward Reingold, Cambridge University Press, 1997, pages 85-91.
    1.68 + *
    1.69 + * <li>Hebrew Calendar Science and Myths,
    1.70 + *      <a href="http://www.geocities.com/Athens/1584/">
    1.71 + *      http://www.geocities.com/Athens/1584/</a>
    1.72 + *
    1.73 + * <li>The Calendar FAQ,
    1.74 + *      <a href="http://www.faqs.org/faqs/calendars/faq/">
    1.75 + *      http://www.faqs.org/faqs/calendars/faq/</a>
    1.76 + * </ul>
    1.77 + * <p>
    1.78 + * @see com.ibm.icu.util.GregorianCalendar
    1.79 + *
    1.80 + * @author Laura Werner
    1.81 + * @author Alan Liu
    1.82 + * @author Steven R. Loomis
    1.83 + * <p>
    1.84 + * @internal
    1.85 + */
    1.86 +class U_I18N_API HebrewCalendar : public Calendar {
    1.87 +public:
    1.88 +  /**
    1.89 +   * Useful constants for HebrewCalendar.
    1.90 +   * @internal
    1.91 +   */
    1.92 +  enum EEras {
    1.93 +    /** 
    1.94 +     * Constant for Tishri, the 1st month of the Hebrew year. 
    1.95 +     */
    1.96 +      TISHRI,
    1.97 +      /**
    1.98 +     * Constant for Heshvan, the 2nd month of the Hebrew year. 
    1.99 +     */
   1.100 +      HESHVAN,
   1.101 +      /**
   1.102 +     * Constant for Kislev, the 3rd month of the Hebrew year. 
   1.103 +     */
   1.104 +      KISLEV,
   1.105 +
   1.106 +    /**
   1.107 +     * Constant for Tevet, the 4th month of the Hebrew year. 
   1.108 +     */
   1.109 +      TEVET,
   1.110 +
   1.111 +    /**
   1.112 +     * Constant for Shevat, the 5th month of the Hebrew year. 
   1.113 +     */
   1.114 +      SHEVAT,
   1.115 +
   1.116 +    /**
   1.117 +     * Constant for Adar I, the 6th month of the Hebrew year
   1.118 +     * (present in leap years only). In non-leap years, the calendar
   1.119 +     * jumps from Shevat (5th month) to Adar (7th month).
   1.120 +     */
   1.121 +      ADAR_1,
   1.122 +
   1.123 +    /** 
   1.124 +     * Constant for the Adar, the 7th month of the Hebrew year. 
   1.125 +     */
   1.126 +      ADAR,
   1.127 +
   1.128 +    /**
   1.129 +     * Constant for Nisan, the 8th month of the Hebrew year. 
   1.130 +     */
   1.131 +      NISAN,
   1.132 +
   1.133 +    /**
   1.134 +     * Constant for Iyar, the 9th month of the Hebrew year. 
   1.135 +     */
   1.136 +      IYAR,
   1.137 +
   1.138 +    /**
   1.139 +     * Constant for Sivan, the 10th month of the Hebrew year. 
   1.140 +     */
   1.141 +      SIVAN,
   1.142 +
   1.143 +    /**
   1.144 +     * Constant for Tammuz, the 11th month of the Hebrew year. 
   1.145 +     */
   1.146 +      TAMUZ,
   1.147 +
   1.148 +    /**
   1.149 +     * Constant for Av, the 12th month of the Hebrew year. 
   1.150 +     */
   1.151 +      AV,
   1.152 +
   1.153 +    /**
   1.154 +     * Constant for Elul, the 13th month of the Hebrew year. 
   1.155 +     */
   1.156 +      ELUL
   1.157 +    };
   1.158 +
   1.159 +    /**
   1.160 +     * Constructs a HebrewCalendar based on the current time in the default time zone
   1.161 +     * with the given locale.
   1.162 +     *
   1.163 +     * @param aLocale  The given locale.
   1.164 +     * @param success  Indicates the status of HebrewCalendar object construction.
   1.165 +     *                 Returns U_ZERO_ERROR if constructed successfully.
   1.166 +     * @internal
   1.167 +     */
   1.168 +    HebrewCalendar(const Locale& aLocale, UErrorCode& success);
   1.169 +
   1.170 +
   1.171 +    /**
   1.172 +     * Destructor
   1.173 +     * @internal
   1.174 +     */
   1.175 +    virtual ~HebrewCalendar();
   1.176 +
   1.177 +    /**
   1.178 +     * Copy constructor
   1.179 +     * @param source    the object to be copied.
   1.180 +     * @internal
   1.181 +     */
   1.182 +    HebrewCalendar(const HebrewCalendar& source);
   1.183 +
   1.184 +    /**
   1.185 +     * Default assignment operator
   1.186 +     * @param right    the object to be copied.
   1.187 +     * @internal
   1.188 +     */
   1.189 +    HebrewCalendar& operator=(const HebrewCalendar& right);
   1.190 +
   1.191 +    /**
   1.192 +     * Create and return a polymorphic copy of this calendar.
   1.193 +     * @return    return a polymorphic copy of this calendar.
   1.194 +     * @internal
   1.195 +     */
   1.196 +    virtual Calendar* clone(void) const;
   1.197 +    
   1.198 +public:
   1.199 +    /**
   1.200 +     * Override Calendar Returns a unique class ID POLYMORPHICALLY. Pure virtual
   1.201 +     * override. This method is to implement a simple version of RTTI, since not all C++
   1.202 +     * compilers support genuine RTTI. Polymorphic operator==() and clone() methods call
   1.203 +     * this method.
   1.204 +     *
   1.205 +     * @return   The class ID for this object. All objects of a given class have the
   1.206 +     *           same class ID. Objects of other classes have different class IDs.
   1.207 +     * @internal
   1.208 +     */
   1.209 +    virtual UClassID getDynamicClassID(void) const;
   1.210 +
   1.211 +    /**
   1.212 +     * Return the class ID for this class. This is useful only for comparing to a return
   1.213 +     * value from getDynamicClassID(). For example:
   1.214 +     *
   1.215 +     *      Base* polymorphic_pointer = createPolymorphicObject();
   1.216 +     *      if (polymorphic_pointer->getDynamicClassID() ==
   1.217 +     *          Derived::getStaticClassID()) ...
   1.218 +     *
   1.219 +     * @return   The class ID for all objects of this class.
   1.220 +     * @internal
   1.221 +     */
   1.222 +    static UClassID U_EXPORT2 getStaticClassID(void);
   1.223 +
   1.224 +    /**
   1.225 +     * return the calendar type, "hebrew".
   1.226 +     *
   1.227 +     * @return calendar type
   1.228 +     * @internal
   1.229 +     */
   1.230 +    virtual const char * getType() const;
   1.231 +
   1.232 +
   1.233 +    // Calendar API
   1.234 + public:
   1.235 +    /**
   1.236 +     * (Overrides Calendar) UDate Arithmetic function. Adds the specified (signed) amount
   1.237 +     * of time to the given time field, based on the calendar's rules.  For more
   1.238 +     * information, see the documentation for Calendar::add().
   1.239 +     *
   1.240 +     * @param field   The time field.
   1.241 +     * @param amount  The amount of date or time to be added to the field.
   1.242 +     * @param status  Output param set to success/failure code on exit. If any value
   1.243 +     *                previously set in the time field is invalid, this will be set to
   1.244 +     *                an error status.
   1.245 +     */
   1.246 +    virtual void add(UCalendarDateFields field, int32_t amount, UErrorCode& status);
   1.247 +    /**
   1.248 +     * @deprecated ICU 2.6 use UCalendarDateFields instead of EDateFields
   1.249 +     */
   1.250 +    virtual void add(EDateFields field, int32_t amount, UErrorCode& status);
   1.251 +
   1.252 +
   1.253 +    /**
   1.254 +     * (Overrides Calendar) Rolls up or down by the given amount in the specified field.
   1.255 +     * For more information, see the documentation for Calendar::roll().
   1.256 +     *
   1.257 +     * @param field   The time field.
   1.258 +     * @param amount  Indicates amount to roll.
   1.259 +     * @param status  Output param set to success/failure code on exit. If any value
   1.260 +     *                previously set in the time field is invalid, this will be set to
   1.261 +     *                an error status.
   1.262 +     * @internal
   1.263 +     */
   1.264 +    virtual void roll(UCalendarDateFields field, int32_t amount, UErrorCode& status);
   1.265 +
   1.266 +    /**
   1.267 +     * (Overrides Calendar) Rolls up or down by the given amount in the specified field.
   1.268 +     * For more information, see the documentation for Calendar::roll().
   1.269 +     *
   1.270 +     * @param field   The time field.
   1.271 +     * @param amount  Indicates amount to roll.
   1.272 +     * @param status  Output param set to success/failure code on exit. If any value
   1.273 +     *                previously set in the time field is invalid, this will be set to
   1.274 +     *                an error status.
   1.275 +     * @deprecated ICU 2.6. Use roll(UCalendarDateFields field, int32_t amount, UErrorCode& status) instead.
   1.276 +`     */
   1.277 +    virtual void roll(EDateFields field, int32_t amount, UErrorCode& status);
   1.278 +
   1.279 +    /**
   1.280 +     * @internal 
   1.281 +     */
   1.282 +    static UBool isLeapYear(int32_t year) ;
   1.283 +
   1.284 + protected:
   1.285 +
   1.286 +    /**
   1.287 +     * Subclass API for defining limits of different types.
   1.288 +     * Subclasses must implement this method to return limits for the
   1.289 +     * following fields:
   1.290 +     *
   1.291 +     * <pre>UCAL_ERA
   1.292 +     * UCAL_YEAR
   1.293 +     * UCAL_MONTH
   1.294 +     * UCAL_WEEK_OF_YEAR
   1.295 +     * UCAL_WEEK_OF_MONTH
   1.296 +     * UCAL_DATE (DAY_OF_MONTH on Java)
   1.297 +     * UCAL_DAY_OF_YEAR
   1.298 +     * UCAL_DAY_OF_WEEK_IN_MONTH
   1.299 +     * UCAL_YEAR_WOY
   1.300 +     * UCAL_EXTENDED_YEAR</pre>
   1.301 +     *
   1.302 +     * @param field one of the above field numbers
   1.303 +     * @param limitType one of <code>MINIMUM</code>, <code>GREATEST_MINIMUM</code>,
   1.304 +     * <code>LEAST_MAXIMUM</code>, or <code>MAXIMUM</code>
   1.305 +     * @internal
   1.306 +     */
   1.307 +    virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const;
   1.308 +
   1.309 +    /**
   1.310 +     * Return the number of days in the given month of the given extended
   1.311 +     * year of this calendar system.  Subclasses should override this
   1.312 +     * method if they can provide a more correct or more efficient
   1.313 +     * implementation than the default implementation in Calendar.
   1.314 +     * @internal
   1.315 +     */
   1.316 +    virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month) const;
   1.317 +
   1.318 +    /**
   1.319 +     * Return the number of days in the given extended year of this
   1.320 +     * calendar system.  Subclasses should override this method if they can
   1.321 +     * provide a more correct or more efficient implementation than the
   1.322 +     * default implementation in Calendar.
   1.323 +     * @stable ICU 2.0
   1.324 +     */
   1.325 +    virtual int32_t handleGetYearLength(int32_t eyear) const;
   1.326 +    /**
   1.327 +     * Subclasses may override this method to compute several fields
   1.328 +     * specific to each calendar system.  These are:
   1.329 +     *
   1.330 +     * <ul><li>ERA
   1.331 +     * <li>YEAR
   1.332 +     * <li>MONTH
   1.333 +     * <li>DAY_OF_MONTH
   1.334 +     * <li>DAY_OF_YEAR
   1.335 +     * <li>EXTENDED_YEAR</ul>
   1.336 +     *
   1.337 +     * <p>The GregorianCalendar implementation implements
   1.338 +     * a calendar with the specified Julian/Gregorian cutover date.
   1.339 +     * @internal
   1.340 +     */
   1.341 +    virtual void handleComputeFields(int32_t julianDay, UErrorCode &status);
   1.342 +    /**
   1.343 +     * Return the extended year defined by the current fields.  This will
   1.344 +     * use the UCAL_EXTENDED_YEAR field or the UCAL_YEAR and supra-year fields (such
   1.345 +     * as UCAL_ERA) specific to the calendar system, depending on which set of
   1.346 +     * fields is newer.
   1.347 +     * @return the extended year
   1.348 +     * @internal
   1.349 +     */
   1.350 +    virtual int32_t handleGetExtendedYear();
   1.351 +    /**
   1.352 +     * Return the Julian day number of day before the first day of the
   1.353 +     * given month in the given extended year.  Subclasses should override
   1.354 +     * this method to implement their calendar system.
   1.355 +     * @param eyear the extended year
   1.356 +     * @param month the zero-based month, or 0 if useMonth is false
   1.357 +     * @param useMonth if false, compute the day before the first day of
   1.358 +     * the given year, otherwise, compute the day before the first day of
   1.359 +     * the given month
   1.360 +     * @param return the Julian day number of the day before the first
   1.361 +     * day of the given month and year
   1.362 +     * @internal
   1.363 +     */
   1.364 +    virtual int32_t handleComputeMonthStart(int32_t eyear, int32_t month,
   1.365 +                                                   UBool useMonth) const;
   1.366 +
   1.367 +
   1.368 +
   1.369 + protected:
   1.370 +
   1.371 +  /**
   1.372 +   * (Overrides Calendar) Return true if the current date for this Calendar is in
   1.373 +   * Daylight Savings Time. Recognizes DST_OFFSET, if it is set.
   1.374 +   *
   1.375 +   * @param status Fill-in parameter which receives the status of this operation.
   1.376 +   * @return   True if the current date for this Calendar is in Daylight Savings Time,
   1.377 +   *           false, otherwise.
   1.378 +   * @internal
   1.379 +   */
   1.380 +  virtual UBool inDaylightTime(UErrorCode& status) const;
   1.381 +
   1.382 +    /**
   1.383 +     * Returns TRUE because the Hebrew Calendar does have a default century
   1.384 +     * @internal
   1.385 +     */
   1.386 +    virtual UBool haveDefaultCentury() const;
   1.387 +
   1.388 +    /**
   1.389 +     * Returns the date of the start of the default century
   1.390 +     * @return start of century - in milliseconds since epoch, 1970
   1.391 +     * @internal
   1.392 +     */
   1.393 +    virtual UDate defaultCenturyStart() const;
   1.394 +
   1.395 +    /**
   1.396 +     * Returns the year in which the default century begins
   1.397 +     * @internal
   1.398 +     */
   1.399 +    virtual int32_t defaultCenturyStartYear() const;
   1.400 +
   1.401 + private: // Calendar-specific implementation
   1.402 +    /**
   1.403 +     * Finds the day # of the first day in the given Hebrew year.
   1.404 +     * To do this, we want to calculate the time of the Tishri 1 new moon
   1.405 +     * in that year.
   1.406 +     * <p>
   1.407 +     * The algorithm here is similar to ones described in a number of
   1.408 +     * references, including:
   1.409 +     * <ul>
   1.410 +     * <li>"Calendrical Calculations", by Nachum Dershowitz & Edward Reingold,
   1.411 +     *     Cambridge University Press, 1997, pages 85-91.
   1.412 +     *
   1.413 +     * <li>Hebrew Calendar Science and Myths,
   1.414 +     *     <a href="http://www.geocities.com/Athens/1584/">
   1.415 +     *     http://www.geocities.com/Athens/1584/</a>
   1.416 +     *
   1.417 +     * <li>The Calendar FAQ,
   1.418 +     *      <a href="http://www.faqs.org/faqs/calendars/faq/">
   1.419 +     *      http://www.faqs.org/faqs/calendars/faq/</a>
   1.420 +     * </ul>
   1.421 +     * @param year extended year
   1.422 +     * @return day number (JD)
   1.423 +     * @internal
   1.424 +     */
   1.425 +    static int32_t startOfYear(int32_t year, UErrorCode& status);
   1.426 +
   1.427 +    static int32_t absoluteDayToDayOfWeek(int32_t day) ;
   1.428 +    
   1.429 +    /**
   1.430 +     * @internal 
   1.431 +     */
   1.432 +    int32_t yearType(int32_t year) const;
   1.433 +
   1.434 +    /**
   1.435 +     * @internal 
   1.436 +     */
   1.437 +    static int32_t monthsInYear(int32_t year) ;
   1.438 +};
   1.439 +
   1.440 +U_NAMESPACE_END
   1.441 +
   1.442 +#endif /* #if !UCONFIG_NO_FORMATTING */
   1.443 +
   1.444 +#endif 
   1.445 +//eof
   1.446 +

mercurial