1 // Copyright (C) 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 *****************************************************************************
5 * Copyright (C) 2003-2008, International Business Machines Corporation
6 * and others. All Rights Reserved.
7 *****************************************************************************
10 *****************************************************************************
16 #include "unicode/utypes.h"
18 #if !UCONFIG_NO_FORMATTING
20 #include "unicode/calendar.h"
25 * Concrete class which provides the Indian calendar.
27 * <code>IndianCalendar</code> is a subclass of <code>Calendar</code>
28 * that numbers years since the begining of SAKA ERA. This is the civil calendar
29 * which is accepted by government of India as Indian National Calendar.
30 * The two calendars most widely used in India today are the Vikrama calendar
31 * followed in North India and the Shalivahana or Saka calendar which is followed
32 * in South India and Maharashtra.
34 * A variant of the Shalivahana Calendar was reformed and standardized as the
35 * Indian National calendar in 1957.
37 * Some details of Indian National Calendar (to be implemented) :
39 * Month Length Start date (Gregorian)
40 * =================================================
41 * 1 Chaitra 30/31 March 22*
42 * 2 Vaisakha 31 April 21
43 * 3 Jyaistha 31 May 22
45 * 5 Sravana 31 July 23
46 * 6 Bhadra 31 August 23
47 * 7 Asvina 30 September 23
48 * 8 Kartika 30 October 23
49 * 9 Agrahayana 30 November 22
50 * 10 Pausa 30 December 22
51 * 11 Magha 30 January 21
52 * 12 Phalguna 30 February 20
54 * In leap years, Chaitra has 31 days and starts on March 21 instead.
55 * The leap years of Gregorian calendar and Indian National Calendar are in synchornization.
56 * So When its a leap year in Gregorian calendar then Chaitra has 31 days.
59 * Years are counted in the Saka Era, which starts its year 0 in 78AD (by gregorian calendar).
60 * So for eg. 9th June 2006 by Gregorian Calendar, is same as 19th of Jyaistha in 1928 of Saka
61 * era by Indian National Calendar.
63 * The Indian Calendar has only one allowable era: <code>Saka Era</code>. If the
64 * calendar is not in lenient mode (see <code>setLenient</code>), dates before
65 * 1/1/1 Saka Era are rejected with an <code>IllegalArgumentException</code>.
71 class IndianCalendar : public Calendar {
74 * Useful constants for IndianCalendar.
79 * Constant for Chaitra, the 1st month of the Indian year.
84 * Constant for Vaisakha, the 2nd month of the Indian year.
89 * Constant for Jyaistha, the 3rd month of the Indian year.
94 * Constant for Asadha, the 4th month of the Indian year.
99 * Constant for Sravana, the 5th month of the Indian year.
104 * Constant for Bhadra the 6th month of the Indian year
109 * Constant for the Asvina, the 7th month of the Indian year.
114 * Constant for Kartika, the 8th month of the Indian year.
119 * Constant for Agrahayana, the 9th month of the Indian year.
124 * Constant for Pausa, the 10th month of the Indian year.
129 * Constant for Magha, the 11th month of the Indian year.
134 * Constant for Phalguna, the 12th month of the Indian year.
139 //-------------------------------------------------------------------------
141 //-------------------------------------------------------------------------
144 * Constructs an IndianCalendar based on the current time in the default time zone
145 * with the given locale.
147 * @param aLocale The given locale.
148 * @param success Indicates the status of IndianCalendar object construction.
149 * Returns U_ZERO_ERROR if constructed successfully.
150 * @param beCivil Whether the calendar should be civil (default-TRUE) or religious (FALSE)
153 IndianCalendar(const Locale& aLocale, UErrorCode &success);
159 IndianCalendar(const IndianCalendar& other);
165 virtual ~IndianCalendar();
168 * Determines whether this object uses the fixed-cycle Indian civil calendar
169 * or an approximation of the religious, astronomical calendar.
171 * @param beCivil <code>CIVIL</code> to use the civil calendar,
172 * <code>ASTRONOMICAL</code> to use the astronomical calendar.
175 //void setCivil(ECivil beCivil, UErrorCode &status);
178 * Returns <code>true</code> if this object is using the fixed-cycle civil
179 * calendar, or <code>false</code> if using the religious, astronomical
186 // TODO: copy c'tor, etc
189 virtual Calendar* clone() const;
193 * Determine whether a year is the gregorian year a leap year
195 //static UBool isGregorianLeap(int32_t year);
196 //----------------------------------------------------------------------
197 // Calendar framework
198 //----------------------------------------------------------------------
203 virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const;
206 * Return the length (in days) of the given month.
208 * @param year The year in Saka era
209 * @param year The month(0-based) in Indian year
212 virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month) const;
215 * Return the number of days in the given Indian year
218 virtual int32_t handleGetYearLength(int32_t extendedYear) const;
220 //-------------------------------------------------------------------------
221 // Functions for converting from field values to milliseconds....
222 //-------------------------------------------------------------------------
224 // Return JD of start of given month/year
228 virtual int32_t handleComputeMonthStart(int32_t eyear, int32_t month, UBool useMonth) const;
230 //-------------------------------------------------------------------------
231 // Functions for converting from milliseconds to field values
232 //-------------------------------------------------------------------------
237 virtual int32_t handleGetExtendedYear();
240 * Override Calendar to compute several fields specific to the Indian
241 * calendar system. These are:
248 * <li>EXTENDED_YEAR</ul>
250 * The DAY_OF_WEEK and DOW_LOCAL fields are already set when this
251 * method is called. The getGregorianXxx() methods return Gregorian
252 * calendar equivalents for the given Julian day.
255 virtual void handleComputeFields(int32_t julianDay, UErrorCode &status);
260 * @return The class ID for this object. All objects of a given class have the
261 * same class ID. Objects of other classes have different class IDs.
264 virtual UClassID getDynamicClassID(void) const;
267 * Return the class ID for this class. This is useful only for comparing to a return
268 * value from getDynamicClassID(). For example:
270 * Base* polymorphic_pointer = createPolymorphicObject();
271 * if (polymorphic_pointer->getDynamicClassID() ==
272 * Derived::getStaticClassID()) ...
274 * @return The class ID for all objects of this class.
277 U_I18N_API static UClassID U_EXPORT2 getStaticClassID(void);
280 * return the calendar type, "buddhist".
282 * @return calendar type
285 virtual const char * getType() const;
288 IndianCalendar(); // default constructor not implemented
294 * (Overrides Calendar) Return true if the current date for this Calendar is in
295 * Daylight Savings Time. Recognizes DST_OFFSET, if it is set.
297 * @param status Fill-in parameter which receives the status of this operation.
298 * @return True if the current date for this Calendar is in Daylight Savings Time,
302 virtual UBool inDaylightTime(UErrorCode& status) const;
306 * Returns TRUE because the Indian Calendar does have a default century
309 virtual UBool haveDefaultCentury() const;
312 * Returns the date of the start of the default century
313 * @return start of century - in milliseconds since epoch, 1970
316 virtual UDate defaultCenturyStart() const;
319 * Returns the year in which the default century begins
322 virtual int32_t defaultCenturyStartYear() const;
324 private: // default century stuff.
326 * The system maintains a static default century start date. This is initialized
327 * the first time it is used. Before then, it is set to SYSTEM_DEFAULT_CENTURY to
328 * indicate an uninitialized state. Once the system default century date and year
329 * are set, they do not change.
331 static UDate fgSystemDefaultCenturyStart;
334 * See documentation for systemDefaultCenturyStart.
336 static int32_t fgSystemDefaultCenturyStartYear;
339 * Default value that indicates the defaultCenturyStartYear is unitialized
341 static const int32_t fgSystemDefaultCenturyYear;
344 * start of default century, as a date
346 static const UDate fgSystemDefaultCentury;
349 * Returns the beginning date of the 100-year window that dates
350 * with 2-digit years are considered to fall within.
352 UDate internalGetDefaultCenturyStart(void) const;
355 * Returns the first year of the 100-year window that dates with
356 * 2-digit years are considered to fall within.
358 int32_t internalGetDefaultCenturyStartYear(void) const;
361 * Initializes the 100-year window that dates with 2-digit years
362 * are considered to fall within so that its start date is 80 years
363 * before the current time.
365 static void initializeSystemDefaultCentury(void);