intl/icu/source/i18n/islamcal.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/icu/source/i18n/islamcal.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,429 @@
     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 ISLAMCAL.H
    1.11 + *
    1.12 + * Modification History:
    1.13 + *
    1.14 + *   Date        Name        Description
    1.15 + *   10/14/2003  srl         ported from java IslamicCalendar
    1.16 + *****************************************************************************
    1.17 + */
    1.18 +
    1.19 +#ifndef ISLAMCAL_H
    1.20 +#define ISLAMCAL_H
    1.21 +
    1.22 +#include "unicode/utypes.h"
    1.23 +
    1.24 +#if !UCONFIG_NO_FORMATTING
    1.25 +
    1.26 +#include "unicode/calendar.h"
    1.27 +
    1.28 +U_NAMESPACE_BEGIN
    1.29 +
    1.30 +/**
    1.31 + * <code>IslamicCalendar</code> is a subclass of <code>Calendar</code>
    1.32 + * that implements the Islamic civil and religious calendars.  It
    1.33 + * is used as the civil calendar in most of the Arab world and the
    1.34 + * liturgical calendar of the Islamic faith worldwide.  This calendar
    1.35 + * is also known as the "Hijri" calendar, since it starts at the time
    1.36 + * of Mohammed's emigration (or "hijra") to Medinah on Thursday, 
    1.37 + * July 15, 622 AD (Julian).
    1.38 + * <p>
    1.39 + * The Islamic calendar is strictly lunar, and thus an Islamic year of twelve
    1.40 + * lunar months does not correspond to the solar year used by most other
    1.41 + * calendar systems, including the Gregorian.  An Islamic year is, on average,
    1.42 + * about 354 days long, so each successive Islamic year starts about 11 days
    1.43 + * earlier in the corresponding Gregorian year.
    1.44 + * <p>
    1.45 + * Each month of the calendar starts when the new moon's crescent is visible
    1.46 + * at sunset.  However, in order to keep the time fields in this class
    1.47 + * synchronized with those of the other calendars and with local clock time,
    1.48 + * we treat days and months as beginning at midnight,
    1.49 + * roughly 6 hours after the corresponding sunset.
    1.50 + * <p>
    1.51 + * There are two main variants of the Islamic calendar in existence.  The first
    1.52 + * is the <em>civil</em> calendar, which uses a fixed cycle of alternating 29-
    1.53 + * and 30-day months, with a leap day added to the last month of 11 out of
    1.54 + * every 30 years.  This calendar is easily calculated and thus predictable in
    1.55 + * advance, so it is used as the civil calendar in a number of Arab countries.
    1.56 + * This is the default behavior of a newly-created <code>IslamicCalendar</code>
    1.57 + * object.
    1.58 + * <p>
    1.59 + * The Islamic <em>religious</em> calendar, however, is based on the <em>observation</em>
    1.60 + * of the crescent moon.  It is thus affected by the position at which the
    1.61 + * observations are made, seasonal variations in the time of sunset, the
    1.62 + * eccentricities of the moon's orbit, and even the weather at the observation
    1.63 + * site.  This makes it impossible to calculate in advance, and it causes the
    1.64 + * start of a month in the religious calendar to differ from the civil calendar
    1.65 + * by up to three days.
    1.66 + * <p>
    1.67 + * Using astronomical calculations for the position of the sun and moon, the
    1.68 + * moon's illumination, and other factors, it is possible to determine the start
    1.69 + * of a lunar month with a fairly high degree of certainty.  However, these
    1.70 + * calculations are extremely complicated and thus slow, so most algorithms,
    1.71 + * including the one used here, are only approximations of the true astronical
    1.72 + * calculations.  At present, the approximations used in this class are fairly
    1.73 + * simplistic; they will be improved in later versions of the code.
    1.74 + * <p>
    1.75 + * The {@link #setCivil setCivil} method determines
    1.76 + * which approach is used to determine the start of a month.  By default, the
    1.77 + * fixed-cycle civil calendar is used.  However, if <code>setCivil(false)</code>
    1.78 + * is called, an approximation of the true lunar calendar will be used.
    1.79 + *
    1.80 + * @see GregorianCalendar
    1.81 + *
    1.82 + * @author Laura Werner
    1.83 + * @author Alan Liu
    1.84 + * @author Steven R. Loomis
    1.85 + * @internal
    1.86 + */
    1.87 +class U_I18N_API IslamicCalendar : public Calendar {
    1.88 + public:
    1.89 +  //-------------------------------------------------------------------------
    1.90 +  // Constants...
    1.91 +  //-------------------------------------------------------------------------
    1.92 +  
    1.93 +  /**
    1.94 +   * Calendar type - civil or religious or um alqura
    1.95 +   * @internal 
    1.96 +   */
    1.97 +  enum ECalculationType {
    1.98 +    ASTRONOMICAL,
    1.99 +    CIVIL,
   1.100 +    UMALQURA,
   1.101 +    TBLA
   1.102 +  };
   1.103 +  
   1.104 +  /**
   1.105 +   * Constants for the months
   1.106 +   * @internal
   1.107 +   */
   1.108 +  enum EMonths {
   1.109 +    /**
   1.110 +     * Constant for Muharram, the 1st month of the Islamic year. 
   1.111 +     * @internal
   1.112 +     */
   1.113 +    MUHARRAM = 0,
   1.114 +
   1.115 +    /**
   1.116 +     * Constant for Safar, the 2nd month of the Islamic year. 
   1.117 +     * @internal
   1.118 +     */
   1.119 +    SAFAR = 1,
   1.120 +
   1.121 +    /**
   1.122 +     * Constant for Rabi' al-awwal (or Rabi' I), the 3rd month of the Islamic year. 
   1.123 +     * @internal 
   1.124 +     */
   1.125 +    RABI_1 = 2,
   1.126 +
   1.127 +    /**
   1.128 +     * Constant for Rabi' al-thani or (Rabi' II), the 4th month of the Islamic year. 
   1.129 +     * @internal 
   1.130 +     */
   1.131 +    RABI_2 = 3,
   1.132 +
   1.133 +    /**
   1.134 +     * Constant for Jumada al-awwal or (Jumada I), the 5th month of the Islamic year. 
   1.135 +     * @internal 
   1.136 +     */
   1.137 +    JUMADA_1 = 4,
   1.138 +
   1.139 +    /**
   1.140 +     * Constant for Jumada al-thani or (Jumada II), the 6th month of the Islamic year. 
   1.141 +     * @internal 
   1.142 +     */
   1.143 +    JUMADA_2 = 5,
   1.144 +
   1.145 +    /**
   1.146 +     * Constant for Rajab, the 7th month of the Islamic year. 
   1.147 +     * @internal 
   1.148 +     */
   1.149 +    RAJAB = 6,
   1.150 +
   1.151 +    /**
   1.152 +     * Constant for Sha'ban, the 8th month of the Islamic year. 
   1.153 +     * @internal 
   1.154 +     */
   1.155 +    SHABAN = 7,
   1.156 +
   1.157 +    /**
   1.158 +     * Constant for Ramadan, the 9th month of the Islamic year. 
   1.159 +     * @internal 
   1.160 +     */
   1.161 +    RAMADAN = 8,
   1.162 +
   1.163 +    /**
   1.164 +     * Constant for Shawwal, the 10th month of the Islamic year. 
   1.165 +     * @internal 
   1.166 +     */
   1.167 +    SHAWWAL = 9,
   1.168 +
   1.169 +    /**
   1.170 +     * Constant for Dhu al-Qi'dah, the 11th month of the Islamic year. 
   1.171 +     * @internal 
   1.172 +     */
   1.173 +    DHU_AL_QIDAH = 10,
   1.174 +
   1.175 +    /**
   1.176 +     * Constant for Dhu al-Hijjah, the 12th month of the Islamic year. 
   1.177 +     * @internal 
   1.178 +     */
   1.179 +    DHU_AL_HIJJAH = 11,
   1.180 +    
   1.181 +    ISLAMIC_MONTH_MAX
   1.182 +  }; 
   1.183 +
   1.184 +
   1.185 +  //-------------------------------------------------------------------------
   1.186 +  // Constructors...
   1.187 +  //-------------------------------------------------------------------------
   1.188 +
   1.189 +  /**
   1.190 +   * Constructs an IslamicCalendar based on the current time in the default time zone
   1.191 +   * with the given locale.
   1.192 +   *
   1.193 +   * @param aLocale  The given locale.
   1.194 +   * @param success  Indicates the status of IslamicCalendar object construction.
   1.195 +   *                 Returns U_ZERO_ERROR if constructed successfully.
   1.196 +   * @param type     The Islamic calendar calculation type. The default value is CIVIL.
   1.197 +   * @internal
   1.198 +   */
   1.199 +  IslamicCalendar(const Locale& aLocale, UErrorCode &success, ECalculationType type = CIVIL);
   1.200 +
   1.201 +  /**
   1.202 +   * Copy Constructor
   1.203 +   * @internal
   1.204 +   */
   1.205 +  IslamicCalendar(const IslamicCalendar& other);
   1.206 +
   1.207 +  /**
   1.208 +   * Destructor.
   1.209 +   * @internal
   1.210 +   */
   1.211 +  virtual ~IslamicCalendar();
   1.212 +
   1.213 +  /**
   1.214 +   * Sets Islamic calendar calculation type used by this instance.
   1.215 +   *
   1.216 +   * @param type    The calendar calculation type, <code>CIVIL</code> to use the civil
   1.217 +   *                calendar, <code>ASTRONOMICAL</code> to use the astronomical calendar.
   1.218 +   * @internal
   1.219 +   */
   1.220 +  void setCalculationType(ECalculationType type, UErrorCode &status);
   1.221 +    
   1.222 +  /**
   1.223 +   * Returns <code>true</code> if this object is using the fixed-cycle civil
   1.224 +   * calendar, or <code>false</code> if using the religious, astronomical
   1.225 +   * calendar.
   1.226 +   * @internal
   1.227 +   */
   1.228 +  UBool isCivil();
   1.229 +
   1.230 +
   1.231 +  // TODO: copy c'tor, etc
   1.232 +
   1.233 +  // clone
   1.234 +  virtual Calendar* clone() const;
   1.235 +
   1.236 + private:
   1.237 +  /**
   1.238 +   * Determine whether a year is a leap year in the Islamic civil calendar
   1.239 +   */
   1.240 +  static UBool civilLeapYear(int32_t year);
   1.241 +    
   1.242 +  /**
   1.243 +   * Return the day # on which the given year starts.  Days are counted
   1.244 +   * from the Hijri epoch, origin 0.
   1.245 +   */
   1.246 +  int32_t yearStart(int32_t year) const;
   1.247 +
   1.248 +  /**
   1.249 +   * Return the day # on which the given month starts.  Days are counted
   1.250 +   * from the Hijri epoch, origin 0.
   1.251 +   *
   1.252 +   * @param year  The hijri year
   1.253 +   * @param year  The hijri month, 0-based
   1.254 +   */
   1.255 +  int32_t monthStart(int32_t year, int32_t month) const;
   1.256 +    
   1.257 +  /**
   1.258 +   * Find the day number on which a particular month of the true/lunar
   1.259 +   * Islamic calendar starts.
   1.260 +   *
   1.261 +   * @param month The month in question, origin 0 from the Hijri epoch
   1.262 +   *
   1.263 +   * @return The day number on which the given month starts.
   1.264 +   */
   1.265 +  int32_t trueMonthStart(int32_t month) const;
   1.266 +
   1.267 +  /**
   1.268 +   * Return the "age" of the moon at the given time; this is the difference
   1.269 +   * in ecliptic latitude between the moon and the sun.  This method simply
   1.270 +   * calls CalendarAstronomer.moonAge, converts to degrees, 
   1.271 +   * and adjusts the resultto be in the range [-180, 180].
   1.272 +   *
   1.273 +   * @param time  The time at which the moon's age is desired,
   1.274 +   *              in millis since 1/1/1970.
   1.275 +   */
   1.276 +  static double moonAge(UDate time, UErrorCode &status);
   1.277 +
   1.278 +  //-------------------------------------------------------------------------
   1.279 +  // Internal data....
   1.280 +  //
   1.281 +    
   1.282 +  /**
   1.283 +   * <code>CIVIL</code> if this object uses the fixed-cycle Islamic civil calendar,
   1.284 +   * and <code>ASTRONOMICAL</code> if it approximates the true religious calendar using
   1.285 +   * astronomical calculations for the time of the new moon.
   1.286 +   */
   1.287 +  ECalculationType cType;
   1.288 +
   1.289 +  //----------------------------------------------------------------------
   1.290 +  // Calendar framework
   1.291 +  //----------------------------------------------------------------------
   1.292 + protected:
   1.293 +  /**
   1.294 +   * @internal
   1.295 +   */
   1.296 +  virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const;
   1.297 +  
   1.298 +  /**
   1.299 +   * Return the length (in days) of the given month.
   1.300 +   *
   1.301 +   * @param year  The hijri year
   1.302 +   * @param year  The hijri month, 0-based
   1.303 +   * @internal
   1.304 +   */
   1.305 +  virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month) const;
   1.306 +  
   1.307 +  /**
   1.308 +   * Return the number of days in the given Islamic year
   1.309 +   * @internal
   1.310 +   */
   1.311 +  virtual int32_t handleGetYearLength(int32_t extendedYear) const;
   1.312 +    
   1.313 +  //-------------------------------------------------------------------------
   1.314 +  // Functions for converting from field values to milliseconds....
   1.315 +  //-------------------------------------------------------------------------
   1.316 +
   1.317 +  // Return JD of start of given month/year
   1.318 +  /**
   1.319 +   * @internal
   1.320 +   */
   1.321 +  virtual int32_t handleComputeMonthStart(int32_t eyear, int32_t month, UBool useMonth) const;
   1.322 +
   1.323 +  //-------------------------------------------------------------------------
   1.324 +  // Functions for converting from milliseconds to field values
   1.325 +  //-------------------------------------------------------------------------
   1.326 +
   1.327 +  /**
   1.328 +   * @internal
   1.329 +   */
   1.330 +  virtual int32_t handleGetExtendedYear();
   1.331 +
   1.332 +  /**
   1.333 +   * Override Calendar to compute several fields specific to the Islamic
   1.334 +   * calendar system.  These are:
   1.335 +   *
   1.336 +   * <ul><li>ERA
   1.337 +   * <li>YEAR
   1.338 +   * <li>MONTH
   1.339 +   * <li>DAY_OF_MONTH
   1.340 +   * <li>DAY_OF_YEAR
   1.341 +   * <li>EXTENDED_YEAR</ul>
   1.342 +   * 
   1.343 +   * The DAY_OF_WEEK and DOW_LOCAL fields are already set when this
   1.344 +   * method is called. The getGregorianXxx() methods return Gregorian
   1.345 +   * calendar equivalents for the given Julian day.
   1.346 +   * @internal
   1.347 +   */
   1.348 +  virtual void handleComputeFields(int32_t julianDay, UErrorCode &status);
   1.349 +
   1.350 +  // UObject stuff
   1.351 + public: 
   1.352 +  /**
   1.353 +   * @return   The class ID for this object. All objects of a given class have the
   1.354 +   *           same class ID. Objects of other classes have different class IDs.
   1.355 +   * @internal
   1.356 +   */
   1.357 +  virtual UClassID getDynamicClassID(void) const;
   1.358 +
   1.359 +  /**
   1.360 +   * Return the class ID for this class. This is useful only for comparing to a return
   1.361 +   * value from getDynamicClassID(). For example:
   1.362 +   *
   1.363 +   *      Base* polymorphic_pointer = createPolymorphicObject();
   1.364 +   *      if (polymorphic_pointer->getDynamicClassID() ==
   1.365 +   *          Derived::getStaticClassID()) ...
   1.366 +   *
   1.367 +   * @return   The class ID for all objects of this class.
   1.368 +   * @internal
   1.369 +   */
   1.370 +  /*U_I18N_API*/ static UClassID U_EXPORT2 getStaticClassID(void);
   1.371 +
   1.372 +  /**
   1.373 +   * return the calendar type, "buddhist".
   1.374 +   *
   1.375 +   * @return calendar type
   1.376 +   * @internal
   1.377 +   */
   1.378 +  virtual const char * getType() const;
   1.379 +
   1.380 + private:
   1.381 +  IslamicCalendar(); // default constructor not implemented
   1.382 +
   1.383 +  // Default century.
   1.384 + protected:
   1.385 +
   1.386 +  /**
   1.387 +   * (Overrides Calendar) Return true if the current date for this Calendar is in
   1.388 +   * Daylight Savings Time. Recognizes DST_OFFSET, if it is set.
   1.389 +   *
   1.390 +   * @param status Fill-in parameter which receives the status of this operation.
   1.391 +   * @return   True if the current date for this Calendar is in Daylight Savings Time,
   1.392 +   *           false, otherwise.
   1.393 +   * @internal
   1.394 +   */
   1.395 +  virtual UBool inDaylightTime(UErrorCode& status) const;
   1.396 +
   1.397 +
   1.398 +  /**
   1.399 +   * Returns TRUE because the Islamic Calendar does have a default century
   1.400 +   * @internal
   1.401 +   */
   1.402 +  virtual UBool haveDefaultCentury() const;
   1.403 +
   1.404 +  /**
   1.405 +   * Returns the date of the start of the default century
   1.406 +   * @return start of century - in milliseconds since epoch, 1970
   1.407 +   * @internal
   1.408 +   */
   1.409 +  virtual UDate defaultCenturyStart() const;
   1.410 +
   1.411 +  /**
   1.412 +   * Returns the year in which the default century begins
   1.413 +   * @internal
   1.414 +   */
   1.415 +  virtual int32_t defaultCenturyStartYear() const;
   1.416 +
   1.417 + private:
   1.418 +  /**
   1.419 +   * Initializes the 100-year window that dates with 2-digit years
   1.420 +   * are considered to fall within so that its start date is 80 years
   1.421 +   * before the current time.
   1.422 +   */
   1.423 +  static void  initializeSystemDefaultCentury(void);
   1.424 +};
   1.425 +
   1.426 +U_NAMESPACE_END
   1.427 +
   1.428 +#endif
   1.429 +#endif
   1.430 +
   1.431 +
   1.432 +

mercurial