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