11cb0ef41Sopenharmony_ci// © 2016 and later: Unicode, Inc. and others. 21cb0ef41Sopenharmony_ci// License & terms of use: http://www.unicode.org/copyright.html 31cb0ef41Sopenharmony_ci/* 41cb0ef41Sopenharmony_ci ***************************************************************************** 51cb0ef41Sopenharmony_ci * Copyright (C) 2003-2008, International Business Machines Corporation 61cb0ef41Sopenharmony_ci * and others. All Rights Reserved. 71cb0ef41Sopenharmony_ci ***************************************************************************** 81cb0ef41Sopenharmony_ci * 91cb0ef41Sopenharmony_ci * File INDIANCAL.H 101cb0ef41Sopenharmony_ci ***************************************************************************** 111cb0ef41Sopenharmony_ci */ 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ci#ifndef INDIANCAL_H 141cb0ef41Sopenharmony_ci#define INDIANCAL_H 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ci#include "unicode/utypes.h" 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ci#if !UCONFIG_NO_FORMATTING 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ci#include "unicode/calendar.h" 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ciU_NAMESPACE_BEGIN 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ci/** 251cb0ef41Sopenharmony_ci * Concrete class which provides the Indian calendar. 261cb0ef41Sopenharmony_ci * <P> 271cb0ef41Sopenharmony_ci * <code>IndianCalendar</code> is a subclass of <code>Calendar</code> 281cb0ef41Sopenharmony_ci * that numbers years since the beginning of SAKA ERA. This is the civil calendar 291cb0ef41Sopenharmony_ci * which is accepted by government of India as Indian National Calendar. 301cb0ef41Sopenharmony_ci * The two calendars most widely used in India today are the Vikrama calendar 311cb0ef41Sopenharmony_ci * followed in North India and the Shalivahana or Saka calendar which is followed 321cb0ef41Sopenharmony_ci * in South India and Maharashtra. 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ci * A variant of the Shalivahana Calendar was reformed and standardized as the 351cb0ef41Sopenharmony_ci * Indian National calendar in 1957. 361cb0ef41Sopenharmony_ci * <p> 371cb0ef41Sopenharmony_ci * Some details of Indian National Calendar (to be implemented) : 381cb0ef41Sopenharmony_ci * The Months 391cb0ef41Sopenharmony_ci * Month Length Start date (Gregorian) 401cb0ef41Sopenharmony_ci * ================================================= 411cb0ef41Sopenharmony_ci * 1 Chaitra 30/31 March 22* 421cb0ef41Sopenharmony_ci * 2 Vaisakha 31 April 21 431cb0ef41Sopenharmony_ci * 3 Jyaistha 31 May 22 441cb0ef41Sopenharmony_ci * 4 Asadha 31 June 22 451cb0ef41Sopenharmony_ci * 5 Sravana 31 July 23 461cb0ef41Sopenharmony_ci * 6 Bhadra 31 August 23 471cb0ef41Sopenharmony_ci * 7 Asvina 30 September 23 481cb0ef41Sopenharmony_ci * 8 Kartika 30 October 23 491cb0ef41Sopenharmony_ci * 9 Agrahayana 30 November 22 501cb0ef41Sopenharmony_ci * 10 Pausa 30 December 22 511cb0ef41Sopenharmony_ci * 11 Magha 30 January 21 521cb0ef41Sopenharmony_ci * 12 Phalguna 30 February 20 531cb0ef41Sopenharmony_ci 541cb0ef41Sopenharmony_ci * In leap years, Chaitra has 31 days and starts on March 21 instead. 551cb0ef41Sopenharmony_ci * The leap years of Gregorian calendar and Indian National Calendar are in synchornization. 561cb0ef41Sopenharmony_ci * So When its a leap year in Gregorian calendar then Chaitra has 31 days. 571cb0ef41Sopenharmony_ci * 581cb0ef41Sopenharmony_ci * The Years 591cb0ef41Sopenharmony_ci * Years are counted in the Saka Era, which starts its year 0 in 78AD (by gregorian calendar). 601cb0ef41Sopenharmony_ci * So for eg. 9th June 2006 by Gregorian Calendar, is same as 19th of Jyaistha in 1928 of Saka 611cb0ef41Sopenharmony_ci * era by Indian National Calendar. 621cb0ef41Sopenharmony_ci * <p> 631cb0ef41Sopenharmony_ci * The Indian Calendar has only one allowable era: <code>Saka Era</code>. If the 641cb0ef41Sopenharmony_ci * calendar is not in lenient mode (see <code>setLenient</code>), dates before 651cb0ef41Sopenharmony_ci * 1/1/1 Saka Era are rejected with an <code>IllegalArgumentException</code>. 661cb0ef41Sopenharmony_ci * <p> 671cb0ef41Sopenharmony_ci * @internal 681cb0ef41Sopenharmony_ci */ 691cb0ef41Sopenharmony_ci 701cb0ef41Sopenharmony_ci 711cb0ef41Sopenharmony_ciclass U_I18N_API IndianCalendar : public Calendar { 721cb0ef41Sopenharmony_cipublic: 731cb0ef41Sopenharmony_ci /** 741cb0ef41Sopenharmony_ci * Useful constants for IndianCalendar. 751cb0ef41Sopenharmony_ci * @internal 761cb0ef41Sopenharmony_ci */ 771cb0ef41Sopenharmony_ci enum EEras { 781cb0ef41Sopenharmony_ci /** 791cb0ef41Sopenharmony_ci * Constant for Chaitra, the 1st month of the Indian year. 801cb0ef41Sopenharmony_ci */ 811cb0ef41Sopenharmony_ci CHAITRA, 821cb0ef41Sopenharmony_ci 831cb0ef41Sopenharmony_ci /** 841cb0ef41Sopenharmony_ci * Constant for Vaisakha, the 2nd month of the Indian year. 851cb0ef41Sopenharmony_ci */ 861cb0ef41Sopenharmony_ci VAISAKHA, 871cb0ef41Sopenharmony_ci 881cb0ef41Sopenharmony_ci /** 891cb0ef41Sopenharmony_ci * Constant for Jyaistha, the 3rd month of the Indian year. 901cb0ef41Sopenharmony_ci */ 911cb0ef41Sopenharmony_ci JYAISTHA, 921cb0ef41Sopenharmony_ci 931cb0ef41Sopenharmony_ci /** 941cb0ef41Sopenharmony_ci * Constant for Asadha, the 4th month of the Indian year. 951cb0ef41Sopenharmony_ci */ 961cb0ef41Sopenharmony_ci ASADHA, 971cb0ef41Sopenharmony_ci 981cb0ef41Sopenharmony_ci /** 991cb0ef41Sopenharmony_ci * Constant for Sravana, the 5th month of the Indian year. 1001cb0ef41Sopenharmony_ci */ 1011cb0ef41Sopenharmony_ci SRAVANA, 1021cb0ef41Sopenharmony_ci 1031cb0ef41Sopenharmony_ci /** 1041cb0ef41Sopenharmony_ci * Constant for Bhadra the 6th month of the Indian year 1051cb0ef41Sopenharmony_ci */ 1061cb0ef41Sopenharmony_ci BHADRA, 1071cb0ef41Sopenharmony_ci 1081cb0ef41Sopenharmony_ci /** 1091cb0ef41Sopenharmony_ci * Constant for the Asvina, the 7th month of the Indian year. 1101cb0ef41Sopenharmony_ci */ 1111cb0ef41Sopenharmony_ci ASVINA, 1121cb0ef41Sopenharmony_ci 1131cb0ef41Sopenharmony_ci /** 1141cb0ef41Sopenharmony_ci * Constant for Kartika, the 8th month of the Indian year. 1151cb0ef41Sopenharmony_ci */ 1161cb0ef41Sopenharmony_ci KARTIKA, 1171cb0ef41Sopenharmony_ci 1181cb0ef41Sopenharmony_ci /** 1191cb0ef41Sopenharmony_ci * Constant for Agrahayana, the 9th month of the Indian year. 1201cb0ef41Sopenharmony_ci */ 1211cb0ef41Sopenharmony_ci AGRAHAYANA, 1221cb0ef41Sopenharmony_ci 1231cb0ef41Sopenharmony_ci /** 1241cb0ef41Sopenharmony_ci * Constant for Pausa, the 10th month of the Indian year. 1251cb0ef41Sopenharmony_ci */ 1261cb0ef41Sopenharmony_ci PAUSA, 1271cb0ef41Sopenharmony_ci 1281cb0ef41Sopenharmony_ci /** 1291cb0ef41Sopenharmony_ci * Constant for Magha, the 11th month of the Indian year. 1301cb0ef41Sopenharmony_ci */ 1311cb0ef41Sopenharmony_ci MAGHA, 1321cb0ef41Sopenharmony_ci 1331cb0ef41Sopenharmony_ci /** 1341cb0ef41Sopenharmony_ci * Constant for Phalguna, the 12th month of the Indian year. 1351cb0ef41Sopenharmony_ci */ 1361cb0ef41Sopenharmony_ci PHALGUNA 1371cb0ef41Sopenharmony_ci }; 1381cb0ef41Sopenharmony_ci 1391cb0ef41Sopenharmony_ci //------------------------------------------------------------------------- 1401cb0ef41Sopenharmony_ci // Constructors... 1411cb0ef41Sopenharmony_ci //------------------------------------------------------------------------- 1421cb0ef41Sopenharmony_ci 1431cb0ef41Sopenharmony_ci /** 1441cb0ef41Sopenharmony_ci * Constructs an IndianCalendar based on the current time in the default time zone 1451cb0ef41Sopenharmony_ci * with the given locale. 1461cb0ef41Sopenharmony_ci * 1471cb0ef41Sopenharmony_ci * @param aLocale The given locale. 1481cb0ef41Sopenharmony_ci * @param success Indicates the status of IndianCalendar object construction. 1491cb0ef41Sopenharmony_ci * Returns U_ZERO_ERROR if constructed successfully. 1501cb0ef41Sopenharmony_ci * @param beCivil Whether the calendar should be civil (default-true) or religious (false) 1511cb0ef41Sopenharmony_ci * @internal 1521cb0ef41Sopenharmony_ci */ 1531cb0ef41Sopenharmony_ci IndianCalendar(const Locale& aLocale, UErrorCode &success); 1541cb0ef41Sopenharmony_ci 1551cb0ef41Sopenharmony_ci /** 1561cb0ef41Sopenharmony_ci * Copy Constructor 1571cb0ef41Sopenharmony_ci * @internal 1581cb0ef41Sopenharmony_ci */ 1591cb0ef41Sopenharmony_ci IndianCalendar(const IndianCalendar& other); 1601cb0ef41Sopenharmony_ci 1611cb0ef41Sopenharmony_ci /** 1621cb0ef41Sopenharmony_ci * Destructor. 1631cb0ef41Sopenharmony_ci * @internal 1641cb0ef41Sopenharmony_ci */ 1651cb0ef41Sopenharmony_ci virtual ~IndianCalendar(); 1661cb0ef41Sopenharmony_ci 1671cb0ef41Sopenharmony_ci /** 1681cb0ef41Sopenharmony_ci * Determines whether this object uses the fixed-cycle Indian civil calendar 1691cb0ef41Sopenharmony_ci * or an approximation of the religious, astronomical calendar. 1701cb0ef41Sopenharmony_ci * 1711cb0ef41Sopenharmony_ci * @param beCivil <code>CIVIL</code> to use the civil calendar, 1721cb0ef41Sopenharmony_ci * <code>ASTRONOMICAL</code> to use the astronomical calendar. 1731cb0ef41Sopenharmony_ci * @internal 1741cb0ef41Sopenharmony_ci */ 1751cb0ef41Sopenharmony_ci //void setCivil(ECivil beCivil, UErrorCode &status); 1761cb0ef41Sopenharmony_ci 1771cb0ef41Sopenharmony_ci /** 1781cb0ef41Sopenharmony_ci * Returns <code>true</code> if this object is using the fixed-cycle civil 1791cb0ef41Sopenharmony_ci * calendar, or <code>false</code> if using the religious, astronomical 1801cb0ef41Sopenharmony_ci * calendar. 1811cb0ef41Sopenharmony_ci * @internal 1821cb0ef41Sopenharmony_ci */ 1831cb0ef41Sopenharmony_ci //UBool isCivil(); 1841cb0ef41Sopenharmony_ci 1851cb0ef41Sopenharmony_ci 1861cb0ef41Sopenharmony_ci // TODO: copy c'tor, etc 1871cb0ef41Sopenharmony_ci 1881cb0ef41Sopenharmony_ci // clone 1891cb0ef41Sopenharmony_ci virtual IndianCalendar* clone() const override; 1901cb0ef41Sopenharmony_ci 1911cb0ef41Sopenharmony_ci private: 1921cb0ef41Sopenharmony_ci /** 1931cb0ef41Sopenharmony_ci * Determine whether a year is the gregorian year a leap year 1941cb0ef41Sopenharmony_ci */ 1951cb0ef41Sopenharmony_ci //static UBool isGregorianLeap(int32_t year); 1961cb0ef41Sopenharmony_ci //---------------------------------------------------------------------- 1971cb0ef41Sopenharmony_ci // Calendar framework 1981cb0ef41Sopenharmony_ci //---------------------------------------------------------------------- 1991cb0ef41Sopenharmony_ci protected: 2001cb0ef41Sopenharmony_ci /** 2011cb0ef41Sopenharmony_ci * @internal 2021cb0ef41Sopenharmony_ci */ 2031cb0ef41Sopenharmony_ci virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const override; 2041cb0ef41Sopenharmony_ci 2051cb0ef41Sopenharmony_ci /** 2061cb0ef41Sopenharmony_ci * Return the length (in days) of the given month. 2071cb0ef41Sopenharmony_ci * 2081cb0ef41Sopenharmony_ci * @param year The year in Saka era 2091cb0ef41Sopenharmony_ci * @param year The month(0-based) in Indian year 2101cb0ef41Sopenharmony_ci * @internal 2111cb0ef41Sopenharmony_ci */ 2121cb0ef41Sopenharmony_ci virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month) const override; 2131cb0ef41Sopenharmony_ci 2141cb0ef41Sopenharmony_ci /** 2151cb0ef41Sopenharmony_ci * Return the number of days in the given Indian year 2161cb0ef41Sopenharmony_ci * @internal 2171cb0ef41Sopenharmony_ci */ 2181cb0ef41Sopenharmony_ci virtual int32_t handleGetYearLength(int32_t extendedYear) const override; 2191cb0ef41Sopenharmony_ci 2201cb0ef41Sopenharmony_ci //------------------------------------------------------------------------- 2211cb0ef41Sopenharmony_ci // Functions for converting from field values to milliseconds.... 2221cb0ef41Sopenharmony_ci //------------------------------------------------------------------------- 2231cb0ef41Sopenharmony_ci 2241cb0ef41Sopenharmony_ci // Return JD of start of given month/year 2251cb0ef41Sopenharmony_ci /** 2261cb0ef41Sopenharmony_ci * @internal 2271cb0ef41Sopenharmony_ci */ 2281cb0ef41Sopenharmony_ci virtual int32_t handleComputeMonthStart(int32_t eyear, int32_t month, UBool useMonth) const override; 2291cb0ef41Sopenharmony_ci 2301cb0ef41Sopenharmony_ci //------------------------------------------------------------------------- 2311cb0ef41Sopenharmony_ci // Functions for converting from milliseconds to field values 2321cb0ef41Sopenharmony_ci //------------------------------------------------------------------------- 2331cb0ef41Sopenharmony_ci 2341cb0ef41Sopenharmony_ci /** 2351cb0ef41Sopenharmony_ci * @internal 2361cb0ef41Sopenharmony_ci */ 2371cb0ef41Sopenharmony_ci virtual int32_t handleGetExtendedYear() override; 2381cb0ef41Sopenharmony_ci 2391cb0ef41Sopenharmony_ci /** 2401cb0ef41Sopenharmony_ci * Override Calendar to compute several fields specific to the Indian 2411cb0ef41Sopenharmony_ci * calendar system. These are: 2421cb0ef41Sopenharmony_ci * 2431cb0ef41Sopenharmony_ci * <ul><li>ERA 2441cb0ef41Sopenharmony_ci * <li>YEAR 2451cb0ef41Sopenharmony_ci * <li>MONTH 2461cb0ef41Sopenharmony_ci * <li>DAY_OF_MONTH 2471cb0ef41Sopenharmony_ci * <li>DAY_OF_YEAR 2481cb0ef41Sopenharmony_ci * <li>EXTENDED_YEAR</ul> 2491cb0ef41Sopenharmony_ci * 2501cb0ef41Sopenharmony_ci * The DAY_OF_WEEK and DOW_LOCAL fields are already set when this 2511cb0ef41Sopenharmony_ci * method is called. The getGregorianXxx() methods return Gregorian 2521cb0ef41Sopenharmony_ci * calendar equivalents for the given Julian day. 2531cb0ef41Sopenharmony_ci * @internal 2541cb0ef41Sopenharmony_ci */ 2551cb0ef41Sopenharmony_ci virtual void handleComputeFields(int32_t julianDay, UErrorCode &status) override; 2561cb0ef41Sopenharmony_ci 2571cb0ef41Sopenharmony_ci // UObject stuff 2581cb0ef41Sopenharmony_ci public: 2591cb0ef41Sopenharmony_ci /** 2601cb0ef41Sopenharmony_ci * @return The class ID for this object. All objects of a given class have the 2611cb0ef41Sopenharmony_ci * same class ID. Objects of other classes have different class IDs. 2621cb0ef41Sopenharmony_ci * @internal 2631cb0ef41Sopenharmony_ci */ 2641cb0ef41Sopenharmony_ci virtual UClassID getDynamicClassID() const override; 2651cb0ef41Sopenharmony_ci 2661cb0ef41Sopenharmony_ci /** 2671cb0ef41Sopenharmony_ci * Return the class ID for this class. This is useful only for comparing to a return 2681cb0ef41Sopenharmony_ci * value from getDynamicClassID(). For example: 2691cb0ef41Sopenharmony_ci * 2701cb0ef41Sopenharmony_ci * Base* polymorphic_pointer = createPolymorphicObject(); 2711cb0ef41Sopenharmony_ci * if (polymorphic_pointer->getDynamicClassID() == 2721cb0ef41Sopenharmony_ci * Derived::getStaticClassID()) ... 2731cb0ef41Sopenharmony_ci * 2741cb0ef41Sopenharmony_ci * @return The class ID for all objects of this class. 2751cb0ef41Sopenharmony_ci * @internal 2761cb0ef41Sopenharmony_ci */ 2771cb0ef41Sopenharmony_ci static UClassID U_EXPORT2 getStaticClassID(); 2781cb0ef41Sopenharmony_ci 2791cb0ef41Sopenharmony_ci /** 2801cb0ef41Sopenharmony_ci * return the calendar type, "indian". 2811cb0ef41Sopenharmony_ci * 2821cb0ef41Sopenharmony_ci * @return calendar type 2831cb0ef41Sopenharmony_ci * @internal 2841cb0ef41Sopenharmony_ci */ 2851cb0ef41Sopenharmony_ci virtual const char * getType() const override; 2861cb0ef41Sopenharmony_ci 2871cb0ef41Sopenharmony_ci /** 2881cb0ef41Sopenharmony_ci * @return The related Gregorian year; will be obtained by modifying the value 2891cb0ef41Sopenharmony_ci * obtained by get from UCAL_EXTENDED_YEAR field 2901cb0ef41Sopenharmony_ci * @internal 2911cb0ef41Sopenharmony_ci */ 2921cb0ef41Sopenharmony_ci virtual int32_t getRelatedYear(UErrorCode &status) const override; 2931cb0ef41Sopenharmony_ci 2941cb0ef41Sopenharmony_ci /** 2951cb0ef41Sopenharmony_ci * @param year The related Gregorian year to set; will be modified as necessary then 2961cb0ef41Sopenharmony_ci * set in UCAL_EXTENDED_YEAR field 2971cb0ef41Sopenharmony_ci * @internal 2981cb0ef41Sopenharmony_ci */ 2991cb0ef41Sopenharmony_ci virtual void setRelatedYear(int32_t year) override; 3001cb0ef41Sopenharmony_ci 3011cb0ef41Sopenharmony_ci 3021cb0ef41Sopenharmony_ciprivate: 3031cb0ef41Sopenharmony_ci IndianCalendar() = delete; // default constructor not implemented 3041cb0ef41Sopenharmony_ci 3051cb0ef41Sopenharmony_ci // Default century. 3061cb0ef41Sopenharmony_ciprotected: 3071cb0ef41Sopenharmony_ci /** 3081cb0ef41Sopenharmony_ci * Returns true because the Indian Calendar does have a default century 3091cb0ef41Sopenharmony_ci * @internal 3101cb0ef41Sopenharmony_ci */ 3111cb0ef41Sopenharmony_ci virtual UBool haveDefaultCentury() const override; 3121cb0ef41Sopenharmony_ci 3131cb0ef41Sopenharmony_ci /** 3141cb0ef41Sopenharmony_ci * Returns the date of the start of the default century 3151cb0ef41Sopenharmony_ci * @return start of century - in milliseconds since epoch, 1970 3161cb0ef41Sopenharmony_ci * @internal 3171cb0ef41Sopenharmony_ci */ 3181cb0ef41Sopenharmony_ci virtual UDate defaultCenturyStart() const override; 3191cb0ef41Sopenharmony_ci 3201cb0ef41Sopenharmony_ci /** 3211cb0ef41Sopenharmony_ci * Returns the year in which the default century begins 3221cb0ef41Sopenharmony_ci * @internal 3231cb0ef41Sopenharmony_ci */ 3241cb0ef41Sopenharmony_ci virtual int32_t defaultCenturyStartYear() const override; 3251cb0ef41Sopenharmony_ci}; 3261cb0ef41Sopenharmony_ci 3271cb0ef41Sopenharmony_ciU_NAMESPACE_END 3281cb0ef41Sopenharmony_ci 3291cb0ef41Sopenharmony_ci#endif 3301cb0ef41Sopenharmony_ci#endif 3311cb0ef41Sopenharmony_ci 3321cb0ef41Sopenharmony_ci 3331cb0ef41Sopenharmony_ci 334