indiancal.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  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. #ifndef INDIANCAL_H
  13. #define INDIANCAL_H
  14. #include "unicode/utypes.h"
  15. #if !UCONFIG_NO_FORMATTING
  16. #include "unicode/calendar.h"
  17. U_NAMESPACE_BEGIN
  18. /**
  19. * Concrete class which provides the Indian calendar.
  20. * <P>
  21. * <code>IndianCalendar</code> is a subclass of <code>Calendar</code>
  22. * that numbers years since the begining of SAKA ERA. This is the civil calendar
  23. * which is accepted by government of India as Indian National Calendar.
  24. * The two calendars most widely used in India today are the Vikrama calendar
  25. * followed in North India and the Shalivahana or Saka calendar which is followed
  26. * in South India and Maharashtra.
  27. * A variant of the Shalivahana Calendar was reformed and standardized as the
  28. * Indian National calendar in 1957.
  29. * <p>
  30. * Some details of Indian National Calendar (to be implemented) :
  31. * The Months
  32. * Month Length Start date (Gregorian)
  33. * =================================================
  34. * 1 Chaitra 30/31 March 22*
  35. * 2 Vaisakha 31 April 21
  36. * 3 Jyaistha 31 May 22
  37. * 4 Asadha 31 June 22
  38. * 5 Sravana 31 July 23
  39. * 6 Bhadra 31 August 23
  40. * 7 Asvina 30 September 23
  41. * 8 Kartika 30 October 23
  42. * 9 Agrahayana 30 November 22
  43. * 10 Pausa 30 December 22
  44. * 11 Magha 30 January 21
  45. * 12 Phalguna 30 February 20
  46. * In leap years, Chaitra has 31 days and starts on March 21 instead.
  47. * The leap years of Gregorian calendar and Indian National Calendar are in synchornization.
  48. * So When its a leap year in Gregorian calendar then Chaitra has 31 days.
  49. *
  50. * The Years
  51. * Years are counted in the Saka Era, which starts its year 0 in 78AD (by gregorian calendar).
  52. * So for eg. 9th June 2006 by Gregorian Calendar, is same as 19th of Jyaistha in 1928 of Saka
  53. * era by Indian National Calendar.
  54. * <p>
  55. * The Indian Calendar has only one allowable era: <code>Saka Era</code>. If the
  56. * calendar is not in lenient mode (see <code>setLenient</code>), dates before
  57. * 1/1/1 Saka Era are rejected with an <code>IllegalArgumentException</code>.
  58. * <p>
  59. * @internal
  60. */
  61. class U_I18N_API IndianCalendar : public Calendar {
  62. public:
  63. /**
  64. * Useful constants for IndianCalendar.
  65. * @internal
  66. */
  67. enum EEras {
  68. /**
  69. * Constant for Chaitra, the 1st month of the Indian year.
  70. */
  71. CHAITRA,
  72. /**
  73. * Constant for Vaisakha, the 2nd month of the Indian year.
  74. */
  75. VAISAKHA,
  76. /**
  77. * Constant for Jyaistha, the 3rd month of the Indian year.
  78. */
  79. JYAISTHA,
  80. /**
  81. * Constant for Asadha, the 4th month of the Indian year.
  82. */
  83. ASADHA,
  84. /**
  85. * Constant for Sravana, the 5th month of the Indian year.
  86. */
  87. SRAVANA,
  88. /**
  89. * Constant for Bhadra the 6th month of the Indian year
  90. */
  91. BHADRA,
  92. /**
  93. * Constant for the Asvina, the 7th month of the Indian year.
  94. */
  95. ASVINA,
  96. /**
  97. * Constant for Kartika, the 8th month of the Indian year.
  98. */
  99. KARTIKA,
  100. /**
  101. * Constant for Agrahayana, the 9th month of the Indian year.
  102. */
  103. AGRAHAYANA,
  104. /**
  105. * Constant for Pausa, the 10th month of the Indian year.
  106. */
  107. PAUSA,
  108. /**
  109. * Constant for Magha, the 11th month of the Indian year.
  110. */
  111. MAGHA,
  112. /**
  113. * Constant for Phalguna, the 12th month of the Indian year.
  114. */
  115. PHALGUNA
  116. };
  117. //-------------------------------------------------------------------------
  118. // Constructors...
  119. //-------------------------------------------------------------------------
  120. /**
  121. * Constructs an IndianCalendar based on the current time in the default time zone
  122. * with the given locale.
  123. *
  124. * @param aLocale The given locale.
  125. * @param success Indicates the status of IndianCalendar object construction.
  126. * Returns U_ZERO_ERROR if constructed successfully.
  127. * @param beCivil Whether the calendar should be civil (default-TRUE) or religious (FALSE)
  128. * @internal
  129. */
  130. IndianCalendar(const Locale& aLocale, UErrorCode &success);
  131. /**
  132. * Copy Constructor
  133. * @internal
  134. */
  135. IndianCalendar(const IndianCalendar& other);
  136. /**
  137. * Destructor.
  138. * @internal
  139. */
  140. virtual ~IndianCalendar();
  141. /**
  142. * Determines whether this object uses the fixed-cycle Indian civil calendar
  143. * or an approximation of the religious, astronomical calendar.
  144. *
  145. * @param beCivil <code>CIVIL</code> to use the civil calendar,
  146. * <code>ASTRONOMICAL</code> to use the astronomical calendar.
  147. * @internal
  148. */
  149. //void setCivil(ECivil beCivil, UErrorCode &status);
  150. /**
  151. * Returns <code>true</code> if this object is using the fixed-cycle civil
  152. * calendar, or <code>false</code> if using the religious, astronomical
  153. * calendar.
  154. * @internal
  155. */
  156. //UBool isCivil();
  157. // TODO: copy c'tor, etc
  158. // clone
  159. virtual IndianCalendar* clone() const;
  160. private:
  161. /**
  162. * Determine whether a year is the gregorian year a leap year
  163. */
  164. //static UBool isGregorianLeap(int32_t year);
  165. //----------------------------------------------------------------------
  166. // Calendar framework
  167. //----------------------------------------------------------------------
  168. protected:
  169. /**
  170. * @internal
  171. */
  172. virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const;
  173. /**
  174. * Return the length (in days) of the given month.
  175. *
  176. * @param year The year in Saka era
  177. * @param year The month(0-based) in Indian year
  178. * @internal
  179. */
  180. virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month) const;
  181. /**
  182. * Return the number of days in the given Indian year
  183. * @internal
  184. */
  185. virtual int32_t handleGetYearLength(int32_t extendedYear) const;
  186. //-------------------------------------------------------------------------
  187. // Functions for converting from field values to milliseconds....
  188. //-------------------------------------------------------------------------
  189. // Return JD of start of given month/year
  190. /**
  191. * @internal
  192. */
  193. virtual int32_t handleComputeMonthStart(int32_t eyear, int32_t month, UBool useMonth) const;
  194. //-------------------------------------------------------------------------
  195. // Functions for converting from milliseconds to field values
  196. //-------------------------------------------------------------------------
  197. /**
  198. * @internal
  199. */
  200. virtual int32_t handleGetExtendedYear();
  201. /**
  202. * Override Calendar to compute several fields specific to the Indian
  203. * calendar system. These are:
  204. *
  205. * <ul><li>ERA
  206. * <li>YEAR
  207. * <li>MONTH
  208. * <li>DAY_OF_MONTH
  209. * <li>DAY_OF_YEAR
  210. * <li>EXTENDED_YEAR</ul>
  211. *
  212. * The DAY_OF_WEEK and DOW_LOCAL fields are already set when this
  213. * method is called. The getGregorianXxx() methods return Gregorian
  214. * calendar equivalents for the given Julian day.
  215. * @internal
  216. */
  217. virtual void handleComputeFields(int32_t julianDay, UErrorCode &status);
  218. // UObject stuff
  219. public:
  220. /**
  221. * @return The class ID for this object. All objects of a given class have the
  222. * same class ID. Objects of other classes have different class IDs.
  223. * @internal
  224. */
  225. virtual UClassID getDynamicClassID(void) const;
  226. /**
  227. * Return the class ID for this class. This is useful only for comparing to a return
  228. * value from getDynamicClassID(). For example:
  229. *
  230. * Base* polymorphic_pointer = createPolymorphicObject();
  231. * if (polymorphic_pointer->getDynamicClassID() ==
  232. * Derived::getStaticClassID()) ...
  233. *
  234. * @return The class ID for all objects of this class.
  235. * @internal
  236. */
  237. static UClassID U_EXPORT2 getStaticClassID(void);
  238. /**
  239. * return the calendar type, "indian".
  240. *
  241. * @return calendar type
  242. * @internal
  243. */
  244. virtual const char * getType() const;
  245. private:
  246. IndianCalendar(); // default constructor not implemented
  247. // Default century.
  248. protected:
  249. /**
  250. * (Overrides Calendar) Return true if the current date for this Calendar is in
  251. * Daylight Savings Time. Recognizes DST_OFFSET, if it is set.
  252. *
  253. * @param status Fill-in parameter which receives the status of this operation.
  254. * @return True if the current date for this Calendar is in Daylight Savings Time,
  255. * false, otherwise.
  256. * @internal
  257. */
  258. virtual UBool inDaylightTime(UErrorCode& status) const;
  259. /**
  260. * Returns TRUE because the Indian Calendar does have a default century
  261. * @internal
  262. */
  263. virtual UBool haveDefaultCentury() const;
  264. /**
  265. * Returns the date of the start of the default century
  266. * @return start of century - in milliseconds since epoch, 1970
  267. * @internal
  268. */
  269. virtual UDate defaultCenturyStart() const;
  270. /**
  271. * Returns the year in which the default century begins
  272. * @internal
  273. */
  274. virtual int32_t defaultCenturyStartYear() const;
  275. };
  276. U_NAMESPACE_END
  277. #endif
  278. #endif