intl/icu/source/i18n/persncal.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/icu/source/i18n/persncal.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,321 @@
     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 PERSNCAL.H
    1.11 + *
    1.12 + * Modification History:
    1.13 + *
    1.14 + *   Date        Name        Description
    1.15 + *   9/23/2003 mehran        posted to icu-design
    1.16 + *****************************************************************************
    1.17 + */
    1.18 +
    1.19 +#ifndef PERSNCAL_H
    1.20 +#define PERSNCAL_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>PersianCalendar</code> is a subclass of <code>Calendar</code>
    1.32 + * that implements the Persian calendar.  It is used as the official
    1.33 + * calendar in Iran.  This calendar is also known as the "Hijri Shamsi"
    1.34 + * calendar, since it starts at the time of Mohammed's emigration (or
    1.35 + * "hijra") to Medinah on Thursday, July 15, 622 AD (Julian) and is a
    1.36 + * solar calendar system (or "shamsi").
    1.37 + * <p>
    1.38 + * The Persian calendar is strictly solar, and thus a Persian year has twelve
    1.39 + * solar months. A Persian year is about 365 days long, except in leap years
    1.40 + * which is 366 days long.
    1.41 + * <p>
    1.42 + * The six first months of Persian Calendar are 31 days long. The next five
    1.43 + * months are 30 days long. The last month is 29 days long in normal years,
    1.44 + * and 30 days long in leap years.
    1.45 + *
    1.46 + * @see GregorianCalendar
    1.47 + *
    1.48 + * @author Mehran Mehr
    1.49 + * @internal
    1.50 + */
    1.51 +class PersianCalendar : public Calendar {
    1.52 + public:
    1.53 +  //-------------------------------------------------------------------------
    1.54 +  // Constants...
    1.55 +  //-------------------------------------------------------------------------
    1.56 +  /**
    1.57 +   * Constants for the months
    1.58 +   * @internal
    1.59 +   */
    1.60 +  enum EMonths {
    1.61 +    /**
    1.62 +     * Constant for Farvardin, the 1st month of the Persian year. 
    1.63 +     * @internal
    1.64 +     */
    1.65 +    FARVARDIN = 0,
    1.66 +
    1.67 +    /**
    1.68 +     * Constant for Ordibehesht, the 2nd month of the Persian year. 
    1.69 +     * @internal
    1.70 +     */
    1.71 +    ORDIBEHESHT = 1,
    1.72 +
    1.73 +    /**
    1.74 +     * Constant for Khordad, the 3rd month of the Persian year. 
    1.75 +     * @internal 
    1.76 +     */
    1.77 +    KHORDAD = 2,
    1.78 +
    1.79 +    /**
    1.80 +     * Constant for Tir, the 4th month of the Persian year. 
    1.81 +     * @internal 
    1.82 +     */
    1.83 +    TIR = 3,
    1.84 +
    1.85 +    /**
    1.86 +     * Constant for Mordad, the 5th month of the Persian year. 
    1.87 +     * @internal 
    1.88 +     */
    1.89 +    MORDAD = 4,
    1.90 +
    1.91 +    /**
    1.92 +     * Constant for Shahrivar, the 6th month of the Persian year. 
    1.93 +     * @internal 
    1.94 +     */
    1.95 +    SHAHRIVAR = 5,
    1.96 +
    1.97 +    /**
    1.98 +     * Constant for Mehr, the 7th month of the Persian year. 
    1.99 +     * @internal 
   1.100 +     */
   1.101 +    MEHR = 6,
   1.102 +
   1.103 +    /**
   1.104 +     * Constant for Aban, the 8th month of the Persian year. 
   1.105 +     * @internal 
   1.106 +     */
   1.107 +    ABAN = 7,
   1.108 +
   1.109 +    /**
   1.110 +     * Constant for Azar, the 9th month of the Persian year. 
   1.111 +     * @internal 
   1.112 +     */
   1.113 +    AZAR = 8,
   1.114 +
   1.115 +    /**
   1.116 +     * Constant for Dei, the 10th month of the Persian year. 
   1.117 +     * @internal 
   1.118 +     */
   1.119 +    DEI = 9,
   1.120 +
   1.121 +    /**
   1.122 +     * Constant for Bahman, the 11th month of the Persian year. 
   1.123 +     * @internal 
   1.124 +     */
   1.125 +    BAHMAN = 10,
   1.126 +
   1.127 +    /**
   1.128 +     * Constant for Esfand, the 12th month of the Persian year. 
   1.129 +     * @internal 
   1.130 +     */
   1.131 +    ESFAND = 11,
   1.132 +    
   1.133 +    PERSIAN_MONTH_MAX
   1.134 +  }; 
   1.135 +
   1.136 +
   1.137 +
   1.138 +  //-------------------------------------------------------------------------
   1.139 +  // Constructors...
   1.140 +  //-------------------------------------------------------------------------
   1.141 +
   1.142 +  /**
   1.143 +   * Constructs a PersianCalendar based on the current time in the default time zone
   1.144 +   * with the given locale.
   1.145 +   *
   1.146 +   * @param aLocale  The given locale.
   1.147 +   * @param success  Indicates the status of PersianCalendar object construction.
   1.148 +   *                 Returns U_ZERO_ERROR if constructed successfully.
   1.149 +   * @internal
   1.150 +   */
   1.151 +  PersianCalendar(const Locale& aLocale, UErrorCode &success);
   1.152 +
   1.153 +  /**
   1.154 +   * Copy Constructor
   1.155 +   * @internal
   1.156 +   */
   1.157 +  PersianCalendar(const PersianCalendar& other);
   1.158 +
   1.159 +  /**
   1.160 +   * Destructor.
   1.161 +   * @internal
   1.162 +   */
   1.163 +  virtual ~PersianCalendar();
   1.164 +
   1.165 +  // TODO: copy c'tor, etc
   1.166 +
   1.167 +  // clone
   1.168 +  virtual Calendar* clone() const;
   1.169 +
   1.170 + private:
   1.171 +  /**
   1.172 +   * Determine whether a year is a leap year in the Persian calendar
   1.173 +   */
   1.174 +  static UBool isLeapYear(int32_t year);
   1.175 +    
   1.176 +  /**
   1.177 +   * Return the day # on which the given year starts.  Days are counted
   1.178 +   * from the Hijri epoch, origin 0.
   1.179 +   */
   1.180 +  int32_t yearStart(int32_t year);
   1.181 +
   1.182 +  /**
   1.183 +   * Return the day # on which the given month starts.  Days are counted
   1.184 +   * from the Hijri epoch, origin 0.
   1.185 +   *
   1.186 +   * @param year  The hijri shamsi year
   1.187 +   * @param year  The hijri shamsi month, 0-based
   1.188 +   */
   1.189 +  int32_t monthStart(int32_t year, int32_t month) const;
   1.190 +    
   1.191 +  //----------------------------------------------------------------------
   1.192 +  // Calendar framework
   1.193 +  //----------------------------------------------------------------------
   1.194 + protected:
   1.195 +  /**
   1.196 +   * @internal
   1.197 +   */
   1.198 +  virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const;
   1.199 +  
   1.200 +  /**
   1.201 +   * Return the length (in days) of the given month.
   1.202 +   *
   1.203 +   * @param year  The hijri shamsi year
   1.204 +   * @param year  The hijri shamsi month, 0-based
   1.205 +   * @internal
   1.206 +   */
   1.207 +  virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month) const;
   1.208 +  
   1.209 +  /**
   1.210 +   * Return the number of days in the given Persian year
   1.211 +   * @internal
   1.212 +   */
   1.213 +  virtual int32_t handleGetYearLength(int32_t extendedYear) const;
   1.214 +    
   1.215 +  //-------------------------------------------------------------------------
   1.216 +  // Functions for converting from field values to milliseconds....
   1.217 +  //-------------------------------------------------------------------------
   1.218 +
   1.219 +  // Return JD of start of given month/year
   1.220 +  /**
   1.221 +   * @internal
   1.222 +   */
   1.223 +  virtual int32_t handleComputeMonthStart(int32_t eyear, int32_t month, UBool useMonth) const;
   1.224 +
   1.225 +  //-------------------------------------------------------------------------
   1.226 +  // Functions for converting from milliseconds to field values
   1.227 +  //-------------------------------------------------------------------------
   1.228 +
   1.229 +  /**
   1.230 +   * @internal
   1.231 +   */
   1.232 +  virtual int32_t handleGetExtendedYear();
   1.233 +
   1.234 +  /**
   1.235 +   * Override Calendar to compute several fields specific to the Persian
   1.236 +   * calendar system.  These are:
   1.237 +   *
   1.238 +   * <ul><li>ERA
   1.239 +   * <li>YEAR
   1.240 +   * <li>MONTH
   1.241 +   * <li>DAY_OF_MONTH
   1.242 +   * <li>DAY_OF_YEAR
   1.243 +   * <li>EXTENDED_YEAR</ul>
   1.244 +   * 
   1.245 +   * The DAY_OF_WEEK and DOW_LOCAL fields are already set when this
   1.246 +   * method is called. The getGregorianXxx() methods return Gregorian
   1.247 +   * calendar equivalents for the given Julian day.
   1.248 +   * @internal
   1.249 +   */
   1.250 +  virtual void handleComputeFields(int32_t julianDay, UErrorCode &status);
   1.251 +
   1.252 +  // UObject stuff
   1.253 + public: 
   1.254 +  /**
   1.255 +   * @return   The class ID for this object. All objects of a given class have the
   1.256 +   *           same class ID. Objects of other classes have different class IDs.
   1.257 +   * @internal
   1.258 +   */
   1.259 +  virtual UClassID getDynamicClassID(void) const;
   1.260 +
   1.261 +  /**
   1.262 +   * Return the class ID for this class. This is useful only for comparing to a return
   1.263 +   * value from getDynamicClassID(). For example:
   1.264 +   *
   1.265 +   *      Base* polymorphic_pointer = createPolymorphicObject();
   1.266 +   *      if (polymorphic_pointer->getDynamicClassID() ==
   1.267 +   *          Derived::getStaticClassID()) ...
   1.268 +   *
   1.269 +   * @return   The class ID for all objects of this class.
   1.270 +   * @internal
   1.271 +   */
   1.272 +  U_I18N_API static UClassID U_EXPORT2 getStaticClassID(void);
   1.273 +
   1.274 +  /**
   1.275 +   * return the calendar type, "persian".
   1.276 +   *
   1.277 +   * @return calendar type
   1.278 +   * @internal
   1.279 +   */
   1.280 +  virtual const char * getType() const;
   1.281 +
   1.282 + private:
   1.283 +  PersianCalendar(); // default constructor not implemented
   1.284 +
   1.285 + protected:
   1.286 +
   1.287 +  /**
   1.288 +   * (Overrides Calendar) Return true if the current date for this Calendar is in
   1.289 +   * Daylight Savings Time. Recognizes DST_OFFSET, if it is set.
   1.290 +   *
   1.291 +   * @param status Fill-in parameter which receives the status of this operation.
   1.292 +   * @return   True if the current date for this Calendar is in Daylight Savings Time,
   1.293 +   *           false, otherwise.
   1.294 +   * @internal
   1.295 +   */
   1.296 +  virtual UBool inDaylightTime(UErrorCode& status) const;
   1.297 +
   1.298 +  /**
   1.299 +   * Returns TRUE because the Persian Calendar does have a default century
   1.300 +   * @internal
   1.301 +   */
   1.302 +  virtual UBool haveDefaultCentury() const;
   1.303 +
   1.304 +  /**
   1.305 +   * Returns the date of the start of the default century
   1.306 +   * @return start of century - in milliseconds since epoch, 1970
   1.307 +   * @internal
   1.308 +   */
   1.309 +  virtual UDate defaultCenturyStart() const;
   1.310 +
   1.311 +  /**
   1.312 +   * Returns the year in which the default century begins
   1.313 +   * @internal
   1.314 +   */
   1.315 +  virtual int32_t defaultCenturyStartYear() const;
   1.316 +};
   1.317 +
   1.318 +U_NAMESPACE_END
   1.319 +
   1.320 +#endif
   1.321 +#endif
   1.322 +
   1.323 +
   1.324 +

mercurial