Class HijriCalendar
- All Implemented Interfaces:
Serializable
,Comparable<HijriCalendar>
,CalendarDate
,ChronoDisplay
,Temporal<CalendarDate>
,VariantSource
,LocalizedPatternSupport
Represents the Hijri calendar used in many islamic countries.
Introduction
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.
Formatting and simple transformations
// 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);
Exact handling of start of islamic day in the evening
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();
How to determine the valid calendar range
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
Support for unicode ca-extensions
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
- Since:
- 3.5/4.3
- Author:
- Meno Hochschild
- See Also:
HijriEra
,HijriMonth
,HijriAlgorithm
,HijriAdjustment
,NumberSystem.ARABIC
,NumberSystem.ARABIC_INDIC
,NumberSystem.ARABIC_INDIC_EXT
,StartOfDay.definedBy(ChronoFunction)
,SolarTime.sunset()
, Serialized Form
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Defines some calendar units for the Hijri calendar. -
Field Summary
Modifier and TypeFieldDescriptionstatic StdCalendarElement<Integer,HijriCalendar>
Equivalent toCommonElements.boundedWeekOfMonth(HijriCalendar.family(), HijriCalendar.getDefaultWeekmodel())
.static StdCalendarElement<Integer,HijriCalendar>
Equivalent toCommonElements.boundedWeekOfYear(HijriCalendar.family(), HijriCalendar.getDefaultWeekmodel())
.static StdCalendarElement<Integer,HijriCalendar>
Represents the islamic day of month.static StdCalendarElement<Weekday,HijriCalendar>
Represents the islamic day of week.static StdCalendarElement<Integer,HijriCalendar>
Represents the islamic day of year.static ChronoElement<HijriEra>
Represents the islamic era.static StdCalendarElement<Weekday,HijriCalendar>
Equivalent toCommonElements.localDayOfWeek(HijriCalendar.family(), HijriCalendar.getDefaultWeekmodel())
.static StdCalendarElement<HijriMonth,HijriCalendar>
Represents the islamic month.static String
The name of the Turkish Diyanet-variant.static String
Deprecated.scheduled for future removal, as workaround, users might directly use ICU4Jstatic String
The name of Umm-al-qura-variant.static StdCalendarElement<Integer,HijriCalendar>
Equivalent toCommonElements.weekOfMonth(HijriCalendar.family(), HijriCalendar.getDefaultWeekmodel())
.static StdCalendarElement<Integer,HijriCalendar>
Equivalent toCommonElements.weekOfYear(HijriCalendar.family(), HijriCalendar.getDefaultWeekmodel())
.static OrdinalWeekdayElement<HijriCalendar>
Element with the ordinal day-of-week within given calendar month.static StdCalendarElement<Integer,HijriCalendar>
Represents the islamic year. -
Method Summary
Modifier and TypeMethodDescriptionCreates a new local timestamp with this date and given wall time.atTime(int hour, int minute)
Is equivalent toat(PlainTime.of(hour, minute))
.boolean
Compares the whole state of this instance with given object.static CalendarFamily<HijriCalendar>
family()
Returns the associated calendar family.int
Yields the islamic day of month.Determines the day of week.int
Yields the islamic day of year.static Weekmodel
Obtains the standard week model of this calendar.getEra()
Yields the islamic era.getMonth()
Yields the islamic month.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 ofequals()
.static boolean
Queries if given parameter values form a well defined calendar date.int
Yields the length of current islamic month in days.int
Yields the length of current islamic year in days.minus(int amount, HijriCalendar.Unit unit)
Subtracts given calendrical units from this instance.nextDay()
Convenient short form forwith(DAY_OF_MONTH.incremented())
.Convenient short form forwith(MONTH_OF_YEAR.incremented())
.nextYear()
Convenient short form forwith(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
Creates a new instance of a Hijri calendar date in given variant.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(VariantSource variantSource, 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
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.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.plus(int amount, HijriCalendar.Unit unit)
Adds given calendrical units to this instance.static void
Registers a regional variant of the Hijri calendar.toString()
Provides a complete textual representation of the state of this calendar variant.Methods inherited from class net.time4j.engine.CalendarVariant
compareTo, getDaysSinceEpochUTC, isAfter, isBefore, isSimultaneous, minus, plus, withVariant, withVariant
Methods inherited from class net.time4j.engine.ChronoEntity
contains, get, get, getInt, getMaximum, getMinimum, getRegisteredElements, getTimezone, hasTimezone, isValid, isValid, isValid, matches, with, with, with, with
Methods inherited from interface net.time4j.engine.CalendarDate
transform, transform, transform, transform, transform, transform
Methods inherited from interface net.time4j.format.LocalizedPatternSupport
getFormatPattern, getFormatPattern, useDynamicFormatPattern
Methods inherited from interface net.time4j.engine.Temporal
isAfterAll, isAfterOrEqual, isBeforeAll, isBeforeOrEqual
-
Field Details
-
ERA
Represents the islamic era.
-
YEAR_OF_ERA
@FormattableElement(format="y") public static final StdCalendarElement<Integer,HijriCalendar> YEAR_OF_ERARepresents the islamic year.
-
MONTH_OF_YEAR
@FormattableElement(format="M", alt="L") public static final StdCalendarElement<HijriMonth,HijriCalendar> MONTH_OF_YEARRepresents the islamic month.
-
DAY_OF_MONTH
@FormattableElement(format="d") public static final StdCalendarElement<Integer,HijriCalendar> DAY_OF_MONTHRepresents the islamic day of month.
-
DAY_OF_YEAR
@FormattableElement(format="D") public static final StdCalendarElement<Integer,HijriCalendar> DAY_OF_YEARRepresents the islamic day of year.
-
DAY_OF_WEEK
@FormattableElement(format="E") public static final StdCalendarElement<Weekday,HijriCalendar> DAY_OF_WEEKRepresents 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.
-
WEEKDAY_IN_MONTH
@FormattableElement(format="F") public static final OrdinalWeekdayElement<HijriCalendar> WEEKDAY_IN_MONTHElement 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]
-
VARIANT_UMALQURA
The name of Umm-al-qura-variant.The supported range of islamic years is 1300-1500.
- See Also:
- Constant Field Values
-
VARIANT_ICU4J
Deprecated.scheduled for future removal, as workaround, users might directly use ICU4JThe name of the astronomical ICU4J-variant.The supported range of islamic years is 1-1600.
- Since:
- 3.6/4.4
- See Also:
- Constant Field Values
-
VARIANT_DIYANET
The name of the Turkish Diyanet-variant.The supported range is 1318-01-01/1449-08-29 (ISO: 1900-05-01/2028-01-26).
- Since:
- 3.9/4.6
- See Also:
- Constant Field Values
-
LOCAL_DAY_OF_WEEK
Equivalent to
CommonElements.localDayOfWeek(HijriCalendar.family(), HijriCalendar.getDefaultWeekmodel())
.- Since:
- 3.40/4.35
- See Also:
CommonElements.localDayOfWeek(net.time4j.engine.Chronology, Weekmodel)
,getDefaultWeekmodel()
-
WEEK_OF_YEAR
Equivalent to
CommonElements.weekOfYear(HijriCalendar.family(), HijriCalendar.getDefaultWeekmodel())
.- Since:
- 3.40/4.35
- See Also:
CommonElements.weekOfYear(net.time4j.engine.Chronology, Weekmodel)
,getDefaultWeekmodel()
-
WEEK_OF_MONTH
Equivalent to
CommonElements.weekOfMonth(HijriCalendar.family(), HijriCalendar.getDefaultWeekmodel())
.- Since:
- 3.40/4.35
- See Also:
CommonElements.weekOfMonth(net.time4j.engine.Chronology, Weekmodel)
,getDefaultWeekmodel()
-
BOUNDED_WEEK_OF_YEAR
Equivalent to
CommonElements.boundedWeekOfYear(HijriCalendar.family(), HijriCalendar.getDefaultWeekmodel())
.- Since:
- 3.40/4.35
- See Also:
CommonElements.boundedWeekOfYear(net.time4j.engine.Chronology, Weekmodel)
,getDefaultWeekmodel()
-
BOUNDED_WEEK_OF_MONTH
Equivalent to
CommonElements.boundedWeekOfMonth(HijriCalendar.family(), HijriCalendar.getDefaultWeekmodel())
.- Since:
- 3.40/4.35
- See Also:
CommonElements.boundedWeekOfMonth(net.time4j.engine.Chronology, Weekmodel)
,getDefaultWeekmodel()
-
-
Method Details
-
of
Creates a new instance of a Hijri calendar date in given variant.
- Parameters:
variant
- calendar varianthyear
- islamic yearhmonth
- islamic monthhdom
- islamic day of month- Returns:
- new instance of
HijriCalendar
- Throws:
ChronoException
- if given variant is not supportedIllegalArgumentException
- in case of any inconsistencies- Since:
- 3.5/4.3
-
of
Creates a new instance of a Hijri calendar date in given variant.
- Parameters:
variant
- calendar varianthyear
- islamic yearhmonth
- islamic monthhdom
- islamic day of month- Returns:
- new instance of
HijriCalendar
- Throws:
ChronoException
- if given variant is not supportedIllegalArgumentException
- in case of any inconsistencies- Since:
- 3.5/4.3
-
of
public static HijriCalendar of(VariantSource variantSource, int hyear, HijriMonth hmonth, int hdom)Creates a new instance of a Hijri calendar date in given variant.
- Parameters:
variantSource
- source of calendar varianthyear
- islamic yearhmonth
- islamic monthhdom
- islamic day of month- Returns:
- new instance of
HijriCalendar
- Throws:
ChronoException
- if given variant is not supportedIllegalArgumentException
- in case of any inconsistencies- Since:
- 3.6/4.4
-
of
Creates a new instance of a Hijri calendar date in given variant.
- Parameters:
variantSource
- source of calendar varianthyear
- islamic yearhmonth
- islamic monthhdom
- islamic day of month- Returns:
- new instance of
HijriCalendar
- Throws:
ChronoException
- if given variant is not supportedIllegalArgumentException
- in case of any inconsistencies- Since:
- 3.6/4.4
-
ofUmalqura
Creates a new instance of a Hijri calendar date in the variant "islamic-umalqura" used in Saudi-Arabia.
- Parameters:
hyear
- islamic yearhmonth
- islamic monthhdom
- islamic day of month- Returns:
- new instance of
HijriCalendar
- Throws:
ChronoException
- if given variant is not supportedIllegalArgumentException
- in case of any inconsistencies- Since:
- 3.5/4.3
-
ofUmalqura
Creates a new instance of a Hijri calendar date in the variant "islamic-umalqura" used in Saudi-Arabia.
- Parameters:
hyear
- islamic yearhmonth
- islamic monthhdom
- islamic day of month- Returns:
- new instance of
HijriCalendar
- Throws:
ChronoException
- if given variant is not supportedIllegalArgumentException
- in case of any inconsistencies- Since:
- 3.5/4.3
-
nowInSystemTime
Obtains the current calendar date in system time.
Convenient short-cut for:
SystemClock.inLocalView().now(HijriCalendar.family(), variant, startOfDay).toDate())
.- Parameters:
variant
- calendar variantstartOfDay
- determines the exact time of day when the calendar date will change (usually in the evening)- Returns:
- current calendar date in system time zone using the system clock
- Since:
- 3.23/4.19
- See Also:
SystemClock.inLocalView()
,ZonalClock.now(CalendarFamily, String, StartOfDay)
,StartOfDay.EVENING
-
nowInSystemTime
Obtains the current calendar date in system time.
Convenient short-cut for:
SystemClock.inLocalView().now(HijriCalendar.family(), variantSource, startOfDay).toDate())
.- Parameters:
variantSource
- source of calendar variantstartOfDay
- determines the exact time of day when the calendar date will change (usually in the evening)- Returns:
- current calendar date in system time zone using the system clock
- Since:
- 3.23/4.19
- See Also:
SystemClock.inLocalView()
,ZonalClock.now(CalendarFamily, VariantSource, StartOfDay)
,StartOfDay.EVENING
-
getEra
Yields the islamic era.
- Returns:
HijriEra.ANNO_HEGIRAE
- Since:
- 3.5/4.3
-
getYear
public int getYear()Yields the islamic year.
- Returns:
- int
- Since:
- 3.5/4.3
-
getMonth
Yields the islamic month.
- Returns:
- enum
- Since:
- 3.5/4.3
-
getDayOfMonth
public int getDayOfMonth()Yields the islamic day of month.
- Returns:
- int
- Since:
- 3.5/4.3
-
getDayOfWeek
Determines the day of week.
The Hijri calendar also uses a 7-day-week.
- Returns:
- Weekday
- Since:
- 3.5/4.3
-
getDayOfYear
public int getDayOfYear()Yields the islamic day of year.
- Returns:
- int
- Since:
- 3.5/4.3
-
getVariant
Description copied from interface:VariantSource
Yields the variant name of a calendar system.
- Specified by:
getVariant
in interfaceVariantSource
- Returns:
- String which is empty if there are no variants
-
lengthOfMonth
public int lengthOfMonth()Yields the length of current islamic month in days.
- Returns:
- int
- Since:
- 3.6/4.4
-
lengthOfYear
public int lengthOfYear()Yields the length of current islamic year in days.
- Returns:
- int
- Throws:
ChronoException
- if data are not available for the whole year (edge case)- Since:
- 3.6/4.4
-
isValid
Queries if given parameter values form a well defined calendar date.
- Parameters:
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 checked- Returns:
true
if valid elsefalse
- Since:
- 3.34/4.29
- See Also:
of(String, int, int, int)
-
nextYear
Convenient short form for
with(YEAR_OF_ERA.incremented())
.- Returns:
- copy of this instance at next year
- Since:
- 3.5/4.3
-
nextMonth
Convenient short form for
with(MONTH_OF_YEAR.incremented())
.- Returns:
- copy of this instance at next month
- Since:
- 3.5/4.3
-
nextDay
Convenient short form for
with(DAY_OF_MONTH.incremented())
.- Returns:
- copy of this instance at next day
- Since:
- 3.5/4.3
-
at
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.- Parameters:
time
- wall time- Returns:
- general timestamp as composition of this date and given time
- Since:
- 3.8/4.5
-
atTime
Is equivalent to
at(PlainTime.of(hour, minute))
.- Parameters:
hour
- hour of day in range (0-24)minute
- minute of hour in range (0-59)- Returns:
- general timestamp as composition of this date and given time
- Throws:
IllegalArgumentException
- if any argument is out of range- Since:
- 3.8/4.5
-
plus
Adds given calendrical units to this instance.
- Parameters:
amount
- amount to be added (maybe negative)unit
- calendrical unit- Returns:
- result of addition as changed copy, this instance remains unaffected
- Throws:
ArithmeticException
- in case of numerical overflow- Since:
- 3.14/4.10
-
minus
Subtracts given calendrical units from this instance.
- Parameters:
amount
- amount to be subtracted (maybe negative)unit
- calendrical unit- Returns:
- result of subtraction as changed copy, this instance remains unaffected
- Throws:
ArithmeticException
- in case of numerical overflow- Since:
- 3.14/4.10
-
equals
Description copied from class:CalendarVariant
Compares 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.
- Specified by:
equals
in classCalendarVariant<HijriCalendar>
- See Also:
CalendarVariant.compareTo(CalendarVariant)
-
hashCode
public int hashCode()Description copied from class:CalendarVariant
Subclasses must redefine this method corresponding to the behaviour of
equals()
.- Specified by:
hashCode
in classCalendarVariant<HijriCalendar>
-
toString
Description copied from class:CalendarVariant
Provides a complete textual representation of the state of this calendar variant.
- Specified by:
toString
in classCalendarVariant<HijriCalendar>
-
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).
- Returns:
- Weekmodel
- Since:
- 3.24/4.20
-
family
Returns the associated calendar family.
- Returns:
- chronology as calendar family
- Since:
- 3.5/4.3
-
register
Registers a regional variant of the Hijri calendar.
Repeated calls with the same variant will effectively update the existing registered variant.
- Parameters:
hijriData
- interface for regional Hijri variant- Throws:
IllegalStateException
- if the initialization of Hijri data failsIllegalArgumentException
- if the data are wrong- Since:
- 5.6
-
getVersion
Determines the data version of given variant.
This method serves for data analysis only.
- Parameters:
variant
- name of islamic calendar variant- Returns:
- version info (maybe empty if not relevant)
- Throws:
ChronoException
- if the variant is not recognized- Since:
- 3.9/4.6
-