• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4  *****************************************************************************
5  * Copyright (C) 2003-2008, International Business Machines Corporation
6  * and others. All Rights Reserved.
7  *****************************************************************************
8  *
9  * File INDIANCAL.H
10  *****************************************************************************
11  */
12 
13 #ifndef INDIANCAL_H
14 #define INDIANCAL_H
15 
16 #include "unicode/utypes.h"
17 
18 #if !UCONFIG_NO_FORMATTING
19 
20 #include "unicode/calendar.h"
21 
22 U_NAMESPACE_BEGIN
23 
24 /**
25  * Concrete class which provides the Indian calendar.
26  * <P>
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.
33 
34  * A variant of the Shalivahana Calendar was reformed and standardized as the
35  * Indian National calendar in 1957.
36  * <p>
37  * Some details of Indian National Calendar (to be implemented) :
38  * The Months
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
44  * 4 Asadha       31             June 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
53 
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.
57  *
58  * The Years
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.
62  * <p>
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>.
66  * <p>
67  * @internal
68  */
69 
70 
71 class U_I18N_API IndianCalendar : public Calendar {
72 public:
73   /**
74    * Useful constants for IndianCalendar.
75    * @internal
76    */
77   enum EEras {
78     /**
79      * Constant for Chaitra, the 1st month of the Indian year.
80      */
81       CHAITRA,
82 
83       /**
84      * Constant for Vaisakha, the 2nd month of the Indian year.
85      */
86       VAISAKHA,
87 
88       /**
89      * Constant for Jyaistha, the 3rd month of the Indian year.
90      */
91       JYAISTHA,
92 
93     /**
94      * Constant for Asadha, the 4th month of the Indian year.
95      */
96       ASADHA,
97 
98     /**
99      * Constant for Sravana, the 5th month of the Indian year.
100      */
101       SRAVANA,
102 
103     /**
104      * Constant for Bhadra the 6th month of the Indian year
105      */
106       BHADRA,
107 
108     /**
109      * Constant for the Asvina, the 7th month of the Indian year.
110      */
111       ASVINA,
112 
113     /**
114      * Constant for Kartika, the 8th month of the Indian year.
115      */
116       KARTIKA,
117 
118     /**
119      * Constant for Agrahayana, the 9th month of the Indian year.
120      */
121       AGRAHAYANA,
122 
123     /**
124      * Constant for Pausa, the 10th month of the Indian year.
125      */
126       PAUSA,
127 
128     /**
129      * Constant for Magha, the 11th month of the Indian year.
130      */
131       MAGHA,
132 
133     /**
134      * Constant for Phalguna, the 12th month of the Indian year.
135      */
136       PHALGUNA
137     };
138 
139   //-------------------------------------------------------------------------
140   // Constructors...
141   //-------------------------------------------------------------------------
142 
143   /**
144    * Constructs an IndianCalendar based on the current time in the default time zone
145    * with the given locale.
146    *
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)
151    * @internal
152    */
153   IndianCalendar(const Locale& aLocale, UErrorCode &success);
154 
155   /**
156    * Copy Constructor
157    * @internal
158    */
159   IndianCalendar(const IndianCalendar& other);
160 
161   /**
162    * Destructor.
163    * @internal
164    */
165   virtual ~IndianCalendar();
166 
167   /**
168    * Determines whether this object uses the fixed-cycle Indian civil calendar
169    * or an approximation of the religious, astronomical calendar.
170    *
171    * @param beCivil   <code>CIVIL</code> to use the civil calendar,
172    *                  <code>ASTRONOMICAL</code> to use the astronomical calendar.
173    * @internal
174    */
175   //void setCivil(ECivil beCivil, UErrorCode &status);
176 
177   /**
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
180    * calendar.
181    * @internal
182    */
183   //UBool isCivil();
184 
185 
186   // TODO: copy c'tor, etc
187 
188   // clone
189   virtual Calendar* clone() const;
190 
191  private:
192   /**
193    * Determine whether a year is the gregorian year a leap year
194    */
195   //static UBool isGregorianLeap(int32_t year);
196   //----------------------------------------------------------------------
197   // Calendar framework
198   //----------------------------------------------------------------------
199  protected:
200   /**
201    * @internal
202    */
203   virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const;
204 
205   /**
206    * Return the length (in days) of the given month.
207    *
208    * @param year  The year in Saka era
209    * @param year  The month(0-based) in Indian year
210    * @internal
211    */
212   virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month) const;
213 
214   /**
215    * Return the number of days in the given Indian year
216    * @internal
217    */
218   virtual int32_t handleGetYearLength(int32_t extendedYear) const;
219 
220   //-------------------------------------------------------------------------
221   // Functions for converting from field values to milliseconds....
222   //-------------------------------------------------------------------------
223 
224   // Return JD of start of given month/year
225   /**
226    * @internal
227    */
228   virtual int32_t handleComputeMonthStart(int32_t eyear, int32_t month, UBool useMonth) const;
229 
230   //-------------------------------------------------------------------------
231   // Functions for converting from milliseconds to field values
232   //-------------------------------------------------------------------------
233 
234   /**
235    * @internal
236    */
237   virtual int32_t handleGetExtendedYear();
238 
239   /**
240    * Override Calendar to compute several fields specific to the Indian
241    * calendar system.  These are:
242    *
243    * <ul><li>ERA
244    * <li>YEAR
245    * <li>MONTH
246    * <li>DAY_OF_MONTH
247    * <li>DAY_OF_YEAR
248    * <li>EXTENDED_YEAR</ul>
249    *
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.
253    * @internal
254    */
255   virtual void handleComputeFields(int32_t julianDay, UErrorCode &status);
256 
257   // UObject stuff
258  public:
259   /**
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.
262    * @internal
263    */
264   virtual UClassID getDynamicClassID(void) const;
265 
266   /**
267    * Return the class ID for this class. This is useful only for comparing to a return
268    * value from getDynamicClassID(). For example:
269    *
270    *      Base* polymorphic_pointer = createPolymorphicObject();
271    *      if (polymorphic_pointer->getDynamicClassID() ==
272    *          Derived::getStaticClassID()) ...
273    *
274    * @return   The class ID for all objects of this class.
275    * @internal
276    */
277   static UClassID U_EXPORT2 getStaticClassID(void);
278 
279   /**
280    * return the calendar type, "indian".
281    *
282    * @return calendar type
283    * @internal
284    */
285   virtual const char * getType() const;
286 
287 private:
288   IndianCalendar(); // default constructor not implemented
289 
290   // Default century.
291 protected:
292 
293   /**
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.
296    *
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,
299    *           false, otherwise.
300    * @internal
301    */
302   virtual UBool inDaylightTime(UErrorCode& status) const;
303 
304 
305   /**
306    * Returns TRUE because the Indian Calendar does have a default century
307    * @internal
308    */
309   virtual UBool haveDefaultCentury() const;
310 
311   /**
312    * Returns the date of the start of the default century
313    * @return start of century - in milliseconds since epoch, 1970
314    * @internal
315    */
316   virtual UDate defaultCenturyStart() const;
317 
318   /**
319    * Returns the year in which the default century begins
320    * @internal
321    */
322   virtual int32_t defaultCenturyStartYear() const;
323 };
324 
325 U_NAMESPACE_END
326 
327 #endif
328 #endif
329 
330 
331 
332