/*
* Copyright (C) 2003-2004, International Business Machines Corporation
* and others. All Rights Reserved.
******************************************************************************
*
* File ISLAMCAL.H
*
* Modification History:
*
* Date Name Description
* 10/14/2003 srl ported from java IslamicCalendar
*****************************************************************************
*/
#ifndef ISLAMCAL_H
#define ISLAMCAL_H
#include "unicode/utypes.h"
#if !UCONFIG_NO_FORMATTING
#include "unicode/calendar.h"
U_NAMESPACE_BEGIN
/**
* IslamicCalendar
is a subclass of Calendar
* that that implements the Islamic civil and religious calendars. It
* is used as the civil calendar in most of the Arab world and the
* liturgical calendar of the Islamic faith worldwide. This calendar
* is also known as the "Hijri" calendar, since it starts at the time
* of Mohammed's emigration (or "hijra") to Medinah on Thursday,
* July 15, 622 AD (Julian).
*
* The Islamic calendar is strictly lunar, and thus an Islamic year of twelve * lunar months does not correspond to the solar year used by most other * calendar systems, including the Gregorian. An Islamic year is, on average, * about 354 days long, so each successive Islamic year starts about 11 days * earlier in the corresponding Gregorian year. *
* Each month of the calendar starts when the new moon's crescent is visible * at sunset. However, in order to keep the time fields in this class * synchronized with those of the other calendars and with local clock time, * we treat days and months as beginning at midnight, * roughly 6 hours after the corresponding sunset. *
* There are two main variants of the Islamic calendar in existence. The first
* is the civil calendar, which uses a fixed cycle of alternating 29-
* and 30-day months, with a leap day added to the last month of 11 out of
* every 30 years. This calendar is easily calculated and thus predictable in
* advance, so it is used as the civil calendar in a number of Arab countries.
* This is the default behavior of a newly-created IslamicCalendar
* object.
*
* The Islamic religious calendar, however, is based on the observation * of the crescent moon. It is thus affected by the position at which the * observations are made, seasonal variations in the time of sunset, the * eccentricities of the moon's orbit, and even the weather at the observation * site. This makes it impossible to calculate in advance, and it causes the * start of a month in the religious calendar to differ from the civil calendar * by up to three days. *
* Using astronomical calculations for the position of the sun and moon, the * moon's illumination, and other factors, it is possible to determine the start * of a lunar month with a fairly high degree of certainty. However, these * calculations are extremely complicated and thus slow, so most algorithms, * including the one used here, are only approximations of the true astronical * calculations. At present, the approximations used in this class are fairly * simplistic; they will be improved in later versions of the code. *
* The {@link #setCivil setCivil} method determines
* which approach is used to determine the start of a month. By default, the
* fixed-cycle civil calendar is used. However, if setCivil(false)
* is called, an approximation of the true lunar calendar will be used.
*
* @see GregorianCalendar
*
* @author Laura Werner
* @author Alan Liu
* @author Steven R. Loomis
* @internal
*/
class U_I18N_API IslamicCalendar : public Calendar {
public:
//-------------------------------------------------------------------------
// Constants...
//-------------------------------------------------------------------------
/**
* Calendar type - civil or religious
* @internal
*/
enum ECivil {
ASTRONOMICAL,
CIVIL
};
/**
* Constants for the months
* @internal
*/
enum EMonths {
/**
* Constant for Muharram, the 1st month of the Islamic year.
* @internal
*/
MUHARRAM = 0,
/**
* Constant for Safar, the 2nd month of the Islamic year.
* @internal
*/
SAFAR = 1,
/**
* Constant for Rabi' al-awwal (or Rabi' I), the 3rd month of the Islamic year.
* @internal
*/
RABI_1 = 2,
/**
* Constant for Rabi' al-thani or (Rabi' II), the 4th month of the Islamic year.
* @internal
*/
RABI_2 = 3,
/**
* Constant for Jumada al-awwal or (Jumada I), the 5th month of the Islamic year.
* @internal
*/
JUMADA_1 = 4,
/**
* Constant for Jumada al-thani or (Jumada II), the 6th month of the Islamic year.
* @internal
*/
JUMADA_2 = 5,
/**
* Constant for Rajab, the 7th month of the Islamic year.
* @internal
*/
RAJAB = 6,
/**
* Constant for Sha'ban, the 8th month of the Islamic year.
* @internal
*/
SHABAN = 7,
/**
* Constant for Ramadan, the 9th month of the Islamic year.
* @internal
*/
RAMADAN = 8,
/**
* Constant for Shawwal, the 10th month of the Islamic year.
* @internal
*/
SHAWWAL = 9,
/**
* Constant for Dhu al-Qi'dah, the 11th month of the Islamic year.
* @internal
*/
DHU_AL_QIDAH = 10,
/**
* Constant for Dhu al-Hijjah, the 12th month of the Islamic year.
* @internal
*/
DHU_AL_HIJJAH = 11,
ISLAMIC_MONTH_MAX
};
//-------------------------------------------------------------------------
// Constructors...
//-------------------------------------------------------------------------
/**
* Constructs an IslamicCalendar based on the current time in the default time zone
* with the given locale.
*
* @param aLocale The given locale.
* @param success Indicates the status of IslamicCalendar object construction.
* Returns U_ZERO_ERROR if constructed successfully.
* @param beCivil Whether the calendar should be civil (default-TRUE) or religious (FALSE)
* @internal
*/
IslamicCalendar(const Locale& aLocale, UErrorCode &success, ECivil beCivil = CIVIL);
/**
* Copy Constructor
* @internal
*/
IslamicCalendar(const IslamicCalendar& other);
/**
* Destructor.
* @internal
*/
virtual ~IslamicCalendar();
/**
* Determines whether this object uses the fixed-cycle Islamic civil calendar
* or an approximation of the religious, astronomical calendar.
*
* @param beCivil CIVIL
to use the civil calendar,
* ASTRONOMICAL
to use the astronomical calendar.
* @internal
*/
void setCivil(ECivil beCivil, UErrorCode &status);
/**
* Returns true
if this object is using the fixed-cycle civil
* calendar, or false
if using the religious, astronomical
* calendar.
* @internal
*/
UBool isCivil();
// TODO: copy c'tor, etc
// clone
virtual Calendar* clone() const;
private:
/**
* Determine whether a year is a leap year in the Islamic civil calendar
*/
static UBool civilLeapYear(int32_t year);
/**
* Return the day # on which the given year starts. Days are counted
* from the Hijri epoch, origin 0.
*/
int32_t yearStart(int32_t year);
/**
* Return the day # on which the given month starts. Days are counted
* from the Hijri epoch, origin 0.
*
* @param year The hijri year
* @param year The hijri month, 0-based
*/
int32_t monthStart(int32_t year, int32_t month) const;
/**
* Find the day number on which a particular month of the true/lunar
* Islamic calendar starts.
*
* @param month The month in question, origin 0 from the Hijri epoch
*
* @return The day number on which the given month starts.
*/
int32_t trueMonthStart(int32_t month) const;
/**
* Return the "age" of the moon at the given time; this is the difference
* in ecliptic latitude between the moon and the sun. This method simply
* calls CalendarAstronomer.moonAge, converts to degrees,
* and adjusts the resultto be in the range [-180, 180].
*
* @param time The time at which the moon's age is desired,
* in millis since 1/1/1970.
*/
static double moonAge(UDate time);
//-------------------------------------------------------------------------
// Internal data....
//
/**
* CIVIL
if this object uses the fixed-cycle Islamic civil calendar,
* and ASTRONOMICAL
if it approximates the true religious calendar using
* astronomical calculations for the time of the new moon.
*/
ECivil civil;
//----------------------------------------------------------------------
// Calendar framework
//----------------------------------------------------------------------
protected:
/**
* @internal
*/
virtual int32_t handleGetLimit(UCalendarDateFields field, ELimitType limitType) const;
/**
* Return the length (in days) of the given month.
*
* @param year The hijri year
* @param year The hijri month, 0-based
* @internal
*/
virtual int32_t handleGetMonthLength(int32_t extendedYear, int32_t month) const;
/**
* Return the number of days in the given Islamic year
* @internal
*/
virtual int32_t handleGetYearLength(int32_t extendedYear) const;
//-------------------------------------------------------------------------
// Functions for converting from field values to milliseconds....
//-------------------------------------------------------------------------
// Return JD of start of given month/year
/**
* @internal
*/
virtual int32_t handleComputeMonthStart(int32_t eyear, int32_t month, UBool useMonth) const;
//-------------------------------------------------------------------------
// Functions for converting from milliseconds to field values
//-------------------------------------------------------------------------
/**
* @internal
*/
virtual int32_t handleGetExtendedYear();
/**
* Override Calendar to compute several fields specific to the Islamic
* calendar system. These are:
*
*