@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".
Furthermore, all elements defined in EpochDays and CommonElements are supported.
// 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.CLDR_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
HijriCalendar today = // conversion valid at noon (not in the evening when next islamic day starts)
SystemClock.inLocalView().today().transform(HijriCalendar.class, HijriCalendar.VARIANT_UMALQURA);
SolarTime meccaTime = SolarTime.ofLocation(21.4225, 39.826111);
StartOfDay startOfDay = StartOfDay.definedBy(meccaTime.sunset());
HijriCalendar todayExact =
SystemClock.inLocalView().now(
HijriCalendar.family(),
HijriCalendar.VARIANT_UMALQURA,
startOfDay
).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
Locale locale = Locale.forLanguageTag("ar-SA-u-ca-islamic-umalqura");
ChronoFormatter<CalendarDate> f = ChronoFormatter.ofGenericCalendarStyle(DisplayMode.FULL, locale);
String today = f.format(SystemClock.inLocalView().today()); // conversion valid at noon
// output in arabic language using the calendar of Saudi-Arabia
HijriEra,
HijriMonth,
HijriAlgorithm,
HijriAdjustment,
NumberSystem.ARABIC,
NumberSystem.ARABIC_INDIC,
NumberSystem.ARABIC_INDIC_EXT,
StartOfDay.definedBy(ChronoFunction),
SolarTime.sunset(),
Serialized Form| Modifier and Type | Class and Description |
|---|---|
static class |
HijriCalendar.Unit
Defines some calendar units for the Hijri calendar.
|
| Modifier and Type | Field and Description |
|---|---|
static StdCalendarElement<Integer,HijriCalendar> |
BOUNDED_WEEK_OF_MONTH
Equivalent to
CommonElements.boundedWeekOfMonth(HijriCalendar.family(), HijriCalendar.getDefaultWeekmodel()). |
static StdCalendarElement<Integer,HijriCalendar> |
BOUNDED_WEEK_OF_YEAR
Equivalent to
CommonElements.boundedWeekOfYear(HijriCalendar.family(), HijriCalendar.getDefaultWeekmodel()). |
static StdCalendarElement<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<Integer,HijriCalendar> |
DAY_OF_YEAR
Represents the islamic day of year.
|
static ChronoElement<HijriEra> |
ERA
Represents the islamic era.
|
static StdCalendarElement<Weekday,HijriCalendar> |
LOCAL_DAY_OF_WEEK
Equivalent to
CommonElements.localDayOfWeek(HijriCalendar.family(), HijriCalendar.getDefaultWeekmodel()). |
static StdCalendarElement<HijriMonth,HijriCalendar> |
MONTH_OF_YEAR
Represents the islamic month.
|
static String |
VARIANT_DIYANET
The name of the Turkish Diyanet-variant.
|
static String |
VARIANT_ICU4J
Deprecated.
scheduled for future removal, as workaround, users might directly use ICU4J
|
static String |
VARIANT_UMALQURA
The name of Umm-al-qura-variant.
|
static StdCalendarElement<Integer,HijriCalendar> |
WEEK_OF_MONTH
Equivalent to
CommonElements.weekOfMonth(HijriCalendar.family(), HijriCalendar.getDefaultWeekmodel()). |
static StdCalendarElement<Integer,HijriCalendar> |
WEEK_OF_YEAR
Equivalent to
CommonElements.weekOfYear(HijriCalendar.family(), HijriCalendar.getDefaultWeekmodel()). |
static OrdinalWeekdayElement<HijriCalendar> |
WEEKDAY_IN_MONTH
Element with the ordinal day-of-week within given calendar month.
|
static StdCalendarElement<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(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.
|
String |
getVariant()
Yields the variant name of a calendar system.
|
static String |
getVersion(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(). |
static boolean |
isValid(String variant,
int yearOfEra,
int month,
int dayOfMonth)
Queries if given parameter values form a well defined calendar date.
|
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(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(String variant,
int hyear,
HijriMonth hmonth,
int hdom)
Creates a new instance of a Hijri calendar date in given variant.
|
static HijriCalendar |
of(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.
|
static void |
register(HijriData hijriData)
Registers a regional variant of the Hijri calendar.
|
String |
toString()
Provides a complete textual representation of the state of this calendar variant.
|
compareTo, getDaysSinceEpochUTC, isAfter, isBefore, isSimultaneous, minus, plus, withVariant, withVariantcontains, get, get, getInt, getMaximum, getMinimum, getRegisteredElements, getTimezone, hasTimezone, isValid, isValid, isValid, matches, with, with, with, withgetFormatPattern, getFormatPattern, useDynamicFormatPatternfrom, from, from, transform, transform, transform, transform, transform, transformisAfterAll, isAfterOrEqual, isBeforeAll, isBeforeOrEqual@FormattableElement(format="G") public static final ChronoElement<HijriEra> ERA
Represents the islamic era.
@FormattableElement(format="y") public static final StdCalendarElement<Integer,HijriCalendar> YEAR_OF_ERA
Represents the islamic year.
@FormattableElement(format="M", alt="L") public static final StdCalendarElement<HijriMonth,HijriCalendar> MONTH_OF_YEAR
Represents the islamic month.
@FormattableElement(format="d") public static final StdCalendarElement<Integer,HijriCalendar> DAY_OF_MONTH
Represents the islamic day of month.
@FormattableElement(format="D") public static final StdCalendarElement<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. This corresponds to Saudi-Arabia, but many islamic countries have a different week model.
@FormattableElement(format="F") public static final OrdinalWeekdayElement<HijriCalendar> WEEKDAY_IN_MONTH
Element with the ordinal day-of-week within given calendar month.
Example of usage:
HijriCalendar hijri =
HijriCalendar.of(HijriCalendar.VARIANT_UMALQURA, 1395, HijriMonth.RAMADAN, 1); // Sunday
System.out.println(
hijri.with(HijriCalendar.WEEKDAY_IN_MONTH.setToLast(Weekday.SATURDAY)));
// AH-1395-09-28[islamic-umalqura]
public static final String VARIANT_UMALQURA
The supported range of islamic years is 1300-1500.
@Deprecated public static final String VARIANT_ICU4J
The supported range of islamic years is 1-1600.
public static final String VARIANT_DIYANET
The supported range is 1318-01-01/1444-05-29 (ISO: 1900-05-01/2022-12-23).
public static final StdCalendarElement<Weekday,HijriCalendar> LOCAL_DAY_OF_WEEK
Equivalent to
CommonElements.localDayOfWeek(HijriCalendar.family(), HijriCalendar.getDefaultWeekmodel()).
CommonElements.localDayOfWeek(net.time4j.engine.Chronology, Weekmodel),
getDefaultWeekmodel()public static final StdCalendarElement<Integer,HijriCalendar> WEEK_OF_YEAR
Equivalent to
CommonElements.weekOfYear(HijriCalendar.family(), HijriCalendar.getDefaultWeekmodel()).
CommonElements.weekOfYear(net.time4j.engine.Chronology, Weekmodel),
getDefaultWeekmodel()public static final StdCalendarElement<Integer,HijriCalendar> WEEK_OF_MONTH
Equivalent to
CommonElements.weekOfMonth(HijriCalendar.family(), HijriCalendar.getDefaultWeekmodel()).
CommonElements.weekOfMonth(net.time4j.engine.Chronology, Weekmodel),
getDefaultWeekmodel()public static final StdCalendarElement<Integer,HijriCalendar> BOUNDED_WEEK_OF_YEAR
Equivalent to
CommonElements.boundedWeekOfYear(HijriCalendar.family(), HijriCalendar.getDefaultWeekmodel()).
CommonElements.boundedWeekOfYear(net.time4j.engine.Chronology, Weekmodel),
getDefaultWeekmodel()public static final StdCalendarElement<Integer,HijriCalendar> BOUNDED_WEEK_OF_MONTH
Equivalent to
CommonElements.boundedWeekOfMonth(HijriCalendar.family(), HijriCalendar.getDefaultWeekmodel()).
CommonElements.boundedWeekOfMonth(net.time4j.engine.Chronology, Weekmodel),
getDefaultWeekmodel()public static HijriCalendar of(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 supportedIllegalArgumentException - in case of any inconsistenciespublic static HijriCalendar of(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 supportedIllegalArgumentException - 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 supportedIllegalArgumentException - 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 supportedIllegalArgumentException - 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 supportedIllegalArgumentException - 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 supportedIllegalArgumentException - in case of any inconsistenciespublic static HijriCalendar nowInSystemTime(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 String getVariant()
VariantSourceYields the variant name of a calendar system.
getVariant in interface VariantSourcepublic 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 static boolean isValid(String variant, int yearOfEra, int month, int dayOfMonth)
Queries if given parameter values form a well defined calendar date.
variant - the variant of the underlying calendar systemyearOfEra - the year of era to be checkedmonth - the month to be checkeddayOfMonth - the day of month to be checkedtrue if valid else falseof(String, int, int, int)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)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 unitArithmeticException - 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 unitArithmeticException - in case of numerical overflowpublic boolean equals(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 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 void register(HijriData hijriData)
Registers a regional variant of the Hijri calendar.
Repeated calls with the same variant will effectively update the existing registered variant.
hijriData - interface for regional Hijri variantIllegalStateException - if the initialization of Hijri data failsIllegalArgumentException - if the data are wrongpublic static String getVersion(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 recognizedCopyright © 2014–2021. All rights reserved.