2 *****************************************************************************
3 * Copyright (C) 2003-2008, International Business Machines Corporation
4 * and others. All Rights Reserved.
5 *****************************************************************************
8 *****************************************************************************
14 #include "unicode/utypes.h"
16 #if !UCONFIG_NO_FORMATTING
18 #include "unicode/calendar.h"
23 * Concrete class which provides the Indian calendar.
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.
32 * A variant of the Shalivahana Calendar was reformed and standardized as the
33 * Indian National calendar in 1957.
35 * Some details of Indian National Calendar (to be implemented) :
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
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
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.
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.
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>.
69 class IndianCalendar
: public Calendar
{
72 * Useful constants for IndianCalendar.
77 * Constant for Chaitra, the 1st month of the Indian year.
82 * Constant for Vaisakha, the 2nd month of the Indian year.
87 * Constant for Jyaistha, the 3rd month of the Indian year.
92 * Constant for Asadha, the 4th month of the Indian year.
97 * Constant for Sravana, the 5th month of the Indian year.
102 * Constant for Bhadra the 6th month of the Indian year
107 * Constant for the Asvina, the 7th month of the Indian year.
112 * Constant for Kartika, the 8th month of the Indian year.
117 * Constant for Agrahayana, the 9th month of the Indian year.
122 * Constant for Pausa, the 10th month of the Indian year.
127 * Constant for Magha, the 11th month of the Indian year.
132 * Constant for Phalguna, the 12th month of the Indian year.
137 //-------------------------------------------------------------------------
139 //-------------------------------------------------------------------------
142 * Constructs an IndianCalendar based on the current time in the default time zone
143 * with the given locale.
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)
151 IndianCalendar(const Locale
& aLocale
, UErrorCode
&success
);
157 IndianCalendar(const IndianCalendar
& other
);
163 virtual ~IndianCalendar();
166 * Determines whether this object uses the fixed-cycle Indian civil calendar
167 * or an approximation of the religious, astronomical calendar.
169 * @param beCivil <code>CIVIL</code> to use the civil calendar,
170 * <code>ASTRONOMICAL</code> to use the astronomical calendar.
173 //void setCivil(ECivil beCivil, UErrorCode &status);
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
184 // TODO: copy c'tor, etc
187 virtual Calendar
* clone() const;
191 * Determine whether a year is the gregorian year a leap year
193 //static UBool isGregorianLeap(int32_t year);
194 //----------------------------------------------------------------------
195 // Calendar framework
196 //----------------------------------------------------------------------
201 virtual int32_t handleGetLimit(UCalendarDateFields field
, ELimitType limitType
) const;
204 * Return the length (in days) of the given month.
206 * @param year The year in Saka era
207 * @param year The month(0-based) in Indian year
210 virtual int32_t handleGetMonthLength(int32_t extendedYear
, int32_t month
) const;
213 * Return the number of days in the given Indian year
216 virtual int32_t handleGetYearLength(int32_t extendedYear
) const;
218 //-------------------------------------------------------------------------
219 // Functions for converting from field values to milliseconds....
220 //-------------------------------------------------------------------------
222 // Return JD of start of given month/year
226 virtual int32_t handleComputeMonthStart(int32_t eyear
, int32_t month
, UBool useMonth
) const;
228 //-------------------------------------------------------------------------
229 // Functions for converting from milliseconds to field values
230 //-------------------------------------------------------------------------
235 virtual int32_t handleGetExtendedYear();
238 * Override Calendar to compute several fields specific to the Indian
239 * calendar system. These are:
246 * <li>EXTENDED_YEAR</ul>
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.
253 virtual void handleComputeFields(int32_t julianDay
, UErrorCode
&status
);
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.
262 virtual UClassID
getDynamicClassID(void) const;
265 * Return the class ID for this class. This is useful only for comparing to a return
266 * value from getDynamicClassID(). For example:
268 * Base* polymorphic_pointer = createPolymorphicObject();
269 * if (polymorphic_pointer->getDynamicClassID() ==
270 * Derived::getStaticClassID()) ...
272 * @return The class ID for all objects of this class.
275 U_I18N_API
static UClassID U_EXPORT2
getStaticClassID(void);
278 * return the calendar type, "buddhist".
280 * @return calendar type
283 virtual const char * getType() const;
286 IndianCalendar(); // default constructor not implemented
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.
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,
300 virtual UBool
inDaylightTime(UErrorCode
& status
) const;
304 * Returns TRUE because the Indian Calendar does have a default century
307 virtual UBool
haveDefaultCentury() const;
310 * Returns the date of the start of the default century
311 * @return start of century - in milliseconds since epoch, 1970
314 virtual UDate
defaultCenturyStart() const;
317 * Returns the year in which the default century begins
320 virtual int32_t defaultCenturyStartYear() const;
322 private: // default century stuff.
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.
329 static UDate fgSystemDefaultCenturyStart
;
332 * See documentation for systemDefaultCenturyStart.
334 static int32_t fgSystemDefaultCenturyStartYear
;
337 * Default value that indicates the defaultCenturyStartYear is unitialized
339 static const int32_t fgSystemDefaultCenturyYear
;
342 * start of default century, as a date
344 static const UDate fgSystemDefaultCentury
;
347 * Returns the beginning date of the 100-year window that dates
348 * with 2-digit years are considered to fall within.
350 UDate
internalGetDefaultCenturyStart(void) const;
353 * Returns the first year of the 100-year window that dates with
354 * 2-digit years are considered to fall within.
356 int32_t internalGetDefaultCenturyStartYear(void) const;
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.
363 static void initializeSystemDefaultCentury(void);