michael@0: /* michael@0: ***************************************************************************** michael@0: * Copyright (C) 2003-2008, International Business Machines Corporation michael@0: * and others. All Rights Reserved. michael@0: ***************************************************************************** michael@0: * michael@0: * File INDIANCAL.H michael@0: ***************************************************************************** michael@0: */ michael@0: michael@0: #ifndef INDIANCAL_H michael@0: #define INDIANCAL_H michael@0: michael@0: #include "unicode/utypes.h" michael@0: michael@0: #if !UCONFIG_NO_FORMATTING michael@0: michael@0: #include "unicode/calendar.h" michael@0: michael@0: U_NAMESPACE_BEGIN michael@0: michael@0: /** michael@0: * Concrete class which provides the Indian calendar. michael@0: *

michael@0: * IndianCalendar is a subclass of Calendar michael@0: * that numbers years since the begining of SAKA ERA. This is the civil calendar michael@0: * which is accepted by government of India as Indian National Calendar. michael@0: * The two calendars most widely used in India today are the Vikrama calendar michael@0: * followed in North India and the Shalivahana or Saka calendar which is followed michael@0: * in South India and Maharashtra. michael@0: michael@0: * A variant of the Shalivahana Calendar was reformed and standardized as the michael@0: * Indian National calendar in 1957. michael@0: *

michael@0: * Some details of Indian National Calendar (to be implemented) : michael@0: * The Months michael@0: * Month Length Start date (Gregorian) michael@0: * ================================================= michael@0: * 1 Chaitra 30/31 March 22* michael@0: * 2 Vaisakha 31 April 21 michael@0: * 3 Jyaistha 31 May 22 michael@0: * 4 Asadha 31 June 22 michael@0: * 5 Sravana 31 July 23 michael@0: * 6 Bhadra 31 August 23 michael@0: * 7 Asvina 30 September 23 michael@0: * 8 Kartika 30 October 23 michael@0: * 9 Agrahayana 30 November 22 michael@0: * 10 Pausa 30 December 22 michael@0: * 11 Magha 30 January 21 michael@0: * 12 Phalguna 30 February 20 michael@0: michael@0: * In leap years, Chaitra has 31 days and starts on March 21 instead. michael@0: * The leap years of Gregorian calendar and Indian National Calendar are in synchornization. michael@0: * So When its a leap year in Gregorian calendar then Chaitra has 31 days. michael@0: * michael@0: * The Years michael@0: * Years are counted in the Saka Era, which starts its year 0 in 78AD (by gregorian calendar). michael@0: * So for eg. 9th June 2006 by Gregorian Calendar, is same as 19th of Jyaistha in 1928 of Saka michael@0: * era by Indian National Calendar. michael@0: *

michael@0: * The Indian Calendar has only one allowable era: Saka Era. If the michael@0: * calendar is not in lenient mode (see setLenient), dates before michael@0: * 1/1/1 Saka Era are rejected with an IllegalArgumentException. michael@0: *

michael@0: * @internal michael@0: */ michael@0: michael@0: michael@0: class IndianCalendar : public Calendar { michael@0: public: michael@0: /** michael@0: * Useful constants for IndianCalendar. michael@0: * @internal michael@0: */ michael@0: enum EEras { michael@0: /** michael@0: * Constant for Chaitra, the 1st month of the Indian year. michael@0: */ michael@0: CHAITRA, michael@0: michael@0: /** michael@0: * Constant for Vaisakha, the 2nd month of the Indian year. michael@0: */ michael@0: VAISAKHA, michael@0: michael@0: /** michael@0: * Constant for Jyaistha, the 3rd month of the Indian year. michael@0: */ michael@0: JYAISTHA, michael@0: michael@0: /** michael@0: * Constant for Asadha, the 4th month of the Indian year. michael@0: */ michael@0: ASADHA, michael@0: michael@0: /** michael@0: * Constant for Sravana, the 5th month of the Indian year. michael@0: */ michael@0: SRAVANA, michael@0: michael@0: /** michael@0: * Constant for Bhadra the 6th month of the Indian year michael@0: */ michael@0: BHADRA, michael@0: michael@0: /** michael@0: * Constant for the Asvina, the 7th month of the Indian year. michael@0: */ michael@0: ASVINA, michael@0: michael@0: /** michael@0: * Constant for Kartika, the 8th month of the Indian year. michael@0: */ michael@0: KARTIKA, michael@0: michael@0: /** michael@0: * Constant for Agrahayana, the 9th month of the Indian year. michael@0: */ michael@0: AGRAHAYANA, michael@0: michael@0: /** michael@0: * Constant for Pausa, the 10th month of the Indian year. michael@0: */ michael@0: PAUSA, michael@0: michael@0: /** michael@0: * Constant for Magha, the 11th month of the Indian year. michael@0: */ michael@0: MAGHA, michael@0: michael@0: /** michael@0: * Constant for Phalguna, the 12th month of the Indian year. michael@0: */ michael@0: PHALGUNA michael@0: }; michael@0: michael@0: //------------------------------------------------------------------------- michael@0: // Constructors... michael@0: //------------------------------------------------------------------------- michael@0: michael@0: /** michael@0: * Constructs an IndianCalendar based on the current time in the default time zone michael@0: * with the given locale. michael@0: * michael@0: * @param aLocale The given locale. michael@0: * @param success Indicates the status of IndianCalendar object construction. michael@0: * Returns U_ZERO_ERROR if constructed successfully. michael@0: * @param beCivil Whether the calendar should be civil (default-TRUE) or religious (FALSE) michael@0: * @internal michael@0: */ michael@0: IndianCalendar(const Locale& aLocale, UErrorCode &success); michael@0: michael@0: /** michael@0: * Copy Constructor michael@0: * @internal michael@0: */ michael@0: IndianCalendar(const IndianCalendar& other); michael@0: michael@0: /** michael@0: * Destructor. michael@0: * @internal michael@0: */ michael@0: virtual ~IndianCalendar(); michael@0: michael@0: /** michael@0: * Determines whether this object uses the fixed-cycle Indian civil calendar michael@0: * or an approximation of the religious, astronomical calendar. michael@0: * michael@0: * @param beCivil CIVIL to use the civil calendar, michael@0: * ASTRONOMICAL to use the astronomical calendar. michael@0: * @internal michael@0: */ michael@0: //void setCivil(ECivil beCivil, UErrorCode &status); michael@0: michael@0: /** michael@0: * Returns true if this object is using the fixed-cycle civil michael@0: * calendar, or false if using the religious, astronomical michael@0: * calendar. michael@0: * @internal michael@0: */ michael@0: //UBool isCivil(); michael@0: michael@0: michael@0: // TODO: copy c'tor, etc michael@0: michael@0: // clone michael@0: virtual Calendar* clone() const; michael@0: michael@0: private: michael@0: /** michael@0: * Determine whether a year is the gregorian year a leap year michael@0: */ michael@0: //static UBool isGregorianLeap(int32_t year); michael@0: //---------------------------------------------------------------------- michael@0: // Calendar framework michael@0: //---------------------------------------------------------------------- michael@0: protected: michael@0: /** michael@0: * @internal michael@0: */ michael@0: virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const; michael@0: michael@0: /** michael@0: * Return the length (in days) of the given month. michael@0: * michael@0: * @param year The year in Saka era michael@0: * @param year The month(0-based) in Indian year michael@0: * @internal michael@0: */ michael@0: virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month) const; michael@0: michael@0: /** michael@0: * Return the number of days in the given Indian year michael@0: * @internal michael@0: */ michael@0: virtual int32_t handleGetYearLength(int32_t extendedYear) const; michael@0: michael@0: //------------------------------------------------------------------------- michael@0: // Functions for converting from field values to milliseconds.... michael@0: //------------------------------------------------------------------------- michael@0: michael@0: // Return JD of start of given month/year michael@0: /** michael@0: * @internal michael@0: */ michael@0: virtual int32_t handleComputeMonthStart(int32_t eyear, int32_t month, UBool useMonth) const; michael@0: michael@0: //------------------------------------------------------------------------- michael@0: // Functions for converting from milliseconds to field values michael@0: //------------------------------------------------------------------------- michael@0: michael@0: /** michael@0: * @internal michael@0: */ michael@0: virtual int32_t handleGetExtendedYear(); michael@0: michael@0: /** michael@0: * Override Calendar to compute several fields specific to the Indian michael@0: * calendar system. These are: michael@0: * michael@0: *

michael@0: * michael@0: * The DAY_OF_WEEK and DOW_LOCAL fields are already set when this michael@0: * method is called. The getGregorianXxx() methods return Gregorian michael@0: * calendar equivalents for the given Julian day. michael@0: * @internal michael@0: */ michael@0: virtual void handleComputeFields(int32_t julianDay, UErrorCode &status); michael@0: michael@0: // UObject stuff michael@0: public: michael@0: /** michael@0: * @return The class ID for this object. All objects of a given class have the michael@0: * same class ID. Objects of other classes have different class IDs. michael@0: * @internal michael@0: */ michael@0: virtual UClassID getDynamicClassID(void) const; michael@0: michael@0: /** michael@0: * Return the class ID for this class. This is useful only for comparing to a return michael@0: * value from getDynamicClassID(). For example: michael@0: * michael@0: * Base* polymorphic_pointer = createPolymorphicObject(); michael@0: * if (polymorphic_pointer->getDynamicClassID() == michael@0: * Derived::getStaticClassID()) ... michael@0: * michael@0: * @return The class ID for all objects of this class. michael@0: * @internal michael@0: */ michael@0: U_I18N_API static UClassID U_EXPORT2 getStaticClassID(void); michael@0: michael@0: /** michael@0: * return the calendar type, "buddhist". michael@0: * michael@0: * @return calendar type michael@0: * @internal michael@0: */ michael@0: virtual const char * getType() const; michael@0: michael@0: private: michael@0: IndianCalendar(); // default constructor not implemented michael@0: michael@0: // Default century. michael@0: protected: michael@0: michael@0: /** michael@0: * (Overrides Calendar) Return true if the current date for this Calendar is in michael@0: * Daylight Savings Time. Recognizes DST_OFFSET, if it is set. michael@0: * michael@0: * @param status Fill-in parameter which receives the status of this operation. michael@0: * @return True if the current date for this Calendar is in Daylight Savings Time, michael@0: * false, otherwise. michael@0: * @internal michael@0: */ michael@0: virtual UBool inDaylightTime(UErrorCode& status) const; michael@0: michael@0: michael@0: /** michael@0: * Returns TRUE because the Indian Calendar does have a default century michael@0: * @internal michael@0: */ michael@0: virtual UBool haveDefaultCentury() const; michael@0: michael@0: /** michael@0: * Returns the date of the start of the default century michael@0: * @return start of century - in milliseconds since epoch, 1970 michael@0: * @internal michael@0: */ michael@0: virtual UDate defaultCenturyStart() const; michael@0: michael@0: /** michael@0: * Returns the year in which the default century begins michael@0: * @internal michael@0: */ michael@0: virtual int32_t defaultCenturyStartYear() const; michael@0: michael@0: private: // default century stuff. michael@0: /** michael@0: * The system maintains a static default century start date. This is initialized michael@0: * the first time it is used. Before then, it is set to SYSTEM_DEFAULT_CENTURY to michael@0: * indicate an uninitialized state. Once the system default century date and year michael@0: * are set, they do not change. michael@0: */ michael@0: static UDate fgSystemDefaultCenturyStart; michael@0: michael@0: /** michael@0: * See documentation for systemDefaultCenturyStart. michael@0: */ michael@0: static int32_t fgSystemDefaultCenturyStartYear; michael@0: michael@0: /** michael@0: * Default value that indicates the defaultCenturyStartYear is unitialized michael@0: */ michael@0: static const int32_t fgSystemDefaultCenturyYear; michael@0: michael@0: /** michael@0: * start of default century, as a date michael@0: */ michael@0: static const UDate fgSystemDefaultCentury; michael@0: michael@0: /** michael@0: * Returns the beginning date of the 100-year window that dates michael@0: * with 2-digit years are considered to fall within. michael@0: */ michael@0: UDate internalGetDefaultCenturyStart(void) const; michael@0: michael@0: /** michael@0: * Returns the first year of the 100-year window that dates with michael@0: * 2-digit years are considered to fall within. michael@0: */ michael@0: int32_t internalGetDefaultCenturyStartYear(void) const; michael@0: michael@0: /** michael@0: * Initializes the 100-year window that dates with 2-digit years michael@0: * are considered to fall within so that its start date is 80 years michael@0: * before the current time. michael@0: */ michael@0: static void initializeSystemDefaultCentury(void); michael@0: }; michael@0: michael@0: U_NAMESPACE_END michael@0: michael@0: #endif michael@0: #endif michael@0: michael@0: michael@0: