michael@0: /*
michael@0: ******************************************************************************
michael@0: * Copyright (C) 2003-2013, International Business Machines Corporation
michael@0: * and others. All Rights Reserved.
michael@0: ******************************************************************************
michael@0: *
michael@0: * File PERSNCAL.H
michael@0: *
michael@0: * Modification History:
michael@0: *
michael@0: * Date Name Description
michael@0: * 9/23/2003 mehran posted to icu-design
michael@0: *****************************************************************************
michael@0: */
michael@0:
michael@0: #ifndef PERSNCAL_H
michael@0: #define PERSNCAL_H
michael@0:
michael@0: #include "unicode/utypes.h"
michael@0:
michael@0: #if !UCONFIG_NO_FORMATTING
michael@0:
michael@0: #include "unicode/calendar.h"
michael@0:
michael@0: U_NAMESPACE_BEGIN
michael@0:
michael@0: /**
michael@0: * PersianCalendar
is a subclass of Calendar
michael@0: * that implements the Persian calendar. It is used as the official
michael@0: * calendar in Iran. This calendar is also known as the "Hijri Shamsi"
michael@0: * calendar, since it starts at the time of Mohammed's emigration (or
michael@0: * "hijra") to Medinah on Thursday, July 15, 622 AD (Julian) and is a
michael@0: * solar calendar system (or "shamsi").
michael@0: *
michael@0: * The Persian calendar is strictly solar, and thus a Persian year has twelve michael@0: * solar months. A Persian year is about 365 days long, except in leap years michael@0: * which is 366 days long. michael@0: *
michael@0: * The six first months of Persian Calendar are 31 days long. The next five michael@0: * months are 30 days long. The last month is 29 days long in normal years, michael@0: * and 30 days long in leap years. michael@0: * michael@0: * @see GregorianCalendar michael@0: * michael@0: * @author Mehran Mehr michael@0: * @internal michael@0: */ michael@0: class PersianCalendar : public Calendar { michael@0: public: michael@0: //------------------------------------------------------------------------- michael@0: // Constants... michael@0: //------------------------------------------------------------------------- michael@0: /** michael@0: * Constants for the months michael@0: * @internal michael@0: */ michael@0: enum EMonths { michael@0: /** michael@0: * Constant for Farvardin, the 1st month of the Persian year. michael@0: * @internal michael@0: */ michael@0: FARVARDIN = 0, michael@0: michael@0: /** michael@0: * Constant for Ordibehesht, the 2nd month of the Persian year. michael@0: * @internal michael@0: */ michael@0: ORDIBEHESHT = 1, michael@0: michael@0: /** michael@0: * Constant for Khordad, the 3rd month of the Persian year. michael@0: * @internal michael@0: */ michael@0: KHORDAD = 2, michael@0: michael@0: /** michael@0: * Constant for Tir, the 4th month of the Persian year. michael@0: * @internal michael@0: */ michael@0: TIR = 3, michael@0: michael@0: /** michael@0: * Constant for Mordad, the 5th month of the Persian year. michael@0: * @internal michael@0: */ michael@0: MORDAD = 4, michael@0: michael@0: /** michael@0: * Constant for Shahrivar, the 6th month of the Persian year. michael@0: * @internal michael@0: */ michael@0: SHAHRIVAR = 5, michael@0: michael@0: /** michael@0: * Constant for Mehr, the 7th month of the Persian year. michael@0: * @internal michael@0: */ michael@0: MEHR = 6, michael@0: michael@0: /** michael@0: * Constant for Aban, the 8th month of the Persian year. michael@0: * @internal michael@0: */ michael@0: ABAN = 7, michael@0: michael@0: /** michael@0: * Constant for Azar, the 9th month of the Persian year. michael@0: * @internal michael@0: */ michael@0: AZAR = 8, michael@0: michael@0: /** michael@0: * Constant for Dei, the 10th month of the Persian year. michael@0: * @internal michael@0: */ michael@0: DEI = 9, michael@0: michael@0: /** michael@0: * Constant for Bahman, the 11th month of the Persian year. michael@0: * @internal michael@0: */ michael@0: BAHMAN = 10, michael@0: michael@0: /** michael@0: * Constant for Esfand, the 12th month of the Persian year. michael@0: * @internal michael@0: */ michael@0: ESFAND = 11, michael@0: michael@0: PERSIAN_MONTH_MAX michael@0: }; michael@0: michael@0: michael@0: michael@0: //------------------------------------------------------------------------- michael@0: // Constructors... michael@0: //------------------------------------------------------------------------- michael@0: michael@0: /** michael@0: * Constructs a PersianCalendar based on the current time in the default time zone michael@0: * with the given locale. michael@0: * michael@0: * @param aLocale The given locale. michael@0: * @param success Indicates the status of PersianCalendar object construction. michael@0: * Returns U_ZERO_ERROR if constructed successfully. michael@0: * @internal michael@0: */ michael@0: PersianCalendar(const Locale& aLocale, UErrorCode &success); michael@0: michael@0: /** michael@0: * Copy Constructor michael@0: * @internal michael@0: */ michael@0: PersianCalendar(const PersianCalendar& other); michael@0: michael@0: /** michael@0: * Destructor. michael@0: * @internal michael@0: */ michael@0: virtual ~PersianCalendar(); michael@0: michael@0: // TODO: copy c'tor, etc michael@0: michael@0: // clone michael@0: virtual Calendar* clone() const; michael@0: michael@0: private: michael@0: /** michael@0: * Determine whether a year is a leap year in the Persian calendar michael@0: */ michael@0: static UBool isLeapYear(int32_t year); michael@0: michael@0: /** michael@0: * Return the day # on which the given year starts. Days are counted michael@0: * from the Hijri epoch, origin 0. michael@0: */ michael@0: int32_t yearStart(int32_t year); michael@0: michael@0: /** michael@0: * Return the day # on which the given month starts. Days are counted michael@0: * from the Hijri epoch, origin 0. michael@0: * michael@0: * @param year The hijri shamsi year michael@0: * @param year The hijri shamsi month, 0-based michael@0: */ michael@0: int32_t monthStart(int32_t year, int32_t month) const; michael@0: michael@0: //---------------------------------------------------------------------- michael@0: // Calendar framework michael@0: //---------------------------------------------------------------------- michael@0: protected: michael@0: /** michael@0: * @internal michael@0: */ michael@0: virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const; michael@0: michael@0: /** michael@0: * Return the length (in days) of the given month. michael@0: * michael@0: * @param year The hijri shamsi year michael@0: * @param year The hijri shamsi month, 0-based michael@0: * @internal michael@0: */ michael@0: virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month) const; michael@0: michael@0: /** michael@0: * Return the number of days in the given Persian year michael@0: * @internal michael@0: */ michael@0: virtual int32_t handleGetYearLength(int32_t extendedYear) const; michael@0: michael@0: //------------------------------------------------------------------------- michael@0: // Functions for converting from field values to milliseconds.... michael@0: //------------------------------------------------------------------------- michael@0: michael@0: // Return JD of start of given month/year michael@0: /** michael@0: * @internal michael@0: */ michael@0: virtual int32_t handleComputeMonthStart(int32_t eyear, int32_t month, UBool useMonth) const; michael@0: michael@0: //------------------------------------------------------------------------- michael@0: // Functions for converting from milliseconds to field values michael@0: //------------------------------------------------------------------------- michael@0: michael@0: /** michael@0: * @internal michael@0: */ michael@0: virtual int32_t handleGetExtendedYear(); michael@0: michael@0: /** michael@0: * Override Calendar to compute several fields specific to the Persian michael@0: * calendar system. These are: michael@0: * michael@0: *