@CalendarType(value="islamic") public final class HijriCalendar extends CalendarVariant<HijriCalendar> implements LocalizedPatternSupport
Represents the Hijri calendar used in many islamic countries.
It is a lunar calendar which exists in several variants and is mainly for religious purposes. The variant used in Saudi-Arabia is named "islamic-umalqura" and is based on data partially observed by sighting the new moon, partially by astronomical calculations/predictions. Note that the religious authorities in most countries often publish dates which deviate from such official calendars by one or two days.
The calendar year is divided into 12 islamic months. Every month usually has either 29 or 30 days. The length of the month in days shall reflect the date when the new moon appears. However, for every variant there are different data or rules how to determine if a month has 29 or 30 days. The Hijri calendar day starts in the evening. New variants can be configured by a file named "{variant-name}.data" in the data-subdirectory of resource class path (where hyphens are replaced by underscores). Format details see the file "islamic_umalqura.data".
Following elements which are declared as constants are registered by this class:
Furthermore, all elements defined in EpochDays and CommonElements are supported.
Examples of usage:
// parse a Hijri-string and convert to a gregorian date
ChronoFormatter<HijriCalendar> formatter =
ChronoFormatter.setUp(HijriCalendar.class, Locale.ENGLISH)
.addPattern("EEE, d. MMMM yy", PatternType.NON_ISO_DATE).build()
.withCalendarVariant(HijriCalendar.VARIANT_UMALQURA)
.with(Attributes.PIVOT_YEAR, 1500); // mapped to range 1400-1499
HijriCalendar hijri = formatter.parse("Thu, 29. Ramadan 36");
PlainDate date = hijri.transform(PlainDate.class);
System.out.println(date); // 2015-07-16
// determine actual Hijri date (two methods)
HijriCalendar today = // conversion valid at noon (not in the evening when next islamic day starts)
SystemClock.inLocalView().today().transform(HijriCalendar.class, HijriCalendar.VARIANT_UMALQURA);
HijriCalendar todayExact = // taking into account the specific start of day for Hijri calendar
SystemClock.inLocalView().now(
HijriCalendar.family(),
HijriCalendar.VARIANT_UMALQURA,
StartOfDay.EVENING // simple approximation => 18:00
).toDate();
Note that the supported range of this class is limited compared with the gregorian counter-example. Users can apply following code to determine the exact variant-dependent range:
CalendarSystem<HijriCalendar> calsys =
HijriCalendar.family().getCalendarSystem(HijriCalendar.VARIANT_UMALQURA);
long min = calsys.getMinimumSinceUTC(); // -32556
long max = calsys.getMaximumSinceUTC(); // 38671
// same minimum and maximum displayed as Hijri calendar dates
HijriCalendar minHijri = calsys.transform(min); // AH-1300-01-01[islamic-umalqura]
HijriCalendar maxHijri = calsys.transform(max); // AH-1500-12-30[islamic-umalqura]
// same minimum and maximum displayed as gregorian dates
PlainDate minGregorian = PlainDate.of(min, EpochDays.UTC); // 1882-11-12
PlainDate maxGregorian = PlainDate.of(max, EpochDays.UTC); // 2077-11-16
| Modifier and Type | Class and Description |
|---|---|
static class |
HijriCalendar.Unit
Defines come calendar units for the Hijri calendar.
|
| Modifier and Type | Field and Description |
|---|---|
static StdCalendarElement<java.lang.Integer,HijriCalendar> |
DAY_OF_MONTH
Represents the islamic day of month.
|
static StdCalendarElement<Weekday,HijriCalendar> |
DAY_OF_WEEK
Represents the islamic day of week.
|
static StdCalendarElement<java.lang.Integer,HijriCalendar> |
DAY_OF_YEAR
Represents the islamic day of year.
|
static ChronoElement<HijriEra> |
ERA
Represents the islamic era.
|
static StdCalendarElement<HijriMonth,HijriCalendar> |
MONTH_OF_YEAR
Represents the islamic month.
|
static java.lang.String |
VARIANT_DIYANET
The name of the Turkish Diyanet-variant.
|
static java.lang.String |
VARIANT_ICU4J
The name of the astronomical ICU4J-variant.
|
static java.lang.String |
VARIANT_UMALQURA
The name of Umm-al-qura-variant.
|
static StdCalendarElement<java.lang.Integer,HijriCalendar> |
YEAR_OF_ERA
Represents the islamic year.
|
| Modifier and Type | Method and Description |
|---|---|
GeneralTimestamp<HijriCalendar> |
at(PlainTime time)
Creates a new local timestamp with this date and given wall time.
|
GeneralTimestamp<HijriCalendar> |
atTime(int hour,
int minute)
Is equivalent to
at(PlainTime.of(hour, minute)). |
boolean |
equals(java.lang.Object obj)
Compares the whole state of this instance with given object.
|
static CalendarFamily<HijriCalendar> |
family()
Returns the associated calendar family.
|
int |
getDayOfMonth()
Yields the islamic day of month.
|
Weekday |
getDayOfWeek()
Determines the day of week.
|
int |
getDayOfYear()
Yields the islamic day of year.
|
static Weekmodel |
getDefaultWeekmodel()
Obtains the standard week model of this calendar.
|
HijriEra |
getEra()
Yields the islamic era.
|
HijriMonth |
getMonth()
Yields the islamic month.
|
java.lang.String |
getVariant()
Returns the name of the associated variant of underlying calendar system.
|
static java.lang.String |
getVersion(java.lang.String variant)
Determines the data version of given variant.
|
int |
getYear()
Yields the islamic year.
|
int |
hashCode()
Subclasses must redefine this method corresponding to the
behaviour of
equals(). |
int |
lengthOfMonth()
Yields the length of current islamic month in days.
|
int |
lengthOfYear()
Yields the length of current islamic year in days.
|
HijriCalendar |
minus(int amount,
HijriCalendar.Unit unit)
Subtracts given calendrical units from this instance.
|
HijriCalendar |
nextDay()
Convenient short form for
with(DAY_OF_MONTH.incremented()). |
HijriCalendar |
nextMonth()
Convenient short form for
with(MONTH_OF_YEAR.incremented()). |
HijriCalendar |
nextYear()
Convenient short form for
with(YEAR_OF_ERA.incremented()). |
static HijriCalendar |
nowInSystemTime(java.lang.String variant,
StartOfDay startOfDay)
Obtains the current calendar date in system time.
|
static HijriCalendar |
nowInSystemTime(VariantSource variantSource,
StartOfDay startOfDay)
Obtains the current calendar date in system time.
|
static HijriCalendar |
of(java.lang.String variant,
int hyear,
HijriMonth hmonth,
int hdom)
Creates a new instance of a Hijri calendar date in given variant.
|
static HijriCalendar |
of(java.lang.String variant,
int hyear,
int hmonth,
int hdom)
Creates a new instance of a Hijri calendar date in given variant.
|
static HijriCalendar |
of(VariantSource variantSource,
int hyear,
HijriMonth hmonth,
int hdom)
Creates a new instance of a Hijri calendar date in given variant.
|
static HijriCalendar |
of(VariantSource variantSource,
int hyear,
int hmonth,
int hdom)
Creates a new instance of a Hijri calendar date in given variant.
|
static HijriCalendar |
ofUmalqura(int hyear,
HijriMonth hmonth,
int hdom)
Creates a new instance of a Hijri calendar date in the variant "islamic-umalqura"
used in Saudi-Arabia.
|
static HijriCalendar |
ofUmalqura(int hyear,
int hmonth,
int hdom)
Creates a new instance of a Hijri calendar date in the variant "islamic-umalqura"
used in Saudi-Arabia.
|
HijriCalendar |
plus(int amount,
HijriCalendar.Unit unit)
Adds given calendrical units to this instance.
|
java.lang.String |
toString()
Provides a complete textual representation of the state of this calendar variant.
|
compareTo, getDaysSinceEpochUTC, isAfter, isBefore, isSimultaneous, minus, plus, transform, transform, transform, withVariant, withVariantcontains, get, get, getInt, getMaximum, getMinimum, getRegisteredElements, getTimezone, hasTimezone, isValid, isValid, isValid, matches, with, with, with, with@FormattableElement(format="G") public static final ChronoElement<HijriEra> ERA
Represents the islamic era.
@FormattableElement(format="y") public static final StdCalendarElement<java.lang.Integer,HijriCalendar> YEAR_OF_ERA
Represents the islamic year.
@FormattableElement(format="M", standalone="L") public static final StdCalendarElement<HijriMonth,HijriCalendar> MONTH_OF_YEAR
Represents the islamic month.
@FormattableElement(format="d") public static final StdCalendarElement<java.lang.Integer,HijriCalendar> DAY_OF_MONTH
Represents the islamic day of month.
@FormattableElement(format="D") public static final StdCalendarElement<java.lang.Integer,HijriCalendar> DAY_OF_YEAR
Represents the islamic day of year.
@FormattableElement(format="E") public static final StdCalendarElement<Weekday,HijriCalendar> DAY_OF_WEEK
Represents the islamic day of week.
If the day-of-week is set to a new value then Time4J handles the islamic calendar week as starting on Sunday.
public static final java.lang.String VARIANT_UMALQURA
The supported range of islamic years is 1300-1500.
public static final java.lang.String VARIANT_ICU4J
The supported range of islamic years is 1-1600.
public static final java.lang.String VARIANT_DIYANET
The supported range is 1318-01-01/1444-05-29 (ISO: 1900-05-01/2022-12-23).
public static HijriCalendar of(java.lang.String variant, int hyear, HijriMonth hmonth, int hdom)
Creates a new instance of a Hijri calendar date in given variant.
variant - calendar varianthyear - islamic yearhmonth - islamic monthhdom - islamic day of monthHijriCalendarChronoException - if given variant is not supportedjava.lang.IllegalArgumentException - in case of any inconsistenciespublic static HijriCalendar of(java.lang.String variant, int hyear, int hmonth, int hdom)
Creates a new instance of a Hijri calendar date in given variant.
variant - calendar varianthyear - islamic yearhmonth - islamic monthhdom - islamic day of monthHijriCalendarChronoException - if given variant is not supportedjava.lang.IllegalArgumentException - in case of any inconsistenciespublic static HijriCalendar of(VariantSource variantSource, int hyear, HijriMonth hmonth, int hdom)
Creates a new instance of a Hijri calendar date in given variant.
variantSource - source of calendar varianthyear - islamic yearhmonth - islamic monthhdom - islamic day of monthHijriCalendarChronoException - if given variant is not supportedjava.lang.IllegalArgumentException - in case of any inconsistenciespublic static HijriCalendar of(VariantSource variantSource, int hyear, int hmonth, int hdom)
Creates a new instance of a Hijri calendar date in given variant.
variantSource - source of calendar varianthyear - islamic yearhmonth - islamic monthhdom - islamic day of monthHijriCalendarChronoException - if given variant is not supportedjava.lang.IllegalArgumentException - in case of any inconsistenciespublic static HijriCalendar ofUmalqura(int hyear, HijriMonth hmonth, int hdom)
Creates a new instance of a Hijri calendar date in the variant "islamic-umalqura" used in Saudi-Arabia.
hyear - islamic yearhmonth - islamic monthhdom - islamic day of monthHijriCalendarChronoException - if given variant is not supportedjava.lang.IllegalArgumentException - in case of any inconsistenciespublic static HijriCalendar ofUmalqura(int hyear, int hmonth, int hdom)
Creates a new instance of a Hijri calendar date in the variant "islamic-umalqura" used in Saudi-Arabia.
hyear - islamic yearhmonth - islamic monthhdom - islamic day of monthHijriCalendarChronoException - if given variant is not supportedjava.lang.IllegalArgumentException - in case of any inconsistenciespublic static HijriCalendar nowInSystemTime(java.lang.String variant, StartOfDay startOfDay)
Obtains the current calendar date in system time.
Convenient short-cut for:
SystemClock.inLocalView().now(HijriCalendar.family(), variant, startOfDay).toDate()).
variant - calendar variantstartOfDay - determines the exact time of day when the calendar date will change (usually in the evening)SystemClock.inLocalView(),
ZonalClock.now(CalendarFamily, String, StartOfDay),
StartOfDay.EVENINGpublic static HijriCalendar nowInSystemTime(VariantSource variantSource, StartOfDay startOfDay)
Obtains the current calendar date in system time.
Convenient short-cut for:
SystemClock.inLocalView().now(HijriCalendar.family(), variantSource, startOfDay).toDate()).
variantSource - source of calendar variantstartOfDay - determines the exact time of day when the calendar date will change (usually in the evening)SystemClock.inLocalView(),
ZonalClock.now(CalendarFamily, VariantSource, StartOfDay),
StartOfDay.EVENINGpublic HijriEra getEra()
Yields the islamic era.
HijriEra.ANNO_HEGIRAEpublic int getYear()
Yields the islamic year.
public HijriMonth getMonth()
Yields the islamic month.
public int getDayOfMonth()
Yields the islamic day of month.
public Weekday getDayOfWeek()
Determines the day of week.
The Hijri calendar also uses a 7-day-week.
public int getDayOfYear()
Yields the islamic day of year.
public java.lang.String getVariant()
CalendarVariantReturns the name of the associated variant of underlying calendar system.
getVariant in class CalendarVariant<HijriCalendar>CalendarFamily.getCalendarSystem(String)public int lengthOfMonth()
Yields the length of current islamic month in days.
public int lengthOfYear()
Yields the length of current islamic year in days.
ChronoException - if data are not available for the whole year (edge case)public HijriCalendar nextYear()
Convenient short form for with(YEAR_OF_ERA.incremented()).
public HijriCalendar nextMonth()
Convenient short form for with(MONTH_OF_YEAR.incremented()).
public HijriCalendar nextDay()
Convenient short form for with(DAY_OF_MONTH.incremented()).
public GeneralTimestamp<HijriCalendar> at(PlainTime time)
Creates a new local timestamp with this date and given wall time.
If the time T24:00 is used
then the resulting timestamp will automatically be normalized such
that the timestamp will contain the following day instead.
time - wall timepublic GeneralTimestamp<HijriCalendar> atTime(int hour, int minute)
Is equivalent to at(PlainTime.of(hour, minute)).
hour - hour of day in range (0-24)minute - minute of hour in range (0-59)java.lang.IllegalArgumentException - if any argument is out of rangepublic HijriCalendar plus(int amount, HijriCalendar.Unit unit)
Adds given calendrical units to this instance.
amount - amount to be added (maybe negative)unit - calendrical unitjava.lang.ArithmeticException - in case of numerical overflowpublic HijriCalendar minus(int amount, HijriCalendar.Unit unit)
Subtracts given calendrical units from this instance.
amount - amount to be subtracted (maybe negative)unit - calendrical unitjava.lang.ArithmeticException - in case of numerical overflowpublic boolean equals(java.lang.Object obj)
CalendarVariantCompares the whole state of this instance with given object.
Implementations will usually define their state based on the temporal position and the variant name. Exceptions from this rule should be explicitly documented and reasoned.
equals in class CalendarVariant<HijriCalendar>CalendarVariant.compareTo(CalendarVariant)public int hashCode()
CalendarVariantSubclasses must redefine this method corresponding to the
behaviour of equals().
hashCode in class CalendarVariant<HijriCalendar>public java.lang.String toString()
CalendarVariantProvides a complete textual representation of the state of this calendar variant.
toString in class CalendarVariant<HijriCalendar>public static Weekmodel getDefaultWeekmodel()
Obtains the standard week model of this calendar.
The Hijri calendar usually starts on Sunday, but with the weekend on Friday and Saturday (like in Saudi-Arabia).
public static CalendarFamily<HijriCalendar> family()
Returns the associated calendar family.
public static java.lang.String getVersion(java.lang.String variant)
Determines the data version of given variant.
This method serves for data analysis only.
variant - name of islamic calendar variantChronoException - if the variant is not recognized