Home | History | Annotate | Download | only in i18n
      1 /*
      2  *****************************************************************************
      3  * Copyright (C) 2003-2008, International Business Machines Corporation
      4  * and others. All Rights Reserved.
      5  *****************************************************************************
      6  *
      7  * File INDIANCAL.H
      8  *****************************************************************************
      9  */
     10 
     11 #ifndef INDIANCAL_H
     12 #define INDIANCAL_H
     13 
     14 #include "unicode/utypes.h"
     15 
     16 #if !UCONFIG_NO_FORMATTING
     17 
     18 #include "unicode/calendar.h"
     19 
     20 U_NAMESPACE_BEGIN
     21 
     22 /**
     23  * Concrete class which provides the Indian calendar.
     24  * <P>
     25  * <code>IndianCalendar</code> is a subclass of <code>Calendar</code>
     26  * that numbers years since the begining of SAKA ERA.  This is the civil calendar
     27  * which is accepted by government of India as Indian National Calendar.
     28  * The two calendars most widely used in India today are the Vikrama calendar
     29  * followed in North India and the Shalivahana or Saka calendar which is followed
     30  * in South India and Maharashtra.
     31 
     32  * A variant of the Shalivahana Calendar was reformed and standardized as the
     33  * Indian National calendar in 1957.
     34  * <p>
     35  * Some details of Indian National Calendar (to be implemented) :
     36  * The Months
     37  * Month          Length      Start date (Gregorian)
     38  * =================================================
     39  * 1 Chaitra      30/31          March 22*
     40  * 2 Vaisakha     31             April 21
     41  * 3 Jyaistha     31             May 22
     42  * 4 Asadha       31             June 22
     43  * 5 Sravana      31             July 23
     44  * 6 Bhadra       31             August 23
     45  * 7 Asvina       30             September 23
     46  * 8 Kartika      30             October 23
     47  * 9 Agrahayana   30             November 22
     48  * 10 Pausa       30             December 22
     49  * 11 Magha       30             January 21
     50  * 12 Phalguna    30             February 20
     51 
     52  * In leap years, Chaitra has 31 days and starts on March 21 instead.
     53  * The leap years of Gregorian calendar and Indian National Calendar are in synchornization.
     54  * So When its a leap year in Gregorian calendar then Chaitra has 31 days.
     55  *
     56  * The Years
     57  * Years are counted in the Saka Era, which starts its year 0 in 78AD (by gregorian calendar).
     58  * So for eg. 9th June 2006 by Gregorian Calendar, is same as 19th of Jyaistha in 1928 of Saka
     59  * era by Indian National Calendar.
     60  * <p>
     61  * The Indian Calendar has only one allowable era: <code>Saka Era</code>.  If the
     62  * calendar is not in lenient mode (see <code>setLenient</code>), dates before
     63  * 1/1/1 Saka Era are rejected with an <code>IllegalArgumentException</code>.
     64  * <p>
     65  * @internal
     66  */
     67 
     68 
     69 class IndianCalendar : public Calendar {
     70 public:
     71   /**
     72    * Useful constants for IndianCalendar.
     73    * @internal
     74    */
     75   enum EEras {
     76     /**
     77      * Constant for Chaitra, the 1st month of the Indian year.
     78      */
     79       CHAITRA,
     80 
     81       /**
     82      * Constant for Vaisakha, the 2nd month of the Indian year.
     83      */
     84       VAISAKHA,
     85 
     86       /**
     87      * Constant for Jyaistha, the 3rd month of the Indian year.
     88      */
     89       JYAISTHA,
     90 
     91     /**
     92      * Constant for Asadha, the 4th month of the Indian year.
     93      */
     94       ASADHA,
     95 
     96     /**
     97      * Constant for Sravana, the 5th month of the Indian year.
     98      */
     99       SRAVANA,
    100 
    101     /**
    102      * Constant for Bhadra the 6th month of the Indian year
    103      */
    104       BHADRA,
    105 
    106     /**
    107      * Constant for the Asvina, the 7th month of the Indian year.
    108      */
    109       ASVINA,
    110 
    111     /**
    112      * Constant for Kartika, the 8th month of the Indian year.
    113      */
    114       KARTIKA,
    115 
    116     /**
    117      * Constant for Agrahayana, the 9th month of the Indian year.
    118      */
    119       AGRAHAYANA,
    120 
    121     /**
    122      * Constant for Pausa, the 10th month of the Indian year.
    123      */
    124       PAUSA,
    125 
    126     /**
    127      * Constant for Magha, the 11th month of the Indian year.
    128      */
    129       MAGHA,
    130 
    131     /**
    132      * Constant for Phalguna, the 12th month of the Indian year.
    133      */
    134       PHALGUNA
    135     };
    136 
    137   //-------------------------------------------------------------------------
    138   // Constructors...
    139   //-------------------------------------------------------------------------
    140 
    141   /**
    142    * Constructs an IndianCalendar based on the current time in the default time zone
    143    * with the given locale.
    144    *
    145    * @param aLocale  The given locale.
    146    * @param success  Indicates the status of IndianCalendar object construction.
    147    *                 Returns U_ZERO_ERROR if constructed successfully.
    148    * @param beCivil  Whether the calendar should be civil (default-TRUE) or religious (FALSE)
    149    * @internal
    150    */
    151   IndianCalendar(const Locale& aLocale, UErrorCode &success);
    152 
    153   /**
    154    * Copy Constructor
    155    * @internal
    156    */
    157   IndianCalendar(const IndianCalendar& other);
    158 
    159   /**
    160    * Destructor.
    161    * @internal
    162    */
    163   virtual ~IndianCalendar();
    164 
    165   /**
    166    * Determines whether this object uses the fixed-cycle Indian civil calendar
    167    * or an approximation of the religious, astronomical calendar.
    168    *
    169    * @param beCivil   <code>CIVIL</code> to use the civil calendar,
    170    *                  <code>ASTRONOMICAL</code> to use the astronomical calendar.
    171    * @internal
    172    */
    173   //void setCivil(ECivil beCivil, UErrorCode &status);
    174 
    175   /**
    176    * Returns <code>true</code> if this object is using the fixed-cycle civil
    177    * calendar, or <code>false</code> if using the religious, astronomical
    178    * calendar.
    179    * @internal
    180    */
    181   //UBool isCivil();
    182 
    183 
    184   // TODO: copy c'tor, etc
    185 
    186   // clone
    187   virtual Calendar* clone() const;
    188 
    189  private:
    190   /**
    191    * Determine whether a year is the gregorian year a leap year
    192    */
    193   //static UBool isGregorianLeap(int32_t year);
    194   //----------------------------------------------------------------------
    195   // Calendar framework
    196   //----------------------------------------------------------------------
    197  protected:
    198   /**
    199    * @internal
    200    */
    201   virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const;
    202 
    203   /**
    204    * Return the length (in days) of the given month.
    205    *
    206    * @param year  The year in Saka era
    207    * @param year  The month(0-based) in Indian year
    208    * @internal
    209    */
    210   virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month) const;
    211 
    212   /**
    213    * Return the number of days in the given Indian year
    214    * @internal
    215    */
    216   virtual int32_t handleGetYearLength(int32_t extendedYear) const;
    217 
    218   //-------------------------------------------------------------------------
    219   // Functions for converting from field values to milliseconds....
    220   //-------------------------------------------------------------------------
    221 
    222   // Return JD of start of given month/year
    223   /**
    224    * @internal
    225    */
    226   virtual int32_t handleComputeMonthStart(int32_t eyear, int32_t month, UBool useMonth) const;
    227 
    228   //-------------------------------------------------------------------------
    229   // Functions for converting from milliseconds to field values
    230   //-------------------------------------------------------------------------
    231 
    232   /**
    233    * @internal
    234    */
    235   virtual int32_t handleGetExtendedYear();
    236 
    237   /**
    238    * Override Calendar to compute several fields specific to the Indian
    239    * calendar system.  These are:
    240    *
    241    * <ul><li>ERA
    242    * <li>YEAR
    243    * <li>MONTH
    244    * <li>DAY_OF_MONTH
    245    * <li>DAY_OF_YEAR
    246    * <li>EXTENDED_YEAR</ul>
    247    *
    248    * The DAY_OF_WEEK and DOW_LOCAL fields are already set when this
    249    * method is called. The getGregorianXxx() methods return Gregorian
    250    * calendar equivalents for the given Julian day.
    251    * @internal
    252    */
    253   virtual void handleComputeFields(int32_t julianDay, UErrorCode &status);
    254 
    255   // UObject stuff
    256  public:
    257   /**
    258    * @return   The class ID for this object. All objects of a given class have the
    259    *           same class ID. Objects of other classes have different class IDs.
    260    * @internal
    261    */
    262   virtual UClassID getDynamicClassID(void) const;
    263 
    264   /**
    265    * Return the class ID for this class. This is useful only for comparing to a return
    266    * value from getDynamicClassID(). For example:
    267    *
    268    *      Base* polymorphic_pointer = createPolymorphicObject();
    269    *      if (polymorphic_pointer->getDynamicClassID() ==
    270    *          Derived::getStaticClassID()) ...
    271    *
    272    * @return   The class ID for all objects of this class.
    273    * @internal
    274    */
    275   U_I18N_API static UClassID U_EXPORT2 getStaticClassID(void);
    276 
    277   /**
    278    * return the calendar type, "buddhist".
    279    *
    280    * @return calendar type
    281    * @internal
    282    */
    283   virtual const char * getType() const;
    284 
    285 private:
    286   IndianCalendar(); // default constructor not implemented
    287 
    288   // Default century.
    289 protected:
    290 
    291   /**
    292    * (Overrides Calendar) Return true if the current date for this Calendar is in
    293    * Daylight Savings Time. Recognizes DST_OFFSET, if it is set.
    294    *
    295    * @param status Fill-in parameter which receives the status of this operation.
    296    * @return   True if the current date for this Calendar is in Daylight Savings Time,
    297    *           false, otherwise.
    298    * @internal
    299    */
    300   virtual UBool inDaylightTime(UErrorCode& status) const;
    301 
    302 
    303   /**
    304    * Returns TRUE because the Indian Calendar does have a default century
    305    * @internal
    306    */
    307   virtual UBool haveDefaultCentury() const;
    308 
    309   /**
    310    * Returns the date of the start of the default century
    311    * @return start of century - in milliseconds since epoch, 1970
    312    * @internal
    313    */
    314   virtual UDate defaultCenturyStart() const;
    315 
    316   /**
    317    * Returns the year in which the default century begins
    318    * @internal
    319    */
    320   virtual int32_t defaultCenturyStartYear() const;
    321 
    322  private: // default century stuff.
    323   /**
    324    * The system maintains a static default century start date.  This is initialized
    325    * the first time it is used.  Before then, it is set to SYSTEM_DEFAULT_CENTURY to
    326    * indicate an uninitialized state.  Once the system default century date and year
    327    * are set, they do not change.
    328    */
    329   static UDate         fgSystemDefaultCenturyStart;
    330 
    331   /**
    332    * See documentation for systemDefaultCenturyStart.
    333    */
    334   static int32_t          fgSystemDefaultCenturyStartYear;
    335 
    336   /**
    337    * Default value that indicates the defaultCenturyStartYear is unitialized
    338    */
    339   static const int32_t    fgSystemDefaultCenturyYear;
    340 
    341   /**
    342    * start of default century, as a date
    343    */
    344   static const UDate        fgSystemDefaultCentury;
    345 
    346   /**
    347    * Returns the beginning date of the 100-year window that dates
    348    * with 2-digit years are considered to fall within.
    349    */
    350   UDate         internalGetDefaultCenturyStart(void) const;
    351 
    352   /**
    353    * Returns the first year of the 100-year window that dates with
    354    * 2-digit years are considered to fall within.
    355    */
    356   int32_t          internalGetDefaultCenturyStartYear(void) const;
    357 
    358   /**
    359    * Initializes the 100-year window that dates with 2-digit years
    360    * are considered to fall within so that its start date is 80 years
    361    * before the current time.
    362    */
    363   static void  initializeSystemDefaultCentury(void);
    364 };
    365 
    366 U_NAMESPACE_END
    367 
    368 #endif
    369 #endif
    370 
    371 
    372 
    373