2
******************************************************************************
3
* Copyright (C) 2003-2008, International Business Machines Corporation
4
* and others. All Rights Reserved.
5
******************************************************************************
9
* Modification History:
11
* Date Name Description
12
* 9/23/2003 mehran posted to icu-design
13
*****************************************************************************
19
#include "unicode/utypes.h"
21
#if !UCONFIG_NO_FORMATTING
23
#include "unicode/calendar.h"
28
* <code>PersianCalendar</code> is a subclass of <code>Calendar</code>
29
* that implements the Persian calendar. It is used as the official
30
* calendar in Iran. This calendar is also known as the "Hijri Shamsi"
31
* calendar, since it starts at the time of Mohammed's emigration (or
32
* "hijra") to Medinah on Thursday, July 15, 622 AD (Julian) and is a
33
* solar calendar system (or "shamsi").
35
* The Persian calendar is strictly solar, and thus a Persian year has twelve
36
* solar months. A Persian year is about 365 days long, except in leap years
37
* which is 366 days long.
39
* The six first months of Persian Calendar are 31 days long. The next five
40
* months are 30 days long. The last month is 29 days long in normal years,
41
* and 30 days long in leap years.
43
* @see GregorianCalendar
48
class PersianCalendar : public Calendar {
50
//-------------------------------------------------------------------------
52
//-------------------------------------------------------------------------
54
* Constants for the months
59
* Constant for Farvardin, the 1st month of the Persian year.
65
* Constant for Ordibehesht, the 2nd month of the Persian year.
71
* Constant for Khordad, the 3rd month of the Persian year.
77
* Constant for Tir, the 4th month of the Persian year.
83
* Constant for Mordad, the 5th month of the Persian year.
89
* Constant for Shahrivar, the 6th month of the Persian year.
95
* Constant for Mehr, the 7th month of the Persian year.
101
* Constant for Aban, the 8th month of the Persian year.
107
* Constant for Azar, the 9th month of the Persian year.
113
* Constant for Dei, the 10th month of the Persian year.
119
* Constant for Bahman, the 11th month of the Persian year.
125
* Constant for Esfand, the 12th month of the Persian year.
135
//-------------------------------------------------------------------------
137
//-------------------------------------------------------------------------
140
* Constructs a PersianCalendar based on the current time in the default time zone
141
* with the given locale.
143
* @param aLocale The given locale.
144
* @param success Indicates the status of PersianCalendar object construction.
145
* Returns U_ZERO_ERROR if constructed successfully.
148
PersianCalendar(const Locale& aLocale, UErrorCode &success);
154
PersianCalendar(const PersianCalendar& other);
160
virtual ~PersianCalendar();
162
// TODO: copy c'tor, etc
165
virtual Calendar* clone() const;
169
* Determine whether a year is a leap year in the Persian calendar
171
static UBool isLeapYear(int32_t year);
174
* Return the day # on which the given year starts. Days are counted
175
* from the Hijri epoch, origin 0.
177
int32_t yearStart(int32_t year);
180
* Return the day # on which the given month starts. Days are counted
181
* from the Hijri epoch, origin 0.
183
* @param year The hijri shamsi year
184
* @param year The hijri shamsi month, 0-based
186
int32_t monthStart(int32_t year, int32_t month) const;
188
//----------------------------------------------------------------------
189
// Calendar framework
190
//----------------------------------------------------------------------
195
virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const;
198
* Return the length (in days) of the given month.
200
* @param year The hijri shamsi year
201
* @param year The hijri shamsi month, 0-based
204
virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month) const;
207
* Return the number of days in the given Persian year
210
virtual int32_t handleGetYearLength(int32_t extendedYear) const;
212
//-------------------------------------------------------------------------
213
// Functions for converting from field values to milliseconds....
214
//-------------------------------------------------------------------------
216
// Return JD of start of given month/year
220
virtual int32_t handleComputeMonthStart(int32_t eyear, int32_t month, UBool useMonth) const;
222
//-------------------------------------------------------------------------
223
// Functions for converting from milliseconds to field values
224
//-------------------------------------------------------------------------
229
virtual int32_t handleGetExtendedYear();
232
* Override Calendar to compute several fields specific to the Persian
233
* calendar system. These are:
240
* <li>EXTENDED_YEAR</ul>
242
* The DAY_OF_WEEK and DOW_LOCAL fields are already set when this
243
* method is called. The getGregorianXxx() methods return Gregorian
244
* calendar equivalents for the given Julian day.
247
virtual void handleComputeFields(int32_t julianDay, UErrorCode &status);
252
* @return The class ID for this object. All objects of a given class have the
253
* same class ID. Objects of other classes have different class IDs.
256
virtual UClassID getDynamicClassID(void) const;
259
* Return the class ID for this class. This is useful only for comparing to a return
260
* value from getDynamicClassID(). For example:
262
* Base* polymorphic_pointer = createPolymorphicObject();
263
* if (polymorphic_pointer->getDynamicClassID() ==
264
* Derived::getStaticClassID()) ...
266
* @return The class ID for all objects of this class.
269
U_I18N_API static UClassID U_EXPORT2 getStaticClassID(void);
272
* return the calendar type, "persian".
274
* @return calendar type
277
virtual const char * getType() const;
280
PersianCalendar(); // default constructor not implemented
285
* (Overrides Calendar) Return true if the current date for this Calendar is in
286
* Daylight Savings Time. Recognizes DST_OFFSET, if it is set.
288
* @param status Fill-in parameter which receives the status of this operation.
289
* @return True if the current date for this Calendar is in Daylight Savings Time,
293
virtual UBool inDaylightTime(UErrorCode& status) const;
296
* Returns TRUE because the Persian Calendar does have a default century
299
virtual UBool haveDefaultCentury() const;
302
* Returns the date of the start of the default century
303
* @return start of century - in milliseconds since epoch, 1970
306
virtual UDate defaultCenturyStart() const;
309
* Returns the year in which the default century begins
312
virtual int32_t defaultCenturyStartYear() const;
314
private: // default century stuff.
316
* The system maintains a static default century start date. This is initialized
317
* the first time it is used. Before then, it is set to SYSTEM_DEFAULT_CENTURY to
318
* indicate an uninitialized state. Once the system default century date and year
319
* are set, they do not change.
321
static UDate fgSystemDefaultCenturyStart;
324
* See documentation for systemDefaultCenturyStart.
326
static int32_t fgSystemDefaultCenturyStartYear;
329
* Default value that indicates the defaultCenturyStartYear is unitialized
331
static const int32_t fgSystemDefaultCenturyYear;
334
* start of default century, as a date
336
static const UDate fgSystemDefaultCentury;
339
* Returns the beginning date of the 100-year window that dates
340
* with 2-digit years are considered to fall within.
342
UDate internalGetDefaultCenturyStart(void) const;
345
* Returns the first year of the 100-year window that dates with
346
* 2-digit years are considered to fall within.
348
int32_t internalGetDefaultCenturyStartYear(void) const;
351
* Initializes the 100-year window that dates with 2-digit years
352
* are considered to fall within so that its start date is 80 years
353
* before the current time.
355
static void initializeSystemDefaultCentury(void);