Class IslamicChronology
- java.lang.Object
-
- org.joda.time.Chronology
-
- org.joda.time.chrono.BaseChronology
-
- org.joda.time.chrono.AssembledChronology
-
- org.joda.time.chrono.BasicChronology
-
- org.joda.time.chrono.IslamicChronology
-
- All Implemented Interfaces:
java.io.Serializable
public final class IslamicChronology extends BasicChronology
Implements the Islamic, or Hijri, calendar system using arithmetic rules.This calendar is a lunar calendar with a shorter year than ISO. Year 1 in the Islamic calendar began on July 16, 622 CE (Julian), thus Islamic years do not begin at the same time as Julian years. This chronology is not proleptic, as it does not allow dates before the first Islamic year.
There are two basic forms of the Islamic calendar, the tabular and the observed. The observed form cannot easily be used by computers as it relies on human observation of the new moon. The tabular calendar, implemented here, is an arithmetical approximation of the observed form that follows relatively simple rules.
The tabular form of the calendar defines 12 months of alternately 30 and 29 days. The last month is extended to 30 days in a leap year. Leap years occur according to a 30 year cycle. There are four recognised patterns of leap years in the 30 year cycle:
Years 2, 5, 7, 10, 13, 15, 18, 21, 24, 26 & 29 - 15-based, used by Microsoft Years 2, 5, 7, 10, 13, 16, 18, 21, 24, 26 & 29 - 16-based, most commonly used Years 2, 5, 8, 10, 13, 16, 19, 21, 24, 27 & 29 - Indian Years 2, 5, 8, 11, 13, 16, 19, 21, 24, 27 & 30 - Habash al-Hasib
You can select which pattern to use via the factory methods, or use the default (16-based).This implementation defines a day as midnight to midnight exactly as per the ISO chronology. This correct start of day is at sunset on the previous day, however this cannot readily be modelled and has been ignored.
IslamicChronology is thread-safe and immutable.
- Since:
- 1.2
- See Also:
- Wikipedia, Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classIslamicChronology.LeapYearPatternTypeOpaque object describing a leap year pattern for the Islamic Chronology.-
Nested classes/interfaces inherited from class org.joda.time.chrono.AssembledChronology
AssembledChronology.Fields
-
-
Field Summary
Fields Modifier and Type Field Description static intAHConstant value for 'Anno Hegirae', equivalent to the value returned for AD/CE.private static java.util.concurrent.ConcurrentHashMap<DateTimeZone,IslamicChronology[]>cCacheCache of zone to chronology arraysprivate static intCYCLEThe length of the cycle of leap years.private static DateTimeFieldERA_FIELDA singleton era field.private IslamicChronology.LeapYearPatternTypeiLeapYearsThe leap years to use.private static IslamicChronologyINSTANCE_UTCSingleton instance of a UTC IslamicChronologystatic IslamicChronology.LeapYearPatternTypeLEAP_YEAR_15_BASEDLeap year 15-based pattern.static IslamicChronology.LeapYearPatternTypeLEAP_YEAR_16_BASEDLeap year 16-based pattern.static IslamicChronology.LeapYearPatternTypeLEAP_YEAR_HABASH_AL_HASIBLeap year Habash al-Hasib pattern.static IslamicChronology.LeapYearPatternTypeLEAP_YEAR_INDIANLeap year Indian pattern.private static intLONG_MONTH_LENGTHThe length of the long month.private static intMAX_YEARThe highest year that can be fully supported.private static longMILLIS_PER_CYCLEThe millis of a 30 year cycle.private static longMILLIS_PER_LONG_MONTHThe length of the long month in millis.private static longMILLIS_PER_LONG_YEARThe typical millis per year.private static longMILLIS_PER_MONTHThe length of the long month in millis.private static longMILLIS_PER_MONTH_PAIRThe length of the long month in millis.private static longMILLIS_PER_SHORT_YEARThe typical millis per year.private static longMILLIS_PER_YEARThe typical millis per year.private static longMILLIS_YEAR_1The millis of 0001-01-01.private static intMIN_YEARThe lowest year that can be fully supported.private static intMONTH_PAIR_LENGTHThe days in a pair of months.private static longserialVersionUIDSerialization lockprivate static intSHORT_MONTH_LENGTHThe length of the short month.
-
Constructor Summary
Constructors Constructor Description IslamicChronology(Chronology base, java.lang.Object param, IslamicChronology.LeapYearPatternType leapYears)Restricted constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidassemble(AssembledChronology.Fields fields)Invoked by the constructor and after deserialization to allow subclasses to define all of its supported fields.(package private) longcalculateFirstDayOfYearMillis(int year)Gets the millisecond value of the first day of the year.booleanequals(java.lang.Object obj)Checks if this chronology instance equals another.(package private) longgetApproxMillisAtEpochDividedByTwo()Returns a constant representing the approximate number of milliseconds elapsed from year 0 of this chronology, divided by two.(package private) longgetAverageMillisPerMonth()Gets an average value for the milliseconds per month.(package private) longgetAverageMillisPerYear()Gets an average value for the milliseconds per year.(package private) longgetAverageMillisPerYearDividedByTwo()Gets an average value for the milliseconds per year, divided by two.(package private) intgetDayOfMonth(long millis)(package private) intgetDaysInMonthMax()Gets the maximum number of days in any month.(package private) intgetDaysInMonthMax(int month)Gets the maximum days in the specified month.(package private) intgetDaysInYear(int year)Get the number of days in the year.(package private) intgetDaysInYearMax()Get the number of days in the year.(package private) intgetDaysInYearMonth(int year, int month)Gets the number of days in the specified month and year.static IslamicChronologygetInstance()Gets an instance of the IslamicChronology in the default time zone.static IslamicChronologygetInstance(DateTimeZone zone)Gets an instance of the IslamicChronology in the given time zone.static IslamicChronologygetInstance(DateTimeZone zone, IslamicChronology.LeapYearPatternType leapYears)Gets an instance of the IslamicChronology in the given time zone.static IslamicChronologygetInstanceUTC()Gets an instance of the IslamicChronology.IslamicChronology.LeapYearPatternTypegetLeapYearPatternType()Gets the leap year pattern type.(package private) intgetMaxYear()Gets the maximum supported year.(package private) intgetMinYear()Gets the minimum supported year.(package private) intgetMonthOfYear(long millis, int year)(package private) longgetTotalMillisByYearMonth(int year, int month)Gets the total number of millis elapsed in this year at the start of the specified month, such as zero for month 1.(package private) intgetYear(long instant)(package private) longgetYearDifference(long minuendInstant, long subtrahendInstant)Gets the difference between the two instants in years.inthashCode()A suitable hash code for the chronology.(package private) booleanisLeapYear(int year)Is the specified year a leap year?private java.lang.ObjectreadResolve()Serialization singleton.(package private) longsetYear(long instant, int year)Sets the year from an instant and year.ChronologywithUTC()Gets the Chronology in the UTC time zone.ChronologywithZone(DateTimeZone zone)Gets the Chronology in a specific time zone.-
Methods inherited from class org.joda.time.chrono.BasicChronology
getDateMidnightMillis, getDateTimeMillis, getDateTimeMillis, getDayOfMonth, getDayOfMonth, getDayOfWeek, getDayOfYear, getDayOfYear, getDaysInMonthMax, getDaysInMonthMaxForSet, getFirstWeekOfYearMillis, getMaxMonth, getMaxMonth, getMillisOfDay, getMinimumDaysInFirstWeek, getMonthOfYear, getWeekOfWeekyear, getWeekOfWeekyear, getWeeksInYear, getWeekyear, getYearMillis, getYearMonthDayMillis, getYearMonthMillis, getZone, isLeapDay, toString
-
Methods inherited from class org.joda.time.chrono.AssembledChronology
centuries, centuryOfEra, clockhourOfDay, clockhourOfHalfday, dayOfMonth, dayOfWeek, dayOfYear, days, era, eras, getBase, getDateTimeMillis, getParam, halfdayOfDay, halfdays, hourOfDay, hourOfHalfday, hours, millis, millisOfDay, millisOfSecond, minuteOfDay, minuteOfHour, minutes, monthOfYear, months, secondOfDay, secondOfMinute, seconds, weekOfWeekyear, weeks, weekyear, weekyearOfCentury, weekyears, year, yearOfCentury, yearOfEra, years
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
Serialization lock- See Also:
- Constant Field Values
-
AH
public static final int AH
Constant value for 'Anno Hegirae', equivalent to the value returned for AD/CE.- See Also:
- Constant Field Values
-
ERA_FIELD
private static final DateTimeField ERA_FIELD
A singleton era field.
-
LEAP_YEAR_15_BASED
public static final IslamicChronology.LeapYearPatternType LEAP_YEAR_15_BASED
Leap year 15-based pattern.
-
LEAP_YEAR_16_BASED
public static final IslamicChronology.LeapYearPatternType LEAP_YEAR_16_BASED
Leap year 16-based pattern.
-
LEAP_YEAR_INDIAN
public static final IslamicChronology.LeapYearPatternType LEAP_YEAR_INDIAN
Leap year Indian pattern.
-
LEAP_YEAR_HABASH_AL_HASIB
public static final IslamicChronology.LeapYearPatternType LEAP_YEAR_HABASH_AL_HASIB
Leap year Habash al-Hasib pattern.
-
MIN_YEAR
private static final int MIN_YEAR
The lowest year that can be fully supported.- See Also:
- Constant Field Values
-
MAX_YEAR
private static final int MAX_YEAR
The highest year that can be fully supported. Although calculateFirstDayOfYearMillis can go higher without overflowing, the getYear method overflows when it adds the approximate millis at the epoch.- See Also:
- Constant Field Values
-
MONTH_PAIR_LENGTH
private static final int MONTH_PAIR_LENGTH
The days in a pair of months.- See Also:
- Constant Field Values
-
LONG_MONTH_LENGTH
private static final int LONG_MONTH_LENGTH
The length of the long month.- See Also:
- Constant Field Values
-
SHORT_MONTH_LENGTH
private static final int SHORT_MONTH_LENGTH
The length of the short month.- See Also:
- Constant Field Values
-
MILLIS_PER_MONTH_PAIR
private static final long MILLIS_PER_MONTH_PAIR
The length of the long month in millis.- See Also:
- Constant Field Values
-
MILLIS_PER_MONTH
private static final long MILLIS_PER_MONTH
The length of the long month in millis.- See Also:
- Constant Field Values
-
MILLIS_PER_LONG_MONTH
private static final long MILLIS_PER_LONG_MONTH
The length of the long month in millis.- See Also:
- Constant Field Values
-
MILLIS_PER_YEAR
private static final long MILLIS_PER_YEAR
The typical millis per year.- See Also:
- Constant Field Values
-
MILLIS_PER_SHORT_YEAR
private static final long MILLIS_PER_SHORT_YEAR
The typical millis per year.- See Also:
- Constant Field Values
-
MILLIS_PER_LONG_YEAR
private static final long MILLIS_PER_LONG_YEAR
The typical millis per year.- See Also:
- Constant Field Values
-
MILLIS_YEAR_1
private static final long MILLIS_YEAR_1
The millis of 0001-01-01.- See Also:
- Constant Field Values
-
CYCLE
private static final int CYCLE
The length of the cycle of leap years.- See Also:
- Constant Field Values
-
MILLIS_PER_CYCLE
private static final long MILLIS_PER_CYCLE
The millis of a 30 year cycle.- See Also:
- Constant Field Values
-
cCache
private static final java.util.concurrent.ConcurrentHashMap<DateTimeZone,IslamicChronology[]> cCache
Cache of zone to chronology arrays
-
INSTANCE_UTC
private static final IslamicChronology INSTANCE_UTC
Singleton instance of a UTC IslamicChronology
-
iLeapYears
private final IslamicChronology.LeapYearPatternType iLeapYears
The leap years to use.
-
-
Constructor Detail
-
IslamicChronology
IslamicChronology(Chronology base, java.lang.Object param, IslamicChronology.LeapYearPatternType leapYears)
Restricted constructor.
-
-
Method Detail
-
getInstanceUTC
public static IslamicChronology getInstanceUTC()
Gets an instance of the IslamicChronology. The time zone of the returned instance is UTC.- Returns:
- a singleton UTC instance of the chronology
-
getInstance
public static IslamicChronology getInstance()
Gets an instance of the IslamicChronology in the default time zone.- Returns:
- a chronology in the default time zone
-
getInstance
public static IslamicChronology getInstance(DateTimeZone zone)
Gets an instance of the IslamicChronology in the given time zone.- Parameters:
zone- the time zone to get the chronology in, null is default- Returns:
- a chronology in the specified time zone
-
getInstance
public static IslamicChronology getInstance(DateTimeZone zone, IslamicChronology.LeapYearPatternType leapYears)
Gets an instance of the IslamicChronology in the given time zone.- Parameters:
zone- the time zone to get the chronology in, null is defaultleapYears- the type defining the leap year pattern- Returns:
- a chronology in the specified time zone
-
readResolve
private java.lang.Object readResolve()
Serialization singleton.
-
getLeapYearPatternType
public IslamicChronology.LeapYearPatternType getLeapYearPatternType()
Gets the leap year pattern type.- Returns:
- the pattern type
-
withUTC
public Chronology withUTC()
Gets the Chronology in the UTC time zone.- Specified by:
withUTCin classBaseChronology- Returns:
- the chronology in UTC
-
withZone
public Chronology withZone(DateTimeZone zone)
Gets the Chronology in a specific time zone.- Specified by:
withZonein classBaseChronology- Parameters:
zone- the zone to get the chronology in, null is default- Returns:
- the chronology
- See Also:
ZonedChronology
-
equals
public boolean equals(java.lang.Object obj)
Checks if this chronology instance equals another.- Overrides:
equalsin classBasicChronology- Parameters:
obj- the object to compare to- Returns:
- true if equal
- Since:
- 2.3
-
hashCode
public int hashCode()
A suitable hash code for the chronology.- Overrides:
hashCodein classBasicChronology- Returns:
- the hash code
- Since:
- 1.6
-
getYear
int getYear(long instant)
- Overrides:
getYearin classBasicChronology- Parameters:
instant- millis from 1970-01-01T00:00:00Z
-
setYear
long setYear(long instant, int year)Description copied from class:BasicChronologySets the year from an instant and year.- Specified by:
setYearin classBasicChronology- Parameters:
instant- millis from 1970-01-01T00:00:00Zyear- the year to set- Returns:
- the updated millis
-
getYearDifference
long getYearDifference(long minuendInstant, long subtrahendInstant)Description copied from class:BasicChronologyGets the difference between the two instants in years.- Specified by:
getYearDifferencein classBasicChronology- Parameters:
minuendInstant- the first instantsubtrahendInstant- the second instant- Returns:
- the difference
-
getTotalMillisByYearMonth
long getTotalMillisByYearMonth(int year, int month)Description copied from class:BasicChronologyGets the total number of millis elapsed in this year at the start of the specified month, such as zero for month 1.- Specified by:
getTotalMillisByYearMonthin classBasicChronology- Parameters:
year- the yearmonth- the month- Returns:
- the elapsed millis at the start of the month
-
getDayOfMonth
int getDayOfMonth(long millis)
- Overrides:
getDayOfMonthin classBasicChronology- Parameters:
millis- from 1970-01-01T00:00:00Z
-
isLeapYear
boolean isLeapYear(int year)
Description copied from class:BasicChronologyIs the specified year a leap year?- Specified by:
isLeapYearin classBasicChronology- Parameters:
year- the year to test- Returns:
- true if leap
-
getDaysInYearMax
int getDaysInYearMax()
Description copied from class:BasicChronologyGet the number of days in the year.- Overrides:
getDaysInYearMaxin classBasicChronology- Returns:
- 366
-
getDaysInYear
int getDaysInYear(int year)
Description copied from class:BasicChronologyGet the number of days in the year.- Overrides:
getDaysInYearin classBasicChronology- Parameters:
year- the year to use- Returns:
- 366 if a leap year, otherwise 365
-
getDaysInYearMonth
int getDaysInYearMonth(int year, int month)Description copied from class:BasicChronologyGets the number of days in the specified month and year.- Specified by:
getDaysInYearMonthin classBasicChronology- Parameters:
year- the yearmonth- the month- Returns:
- the number of days
-
getDaysInMonthMax
int getDaysInMonthMax()
Description copied from class:BasicChronologyGets the maximum number of days in any month.- Overrides:
getDaysInMonthMaxin classBasicChronology- Returns:
- 31
-
getDaysInMonthMax
int getDaysInMonthMax(int month)
Description copied from class:BasicChronologyGets the maximum days in the specified month.- Specified by:
getDaysInMonthMaxin classBasicChronology- Parameters:
month- the month- Returns:
- the max days
-
getMonthOfYear
int getMonthOfYear(long millis, int year)- Specified by:
getMonthOfYearin classBasicChronology- Parameters:
millis- from 1970-01-01T00:00:00Zyear- precalculated year of millis
-
getAverageMillisPerYear
long getAverageMillisPerYear()
Description copied from class:BasicChronologyGets an average value for the milliseconds per year.- Specified by:
getAverageMillisPerYearin classBasicChronology- Returns:
- the millis per year
-
getAverageMillisPerYearDividedByTwo
long getAverageMillisPerYearDividedByTwo()
Description copied from class:BasicChronologyGets an average value for the milliseconds per year, divided by two.- Specified by:
getAverageMillisPerYearDividedByTwoin classBasicChronology- Returns:
- the millis per year divided by two
-
getAverageMillisPerMonth
long getAverageMillisPerMonth()
Description copied from class:BasicChronologyGets an average value for the milliseconds per month.- Specified by:
getAverageMillisPerMonthin classBasicChronology- Returns:
- the millis per month
-
calculateFirstDayOfYearMillis
long calculateFirstDayOfYearMillis(int year)
Description copied from class:BasicChronologyGets the millisecond value of the first day of the year.- Specified by:
calculateFirstDayOfYearMillisin classBasicChronology- Returns:
- the milliseconds for the first of the year
-
getMinYear
int getMinYear()
Description copied from class:BasicChronologyGets the minimum supported year.- Specified by:
getMinYearin classBasicChronology- Returns:
- the year
-
getMaxYear
int getMaxYear()
Description copied from class:BasicChronologyGets the maximum supported year.- Specified by:
getMaxYearin classBasicChronology- Returns:
- the year
-
getApproxMillisAtEpochDividedByTwo
long getApproxMillisAtEpochDividedByTwo()
Description copied from class:BasicChronologyReturns a constant representing the approximate number of milliseconds elapsed from year 0 of this chronology, divided by two. This constant must be defined as:(yearAtEpoch * averageMillisPerYear + millisOfYearAtEpoch) / 2where epoch is 1970-01-01 (Gregorian).- Specified by:
getApproxMillisAtEpochDividedByTwoin classBasicChronology
-
assemble
protected void assemble(AssembledChronology.Fields fields)
Description copied from class:AssembledChronologyInvoked by the constructor and after deserialization to allow subclasses to define all of its supported fields. All unset fields default to unsupported instances.- Overrides:
assemblein classBasicChronology- Parameters:
fields- container of fields
-
-