persncal.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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-2013, International Business Machines Corporation
  6. * and others. All Rights Reserved.
  7. ******************************************************************************
  8. *
  9. * File PERSNCAL.H
  10. *
  11. * Modification History:
  12. *
  13. * Date Name Description
  14. * 9/23/2003 mehran posted to icu-design
  15. *****************************************************************************
  16. */
  17. #ifndef PERSNCAL_H
  18. #define PERSNCAL_H
  19. #include "unicode/utypes.h"
  20. #if !UCONFIG_NO_FORMATTING
  21. #include "unicode/calendar.h"
  22. U_NAMESPACE_BEGIN
  23. /**
  24. * <code>PersianCalendar</code> is a subclass of <code>Calendar</code>
  25. * that implements the Persian calendar. It is used as the official
  26. * calendar in Iran. This calendar is also known as the "Hijri Shamsi"
  27. * calendar, since it starts at the time of Mohammed's emigration (or
  28. * "hijra") to Medinah on Thursday, July 15, 622 AD (Julian) and is a
  29. * solar calendar system (or "shamsi").
  30. * <p>
  31. * The Persian calendar is strictly solar, and thus a Persian year has twelve
  32. * solar months. A Persian year is about 365 days long, except in leap years
  33. * which is 366 days long.
  34. * <p>
  35. * The six first months of Persian Calendar are 31 days long. The next five
  36. * months are 30 days long. The last month is 29 days long in normal years,
  37. * and 30 days long in leap years.
  38. *
  39. * @see GregorianCalendar
  40. *
  41. * @author Mehran Mehr
  42. * @internal
  43. */
  44. class PersianCalendar : public Calendar {
  45. public:
  46. //-------------------------------------------------------------------------
  47. // Constants...
  48. //-------------------------------------------------------------------------
  49. /**
  50. * Constants for the months
  51. * @internal
  52. */
  53. enum EMonths {
  54. /**
  55. * Constant for Farvardin, the 1st month of the Persian year.
  56. * @internal
  57. */
  58. FARVARDIN = 0,
  59. /**
  60. * Constant for Ordibehesht, the 2nd month of the Persian year.
  61. * @internal
  62. */
  63. ORDIBEHESHT = 1,
  64. /**
  65. * Constant for Khordad, the 3rd month of the Persian year.
  66. * @internal
  67. */
  68. KHORDAD = 2,
  69. /**
  70. * Constant for Tir, the 4th month of the Persian year.
  71. * @internal
  72. */
  73. TIR = 3,
  74. /**
  75. * Constant for Mordad, the 5th month of the Persian year.
  76. * @internal
  77. */
  78. MORDAD = 4,
  79. /**
  80. * Constant for Shahrivar, the 6th month of the Persian year.
  81. * @internal
  82. */
  83. SHAHRIVAR = 5,
  84. /**
  85. * Constant for Mehr, the 7th month of the Persian year.
  86. * @internal
  87. */
  88. MEHR = 6,
  89. /**
  90. * Constant for Aban, the 8th month of the Persian year.
  91. * @internal
  92. */
  93. ABAN = 7,
  94. /**
  95. * Constant for Azar, the 9th month of the Persian year.
  96. * @internal
  97. */
  98. AZAR = 8,
  99. /**
  100. * Constant for Dei, the 10th month of the Persian year.
  101. * @internal
  102. */
  103. DEI = 9,
  104. /**
  105. * Constant for Bahman, the 11th month of the Persian year.
  106. * @internal
  107. */
  108. BAHMAN = 10,
  109. /**
  110. * Constant for Esfand, the 12th month of the Persian year.
  111. * @internal
  112. */
  113. ESFAND = 11,
  114. PERSIAN_MONTH_MAX
  115. };
  116. //-------------------------------------------------------------------------
  117. // Constructors...
  118. //-------------------------------------------------------------------------
  119. /**
  120. * Constructs a PersianCalendar based on the current time in the default time zone
  121. * with the given locale.
  122. *
  123. * @param aLocale The given locale.
  124. * @param success Indicates the status of PersianCalendar object construction.
  125. * Returns U_ZERO_ERROR if constructed successfully.
  126. * @internal
  127. */
  128. PersianCalendar(const Locale& aLocale, UErrorCode &success);
  129. /**
  130. * Copy Constructor
  131. * @internal
  132. */
  133. PersianCalendar(const PersianCalendar& other);
  134. /**
  135. * Destructor.
  136. * @internal
  137. */
  138. virtual ~PersianCalendar();
  139. // TODO: copy c'tor, etc
  140. // clone
  141. virtual PersianCalendar* clone() const;
  142. private:
  143. /**
  144. * Determine whether a year is a leap year in the Persian calendar
  145. */
  146. static UBool isLeapYear(int32_t year);
  147. /**
  148. * Return the day # on which the given year starts. Days are counted
  149. * from the Hijri epoch, origin 0.
  150. */
  151. int32_t yearStart(int32_t year);
  152. /**
  153. * Return the day # on which the given month starts. Days are counted
  154. * from the Hijri epoch, origin 0.
  155. *
  156. * @param year The hijri shamsi year
  157. * @param year The hijri shamsi month, 0-based
  158. */
  159. int32_t monthStart(int32_t year, int32_t month) const;
  160. //----------------------------------------------------------------------
  161. // Calendar framework
  162. //----------------------------------------------------------------------
  163. protected:
  164. /**
  165. * @internal
  166. */
  167. virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const;
  168. /**
  169. * Return the length (in days) of the given month.
  170. *
  171. * @param year The hijri shamsi year
  172. * @param year The hijri shamsi month, 0-based
  173. * @internal
  174. */
  175. virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month) const;
  176. /**
  177. * Return the number of days in the given Persian year
  178. * @internal
  179. */
  180. virtual int32_t handleGetYearLength(int32_t extendedYear) const;
  181. //-------------------------------------------------------------------------
  182. // Functions for converting from field values to milliseconds....
  183. //-------------------------------------------------------------------------
  184. // Return JD of start of given month/year
  185. /**
  186. * @internal
  187. */
  188. virtual int32_t handleComputeMonthStart(int32_t eyear, int32_t month, UBool useMonth) const;
  189. //-------------------------------------------------------------------------
  190. // Functions for converting from milliseconds to field values
  191. //-------------------------------------------------------------------------
  192. /**
  193. * @internal
  194. */
  195. virtual int32_t handleGetExtendedYear();
  196. /**
  197. * Override Calendar to compute several fields specific to the Persian
  198. * calendar system. These are:
  199. *
  200. * <ul><li>ERA
  201. * <li>YEAR
  202. * <li>MONTH
  203. * <li>DAY_OF_MONTH
  204. * <li>DAY_OF_YEAR
  205. * <li>EXTENDED_YEAR</ul>
  206. *
  207. * The DAY_OF_WEEK and DOW_LOCAL fields are already set when this
  208. * method is called. The getGregorianXxx() methods return Gregorian
  209. * calendar equivalents for the given Julian day.
  210. * @internal
  211. */
  212. virtual void handleComputeFields(int32_t julianDay, UErrorCode &status);
  213. // UObject stuff
  214. public:
  215. /**
  216. * @return The class ID for this object. All objects of a given class have the
  217. * same class ID. Objects of other classes have different class IDs.
  218. * @internal
  219. */
  220. virtual UClassID getDynamicClassID(void) const;
  221. /**
  222. * Return the class ID for this class. This is useful only for comparing to a return
  223. * value from getDynamicClassID(). For example:
  224. *
  225. * Base* polymorphic_pointer = createPolymorphicObject();
  226. * if (polymorphic_pointer->getDynamicClassID() ==
  227. * Derived::getStaticClassID()) ...
  228. *
  229. * @return The class ID for all objects of this class.
  230. * @internal
  231. */
  232. U_I18N_API static UClassID U_EXPORT2 getStaticClassID(void);
  233. /**
  234. * return the calendar type, "persian".
  235. *
  236. * @return calendar type
  237. * @internal
  238. */
  239. virtual const char * getType() const;
  240. private:
  241. PersianCalendar(); // default constructor not implemented
  242. protected:
  243. /**
  244. * (Overrides Calendar) Return true if the current date for this Calendar is in
  245. * Daylight Savings Time. Recognizes DST_OFFSET, if it is set.
  246. *
  247. * @param status Fill-in parameter which receives the status of this operation.
  248. * @return True if the current date for this Calendar is in Daylight Savings Time,
  249. * false, otherwise.
  250. * @internal
  251. */
  252. virtual UBool inDaylightTime(UErrorCode& status) const;
  253. /**
  254. * Returns TRUE because the Persian Calendar does have a default century
  255. * @internal
  256. */
  257. virtual UBool haveDefaultCentury() const;
  258. /**
  259. * Returns the date of the start of the default century
  260. * @return start of century - in milliseconds since epoch, 1970
  261. * @internal
  262. */
  263. virtual UDate defaultCenturyStart() const;
  264. /**
  265. * Returns the year in which the default century begins
  266. * @internal
  267. */
  268. virtual int32_t defaultCenturyStartYear() const;
  269. };
  270. U_NAMESPACE_END
  271. #endif
  272. #endif