1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 ******************************************************************************
5 * Copyright (C) 2003-2013, International Business Machines Corporation
6 * and others. All Rights Reserved.
7 ******************************************************************************
11 * Modification History:
13 * Date Name Description
14 * 9/23/2003 mehran posted to icu-design
15 *****************************************************************************
21 #include "unicode/utypes.h"
23 #if !UCONFIG_NO_FORMATTING
25 #include "unicode/calendar.h"
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").
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.
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.
45 * @see GregorianCalendar
50 class PersianCalendar
: public Calendar
{
52 //-------------------------------------------------------------------------
54 //-------------------------------------------------------------------------
56 * Constants for the months
61 * Constant for Farvardin, the 1st month of the Persian year.
67 * Constant for Ordibehesht, the 2nd month of the Persian year.
73 * Constant for Khordad, the 3rd month of the Persian year.
79 * Constant for Tir, the 4th month of the Persian year.
85 * Constant for Mordad, the 5th month of the Persian year.
91 * Constant for Shahrivar, the 6th month of the Persian year.
97 * Constant for Mehr, the 7th month of the Persian year.
103 * Constant for Aban, the 8th month of the Persian year.
109 * Constant for Azar, the 9th month of the Persian year.
115 * Constant for Dei, the 10th month of the Persian year.
121 * Constant for Bahman, the 11th month of the Persian year.
127 * Constant for Esfand, the 12th month of the Persian year.
137 //-------------------------------------------------------------------------
139 //-------------------------------------------------------------------------
142 * Constructs a PersianCalendar based on the current time in the default time zone
143 * with the given locale.
145 * @param aLocale The given locale.
146 * @param success Indicates the status of PersianCalendar object construction.
147 * Returns U_ZERO_ERROR if constructed successfully.
150 PersianCalendar(const Locale
& aLocale
, UErrorCode
&success
);
156 PersianCalendar(const PersianCalendar
& other
);
162 virtual ~PersianCalendar();
164 // TODO: copy c'tor, etc
167 virtual Calendar
* clone() const;
171 * Determine whether a year is a leap year in the Persian calendar
173 static UBool
isLeapYear(int32_t year
);
176 * Return the day # on which the given year starts. Days are counted
177 * from the Hijri epoch, origin 0.
179 int32_t yearStart(int32_t year
);
182 * Return the day # on which the given month starts. Days are counted
183 * from the Hijri epoch, origin 0.
185 * @param year The hijri shamsi year
186 * @param year The hijri shamsi month, 0-based
188 int32_t monthStart(int32_t year
, int32_t month
) const;
190 //----------------------------------------------------------------------
191 // Calendar framework
192 //----------------------------------------------------------------------
197 virtual int32_t handleGetLimit(UCalendarDateFields field
, ELimitType limitType
) const;
200 * Return the length (in days) of the given month.
202 * @param year The hijri shamsi year
203 * @param year The hijri shamsi month, 0-based
206 virtual int32_t handleGetMonthLength(int32_t extendedYear
, int32_t month
) const;
209 * Return the number of days in the given Persian year
212 virtual int32_t handleGetYearLength(int32_t extendedYear
) const;
214 //-------------------------------------------------------------------------
215 // Functions for converting from field values to milliseconds....
216 //-------------------------------------------------------------------------
218 // Return JD of start of given month/year
222 virtual int32_t handleComputeMonthStart(int32_t eyear
, int32_t month
, UBool useMonth
) const;
224 //-------------------------------------------------------------------------
225 // Functions for converting from milliseconds to field values
226 //-------------------------------------------------------------------------
231 virtual int32_t handleGetExtendedYear();
234 * Override Calendar to compute several fields specific to the Persian
235 * calendar system. These are:
242 * <li>EXTENDED_YEAR</ul>
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.
249 virtual void handleComputeFields(int32_t julianDay
, UErrorCode
&status
);
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.
258 virtual UClassID
getDynamicClassID(void) const;
261 * Return the class ID for this class. This is useful only for comparing to a return
262 * value from getDynamicClassID(). For example:
264 * Base* polymorphic_pointer = createPolymorphicObject();
265 * if (polymorphic_pointer->getDynamicClassID() ==
266 * Derived::getStaticClassID()) ...
268 * @return The class ID for all objects of this class.
271 U_I18N_API
static UClassID U_EXPORT2
getStaticClassID(void);
274 * return the calendar type, "persian".
276 * @return calendar type
279 virtual const char * getType() const;
282 PersianCalendar(); // default constructor not implemented
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.
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,
295 virtual UBool
inDaylightTime(UErrorCode
& status
) const;
298 * Returns TRUE because the Persian Calendar does have a default century
301 virtual UBool
haveDefaultCentury() const;
304 * Returns the date of the start of the default century
305 * @return start of century - in milliseconds since epoch, 1970
308 virtual UDate
defaultCenturyStart() const;
311 * Returns the year in which the default century begins
314 virtual int32_t defaultCenturyStartYear() const;