public final class HijrahDate extends java.lang.Object implements DateProvider, Calendrical, java.lang.Comparable<HijrahDate>, java.io.Serializable
HijrahDate
is an immutable class that represents a date in the Hijrah calendar system.
The rules of the calendar system are described in HijrahChronology
.
The Hijrah calendar has a different total of days in a year than Gregorian calendar, and a month is based on the period of a complete revolution of the moon around the earth (as between successive new moons). The calendar cycles becomes longer and unstable, and sometimes a manual adjustment (for entering deviation) is necessary for correctness because of the complex algorithm.
HijrahDate supports the manual adjustment feature by providing a configuration file. The configuration file contains the adjustment (deviation) data with following format.
StartYear/StartMonth(0-based)-EndYear/EndMonth(0-based):Deviation day (1, 2, -1, or -2) Line separator or ";" is used for the separator of each deviation data.Here is the example.
1429/0-1429/1:1 1429/2-1429/7:1;1429/6-1429/11:1 1429/11-9999/11:1The default location of the configuration file is:
$CLASSPATH/javax/time/i18nAnd the default file name is:
hijrah_deviation.cfgThe default location and file name can be overriden by setting following two Java's system property.
Location: javax.time.i18n.HijrahDate.deviationConfigDir File name: javax.time.i18n.HijrahDate.deviationConfigFile
Instances of this class may be created from other date objects that implement Calendrical
.
Notably this includes LocalDate
and all other date classes from other calendar systems.
HijrahDate is immutable and thread-safe.
Modifier and Type | Field and Description |
---|---|
static int |
MAX_YEAR_OF_ERA
The maximum valid year-of-era.
|
static int |
MIN_YEAR_OF_ERA
The minimum valid year-of-era.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(HijrahDate other)
Compares this date to another date.
|
boolean |
equals(java.lang.Object other)
Checks if this date is equal to the specified date.
|
<T> T |
get(CalendricalRule<T> rule)
Gets the value of the specified calendrical rule.
|
HijrahChronology |
getChronology()
Gets the chronology that this date uses, which is the Hijrah calendar system.
|
int |
getDayOfMonth()
Gets the Hijrah day-of-month field.
|
DayOfWeek |
getDayOfWeek()
Gets the day-of-week field, which is an enum
DayOfWeek . |
int |
getDayOfYear()
Gets the Hijrah day-of-year field.
|
HijrahEra |
getEra()
Gets the Hijrah era field.
|
int |
getMonthOfYear()
Gets the Hijrah month-of-year field.
|
int |
getYearOfEra()
Gets the Hijrah year-of-era field.
|
int |
hashCode()
A hash code for this date.
|
boolean |
isAfter(HijrahDate other)
Checks if this date is after the specified date.
|
boolean |
isBefore(HijrahDate other)
Checks if this date is before the specified date.
|
boolean |
isLeapYear()
Checks if the year is a leap year, according to the Hijrah calendar system rules.
|
HijrahDate |
minusDays(long days)
Returns a copy of this date with the specified number of days subtracted.
|
HijrahDate |
minusMonths(int months)
Returns a copy of this date with the specified number of months subtracted.
|
HijrahDate |
minusWeeks(int weeks)
Returns a copy of this date with the specified number of weeks subtracted.
|
HijrahDate |
minusYears(int years)
Returns a copy of this date with the specified number of years subtracted.
|
static HijrahDate |
of(Calendrical calendrical)
Obtains an instance of
HijrahDate from a calendrical. |
static HijrahDate |
of(HijrahEra era,
int yearOfEra,
int monthOfYear,
int dayOfMonth)
Obtains an instance of
HijrahDate from the era, year-of-era
month-of-year and day-of-month. |
static HijrahDate |
of(int yearOfHijrahEra,
int monthOfYear,
int dayOfMonth)
Obtains an instance of
HijrahDate from the Hijrah era year,
month-of-year and day-of-month. |
HijrahDate |
plusDays(long days)
Returns a copy of this date with the specified number of days added.
|
HijrahDate |
plusMonths(int months)
Returns a copy of this date with the specified number of months added.
|
HijrahDate |
plusWeeks(int weeks)
Returns a copy of this date with the specified number of weeks added.
|
HijrahDate |
plusYears(int years)
Returns a copy of this date with the specified number of years added.
|
static CalendricalRule<HijrahDate> |
rule()
Gets the rule for
HijrahDate . |
LocalDate |
toLocalDate()
Converts this date to a
LocalDate , which is the default representation
of a date, and provides values in the ISO-8601 calendar system. |
java.lang.String |
toString()
Outputs this date as a
String , such as 1430-03-05 (Hijrah) . |
HijrahDate |
withDayOfMonth(int dayOfMonth)
Returns a copy of this date with the day-of-month altered.
|
HijrahDate |
withDayOfYear(int dayOfYear)
Returns a copy of this date with the day-of-year altered.
|
HijrahDate |
withMonthOfYear(int monthOfYear)
Returns a copy of this date with the month-of-year altered.
|
HijrahDate |
withYear(HijrahEra era,
int yearOfEra)
Returns a copy of this date with the year altered.
|
HijrahDate |
withYearOfEra(int yearOfEra)
Returns a copy of this date with the year-of-era altered.
|
public static final int MIN_YEAR_OF_ERA
public static final int MAX_YEAR_OF_ERA
public static HijrahDate of(int yearOfHijrahEra, int monthOfYear, int dayOfMonth)
HijrahDate
from the Hijrah era year,
month-of-year and day-of-month. This uses the Hijrah era.yearOfHijrahEra
- the year to represent in the Hijrah era, from 1 to 9999monthOfYear
- the month-of-year to represent, from 1 to 12dayOfMonth
- the day-of-month to represent, from 1 to 31IllegalCalendarFieldValueException
- if the value of any field is out of rangeInvalidCalendarFieldException
- if the day-of-month is invalid for the month-yearpublic static HijrahDate of(HijrahEra era, int yearOfEra, int monthOfYear, int dayOfMonth)
HijrahDate
from the era, year-of-era
month-of-year and day-of-month.era
- the era to represent, not nullyearOfEra
- the year-of-era to represent, from 1 to 9999monthOfYear
- the month-of-year to represent, from 1 to 12dayOfMonth
- the day-of-month to represent, from 1 to 31IllegalCalendarFieldValueException
- if the value of any field is out of rangeInvalidCalendarFieldException
- if the day-of-month is invalid for the month-yearpublic static HijrahDate of(Calendrical calendrical)
HijrahDate
from a calendrical.
This can be used extract the date directly from any implementation
of Calendrical
, including those in other calendar systems.
calendrical
- the calendrical to extract from, not nullCalendricalException
- if the date cannot be obtainedpublic HijrahChronology getChronology()
public <T> T get(CalendricalRule<T> rule)
This method queries the value of the specified calendrical rule.
If the value cannot be returned for the rule from this date then
null
will be returned.
get
in interface Calendrical
rule
- the rule to use, not nullpublic HijrahEra getEra()
public int getYearOfEra()
public int getMonthOfYear()
public int getDayOfMonth()
public int getDayOfYear()
public DayOfWeek getDayOfWeek()
DayOfWeek
.
This method returns the enum DayOfWeek
for the day-of-week.
This avoids confusion as to what int
values mean.
If you need access to the primitive int
value then the enum
provides the int value
.
Additional information can be obtained from the DayOfWeek
.
This includes textual names of the values.
public boolean isLeapYear()
public HijrahDate withYear(HijrahEra era, int yearOfEra)
This method changes the year of the date. If the resulting date is invalid, an exception is thrown.
This instance is immutable and unaffected by this method call.
era
- the era to set in the returned date, not nullyearOfEra
- the year-of-era to set in the returned date, from 1 to 9999HijrahDate
based on this date with the requested year, never nullIllegalCalendarFieldValueException
- if the year-of-era value is invalidpublic HijrahDate withYearOfEra(int yearOfEra)
This method changes the year-of-era of the date. If the resulting date is invalid, an exception is thrown.
This instance is immutable and unaffected by this method call.
yearOfEra
- the year-of-era to set in the returned date, from 1 to 9999HijrahDate
based on this date with the requested year-of-era, never nullIllegalCalendarFieldValueException
- if the year-of-era value is invalidpublic HijrahDate withMonthOfYear(int monthOfYear)
This method changes the month-of-year of the date. If the resulting date is invalid, an exception is thrown.
This instance is immutable and unaffected by this method call.
monthOfYear
- the month-of-year to set in the returned date, from 1 to 12HijrahDate
based on this date with the requested month, never nullIllegalCalendarFieldValueException
- if the month-of-year is invalidpublic HijrahDate withDayOfMonth(int dayOfMonth)
This method changes the day-of-month of the date. If the resulting date is invalid, an exception is thrown.
This instance is immutable and unaffected by this method call.
dayOfMonth
- the day-of-month to set in the returned date, from 1 to 29-30 (it changes depending on deviation configuration)HijrahDate
based on this date with the requested day, never nullIllegalCalendarFieldValueException
- if the day-of-month value is invalidInvalidCalendarFieldException
- if the day-of-month is invalid for the month-yearpublic HijrahDate withDayOfYear(int dayOfYear)
This method changes the day-of-year of the date. If the resulting date is invalid, an exception is thrown.
This instance is immutable and unaffected by this method call.
dayOfYear
- the day-of-year to set in the returned date, from 1 to 354-355 (it changes depending on deviation configuration)HijrahDate
based on this date with the requested day, never nullIllegalCalendarFieldValueException
- if the day-of-year value is invalidInvalidCalendarFieldException
- if the day-of-year is invalid for the yearpublic HijrahDate plusYears(int years)
This method adds the specified amount in years to the date. If the resulting date is invalid, an exception is thrown.
This instance is immutable and unaffected by this method call.
years
- the years to add, may be negativeHijrahDate
based on this date with the years added, never nullCalendricalException
- if the result exceeds the supported date rangepublic HijrahDate plusMonths(int months)
This method adds the specified amount in months to the date. If the resulting date is invalid, an exception is thrown.
This instance is immutable and unaffected by this method call.
months
- the months to add, may be negativeHijrahDate
based on this date with the months added, never nullCalendricalException
- if the result exceeds the supported date rangepublic HijrahDate plusWeeks(int weeks)
This method adds the specified amount in weeks to the date.
This instance is immutable and unaffected by this method call.
weeks
- the weeks to add, may be negativeHijrahDate
based on this date with the weeks added, never nullCalendricalException
- if the result exceeds the supported date rangepublic HijrahDate plusDays(long days)
This method adds the specified amount in days to the date.
This instance is immutable and unaffected by this method call.
days
- the days to add, may be negativeHijrahDate
based on this date with the days added, never nullCalendricalException
- if the result exceeds the supported date rangepublic HijrahDate minusYears(int years)
This method subtracts the specified amount in years from the date. If the resulting date is invalid, an exception is thrown.
This instance is immutable and unaffected by this method call.
years
- the years to subtract, may be negativeHijrahDate
based on this date with the years subtracted, never nullCalendricalException
- if the result exceeds the supported date rangepublic HijrahDate minusMonths(int months)
This method subtracts the specified amount in months from the date. If the resulting date is invalid, an exception is thrown.
This instance is immutable and unaffected by this method call.
months
- the months to subtract, may be negativeHijrahDate
based on this date with the months subtracted, never nullCalendricalException
- if the result exceeds the supported date rangepublic HijrahDate minusWeeks(int weeks)
This method subtracts the specified amount in weeks from the date.
This instance is immutable and unaffected by this method call.
weeks
- the weeks to subtract, may be negativeHijrahDate
based on this date with the weeks subtracted, never nullCalendricalException
- if the result exceeds the supported date rangepublic HijrahDate minusDays(long days)
This method subtracts the specified amount in days from the date.
This instance is immutable and unaffected by this method call.
days
- the days to subtract, may be negativeHijrahDate
based on this date with the days subtracted, never nullCalendricalException
- if the result exceeds the supported date rangepublic LocalDate toLocalDate()
LocalDate
, which is the default representation
of a date, and provides values in the ISO-8601 calendar system.toLocalDate
in interface DateProvider
public int compareTo(HijrahDate other)
The comparison is based on the time-line position of the dates.
compareTo
in interface java.lang.Comparable<HijrahDate>
other
- the other date to compare to, not nullpublic boolean isAfter(HijrahDate other)
The comparison is based on the time-line position of the dates.
other
- the other date to compare to, not nullpublic boolean isBefore(HijrahDate other)
The comparison is based on the time-line position of the dates.
other
- the other date to compare to, not nullpublic boolean equals(java.lang.Object other)
The comparison is based on the time-line position of the dates.
equals
in class java.lang.Object
other
- the other date to compare to, null returns falsepublic int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
String
, such as 1430-03-05 (Hijrah)
.
The output will be in the format yyyy-MM-dd (Hijrah)
.
toString
in class java.lang.Object
public static CalendricalRule<HijrahDate> rule()
HijrahDate
.