1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/intl/icu/source/i18n/indiancal.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,372 @@ 1.4 +/* 1.5 + ***************************************************************************** 1.6 + * Copyright (C) 2003-2008, International Business Machines Corporation 1.7 + * and others. All Rights Reserved. 1.8 + ***************************************************************************** 1.9 + * 1.10 + * File INDIANCAL.H 1.11 + ***************************************************************************** 1.12 + */ 1.13 + 1.14 +#ifndef INDIANCAL_H 1.15 +#define INDIANCAL_H 1.16 + 1.17 +#include "unicode/utypes.h" 1.18 + 1.19 +#if !UCONFIG_NO_FORMATTING 1.20 + 1.21 +#include "unicode/calendar.h" 1.22 + 1.23 +U_NAMESPACE_BEGIN 1.24 + 1.25 +/** 1.26 + * Concrete class which provides the Indian calendar. 1.27 + * <P> 1.28 + * <code>IndianCalendar</code> is a subclass of <code>Calendar</code> 1.29 + * that numbers years since the begining of SAKA ERA. This is the civil calendar 1.30 + * which is accepted by government of India as Indian National Calendar. 1.31 + * The two calendars most widely used in India today are the Vikrama calendar 1.32 + * followed in North India and the Shalivahana or Saka calendar which is followed 1.33 + * in South India and Maharashtra. 1.34 + 1.35 + * A variant of the Shalivahana Calendar was reformed and standardized as the 1.36 + * Indian National calendar in 1957. 1.37 + * <p> 1.38 + * Some details of Indian National Calendar (to be implemented) : 1.39 + * The Months 1.40 + * Month Length Start date (Gregorian) 1.41 + * ================================================= 1.42 + * 1 Chaitra 30/31 March 22* 1.43 + * 2 Vaisakha 31 April 21 1.44 + * 3 Jyaistha 31 May 22 1.45 + * 4 Asadha 31 June 22 1.46 + * 5 Sravana 31 July 23 1.47 + * 6 Bhadra 31 August 23 1.48 + * 7 Asvina 30 September 23 1.49 + * 8 Kartika 30 October 23 1.50 + * 9 Agrahayana 30 November 22 1.51 + * 10 Pausa 30 December 22 1.52 + * 11 Magha 30 January 21 1.53 + * 12 Phalguna 30 February 20 1.54 + 1.55 + * In leap years, Chaitra has 31 days and starts on March 21 instead. 1.56 + * The leap years of Gregorian calendar and Indian National Calendar are in synchornization. 1.57 + * So When its a leap year in Gregorian calendar then Chaitra has 31 days. 1.58 + * 1.59 + * The Years 1.60 + * Years are counted in the Saka Era, which starts its year 0 in 78AD (by gregorian calendar). 1.61 + * So for eg. 9th June 2006 by Gregorian Calendar, is same as 19th of Jyaistha in 1928 of Saka 1.62 + * era by Indian National Calendar. 1.63 + * <p> 1.64 + * The Indian Calendar has only one allowable era: <code>Saka Era</code>. If the 1.65 + * calendar is not in lenient mode (see <code>setLenient</code>), dates before 1.66 + * 1/1/1 Saka Era are rejected with an <code>IllegalArgumentException</code>. 1.67 + * <p> 1.68 + * @internal 1.69 + */ 1.70 + 1.71 + 1.72 +class IndianCalendar : public Calendar { 1.73 +public: 1.74 + /** 1.75 + * Useful constants for IndianCalendar. 1.76 + * @internal 1.77 + */ 1.78 + enum EEras { 1.79 + /** 1.80 + * Constant for Chaitra, the 1st month of the Indian year. 1.81 + */ 1.82 + CHAITRA, 1.83 + 1.84 + /** 1.85 + * Constant for Vaisakha, the 2nd month of the Indian year. 1.86 + */ 1.87 + VAISAKHA, 1.88 + 1.89 + /** 1.90 + * Constant for Jyaistha, the 3rd month of the Indian year. 1.91 + */ 1.92 + JYAISTHA, 1.93 + 1.94 + /** 1.95 + * Constant for Asadha, the 4th month of the Indian year. 1.96 + */ 1.97 + ASADHA, 1.98 + 1.99 + /** 1.100 + * Constant for Sravana, the 5th month of the Indian year. 1.101 + */ 1.102 + SRAVANA, 1.103 + 1.104 + /** 1.105 + * Constant for Bhadra the 6th month of the Indian year 1.106 + */ 1.107 + BHADRA, 1.108 + 1.109 + /** 1.110 + * Constant for the Asvina, the 7th month of the Indian year. 1.111 + */ 1.112 + ASVINA, 1.113 + 1.114 + /** 1.115 + * Constant for Kartika, the 8th month of the Indian year. 1.116 + */ 1.117 + KARTIKA, 1.118 + 1.119 + /** 1.120 + * Constant for Agrahayana, the 9th month of the Indian year. 1.121 + */ 1.122 + AGRAHAYANA, 1.123 + 1.124 + /** 1.125 + * Constant for Pausa, the 10th month of the Indian year. 1.126 + */ 1.127 + PAUSA, 1.128 + 1.129 + /** 1.130 + * Constant for Magha, the 11th month of the Indian year. 1.131 + */ 1.132 + MAGHA, 1.133 + 1.134 + /** 1.135 + * Constant for Phalguna, the 12th month of the Indian year. 1.136 + */ 1.137 + PHALGUNA 1.138 + }; 1.139 + 1.140 + //------------------------------------------------------------------------- 1.141 + // Constructors... 1.142 + //------------------------------------------------------------------------- 1.143 + 1.144 + /** 1.145 + * Constructs an IndianCalendar based on the current time in the default time zone 1.146 + * with the given locale. 1.147 + * 1.148 + * @param aLocale The given locale. 1.149 + * @param success Indicates the status of IndianCalendar object construction. 1.150 + * Returns U_ZERO_ERROR if constructed successfully. 1.151 + * @param beCivil Whether the calendar should be civil (default-TRUE) or religious (FALSE) 1.152 + * @internal 1.153 + */ 1.154 + IndianCalendar(const Locale& aLocale, UErrorCode &success); 1.155 + 1.156 + /** 1.157 + * Copy Constructor 1.158 + * @internal 1.159 + */ 1.160 + IndianCalendar(const IndianCalendar& other); 1.161 + 1.162 + /** 1.163 + * Destructor. 1.164 + * @internal 1.165 + */ 1.166 + virtual ~IndianCalendar(); 1.167 + 1.168 + /** 1.169 + * Determines whether this object uses the fixed-cycle Indian civil calendar 1.170 + * or an approximation of the religious, astronomical calendar. 1.171 + * 1.172 + * @param beCivil <code>CIVIL</code> to use the civil calendar, 1.173 + * <code>ASTRONOMICAL</code> to use the astronomical calendar. 1.174 + * @internal 1.175 + */ 1.176 + //void setCivil(ECivil beCivil, UErrorCode &status); 1.177 + 1.178 + /** 1.179 + * Returns <code>true</code> if this object is using the fixed-cycle civil 1.180 + * calendar, or <code>false</code> if using the religious, astronomical 1.181 + * calendar. 1.182 + * @internal 1.183 + */ 1.184 + //UBool isCivil(); 1.185 + 1.186 + 1.187 + // TODO: copy c'tor, etc 1.188 + 1.189 + // clone 1.190 + virtual Calendar* clone() const; 1.191 + 1.192 + private: 1.193 + /** 1.194 + * Determine whether a year is the gregorian year a leap year 1.195 + */ 1.196 + //static UBool isGregorianLeap(int32_t year); 1.197 + //---------------------------------------------------------------------- 1.198 + // Calendar framework 1.199 + //---------------------------------------------------------------------- 1.200 + protected: 1.201 + /** 1.202 + * @internal 1.203 + */ 1.204 + virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const; 1.205 + 1.206 + /** 1.207 + * Return the length (in days) of the given month. 1.208 + * 1.209 + * @param year The year in Saka era 1.210 + * @param year The month(0-based) in Indian year 1.211 + * @internal 1.212 + */ 1.213 + virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month) const; 1.214 + 1.215 + /** 1.216 + * Return the number of days in the given Indian year 1.217 + * @internal 1.218 + */ 1.219 + virtual int32_t handleGetYearLength(int32_t extendedYear) const; 1.220 + 1.221 + //------------------------------------------------------------------------- 1.222 + // Functions for converting from field values to milliseconds.... 1.223 + //------------------------------------------------------------------------- 1.224 + 1.225 + // Return JD of start of given month/year 1.226 + /** 1.227 + * @internal 1.228 + */ 1.229 + virtual int32_t handleComputeMonthStart(int32_t eyear, int32_t month, UBool useMonth) const; 1.230 + 1.231 + //------------------------------------------------------------------------- 1.232 + // Functions for converting from milliseconds to field values 1.233 + //------------------------------------------------------------------------- 1.234 + 1.235 + /** 1.236 + * @internal 1.237 + */ 1.238 + virtual int32_t handleGetExtendedYear(); 1.239 + 1.240 + /** 1.241 + * Override Calendar to compute several fields specific to the Indian 1.242 + * calendar system. These are: 1.243 + * 1.244 + * <ul><li>ERA 1.245 + * <li>YEAR 1.246 + * <li>MONTH 1.247 + * <li>DAY_OF_MONTH 1.248 + * <li>DAY_OF_YEAR 1.249 + * <li>EXTENDED_YEAR</ul> 1.250 + * 1.251 + * The DAY_OF_WEEK and DOW_LOCAL fields are already set when this 1.252 + * method is called. The getGregorianXxx() methods return Gregorian 1.253 + * calendar equivalents for the given Julian day. 1.254 + * @internal 1.255 + */ 1.256 + virtual void handleComputeFields(int32_t julianDay, UErrorCode &status); 1.257 + 1.258 + // UObject stuff 1.259 + public: 1.260 + /** 1.261 + * @return The class ID for this object. All objects of a given class have the 1.262 + * same class ID. Objects of other classes have different class IDs. 1.263 + * @internal 1.264 + */ 1.265 + virtual UClassID getDynamicClassID(void) const; 1.266 + 1.267 + /** 1.268 + * Return the class ID for this class. This is useful only for comparing to a return 1.269 + * value from getDynamicClassID(). For example: 1.270 + * 1.271 + * Base* polymorphic_pointer = createPolymorphicObject(); 1.272 + * if (polymorphic_pointer->getDynamicClassID() == 1.273 + * Derived::getStaticClassID()) ... 1.274 + * 1.275 + * @return The class ID for all objects of this class. 1.276 + * @internal 1.277 + */ 1.278 + U_I18N_API static UClassID U_EXPORT2 getStaticClassID(void); 1.279 + 1.280 + /** 1.281 + * return the calendar type, "buddhist". 1.282 + * 1.283 + * @return calendar type 1.284 + * @internal 1.285 + */ 1.286 + virtual const char * getType() const; 1.287 + 1.288 +private: 1.289 + IndianCalendar(); // default constructor not implemented 1.290 + 1.291 + // Default century. 1.292 +protected: 1.293 + 1.294 + /** 1.295 + * (Overrides Calendar) Return true if the current date for this Calendar is in 1.296 + * Daylight Savings Time. Recognizes DST_OFFSET, if it is set. 1.297 + * 1.298 + * @param status Fill-in parameter which receives the status of this operation. 1.299 + * @return True if the current date for this Calendar is in Daylight Savings Time, 1.300 + * false, otherwise. 1.301 + * @internal 1.302 + */ 1.303 + virtual UBool inDaylightTime(UErrorCode& status) const; 1.304 + 1.305 + 1.306 + /** 1.307 + * Returns TRUE because the Indian Calendar does have a default century 1.308 + * @internal 1.309 + */ 1.310 + virtual UBool haveDefaultCentury() const; 1.311 + 1.312 + /** 1.313 + * Returns the date of the start of the default century 1.314 + * @return start of century - in milliseconds since epoch, 1970 1.315 + * @internal 1.316 + */ 1.317 + virtual UDate defaultCenturyStart() const; 1.318 + 1.319 + /** 1.320 + * Returns the year in which the default century begins 1.321 + * @internal 1.322 + */ 1.323 + virtual int32_t defaultCenturyStartYear() const; 1.324 + 1.325 + private: // default century stuff. 1.326 + /** 1.327 + * The system maintains a static default century start date. This is initialized 1.328 + * the first time it is used. Before then, it is set to SYSTEM_DEFAULT_CENTURY to 1.329 + * indicate an uninitialized state. Once the system default century date and year 1.330 + * are set, they do not change. 1.331 + */ 1.332 + static UDate fgSystemDefaultCenturyStart; 1.333 + 1.334 + /** 1.335 + * See documentation for systemDefaultCenturyStart. 1.336 + */ 1.337 + static int32_t fgSystemDefaultCenturyStartYear; 1.338 + 1.339 + /** 1.340 + * Default value that indicates the defaultCenturyStartYear is unitialized 1.341 + */ 1.342 + static const int32_t fgSystemDefaultCenturyYear; 1.343 + 1.344 + /** 1.345 + * start of default century, as a date 1.346 + */ 1.347 + static const UDate fgSystemDefaultCentury; 1.348 + 1.349 + /** 1.350 + * Returns the beginning date of the 100-year window that dates 1.351 + * with 2-digit years are considered to fall within. 1.352 + */ 1.353 + UDate internalGetDefaultCenturyStart(void) const; 1.354 + 1.355 + /** 1.356 + * Returns the first year of the 100-year window that dates with 1.357 + * 2-digit years are considered to fall within. 1.358 + */ 1.359 + int32_t internalGetDefaultCenturyStartYear(void) const; 1.360 + 1.361 + /** 1.362 + * Initializes the 100-year window that dates with 2-digit years 1.363 + * are considered to fall within so that its start date is 80 years 1.364 + * before the current time. 1.365 + */ 1.366 + static void initializeSystemDefaultCentury(void); 1.367 +}; 1.368 + 1.369 +U_NAMESPACE_END 1.370 + 1.371 +#endif 1.372 +#endif 1.373 + 1.374 + 1.375 +