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