Class PersianCalendar
- All Implemented Interfaces:
Serializable,Comparable<PersianCalendar>,CalendarDate,ChronoDisplay,Temporal<CalendarDate>,LocalizedPatternSupport
Represents the Solar Hijri calendar which is officially used in Iran and Afghanistan.
Introduction
It is a solar calendar which is in close agreement with the astronomical seasons. The vernal equinox serves as the first day of the Persian year (Farvardin 1st). If it is observed before noon at local time in Teheran then the associated day is the first day of the year else the next day. More details about the length of the vernal-equinox-year see: A concise review of the Iranian calendar
The calendar year is divided into 12 Persian months. The first 6 months are 31 days long. The following months are 30 days long with the exception of the last month whose length is 29 days in normal years and 30 days in leap years. The algorithm is based on the excellent work of Borkowski who describes the details at The Persian calendar for 3000 years. It is in agreement with the well known cycle proposed by Omar Khayam for the years 1178-1633 (ISO: 1799-2254). However, dates calculated in far future beyond 2123 can still be wrong due to the uncertainty of astronomical term delta-T and should be considered as approximation.
Following elements which are declared as constants are registered by this class
Furthermore, all elements defined in EpochDays and CommonElements are supported.
Example of usage
ChronoFormatter<PersianCalendar> formatter =
ChronoFormatter.setUp(PersianCalendar.axis(), new Locale("fa"))
.addPattern("EEE, d. MMMM yy", PatternType.CLDR_DATE).build();
PlainDate today = SystemClock.inLocalView().today();
PersianCalendar jalali = today.transform(PersianCalendar.class);
System.out.println(formatter.format(jalali));
Support for unicode ca-extensions
Locale loc = Locale.forLanguageTag("de-IR-u-ca-persian");
ChronoFormatter<CalendarDate> formatter = ChronoFormatter.ofGenericCalendarStyle(DisplayMode.MEDIUM, loc);
PersianCalendar jalali = PersianCalendar.of(1393, 1, 10);
PlainDate gregorian = jalali.transform(PlainDate.class);
assertThat(formatter.format(jalali), is("10.01.1393 AP"));
assertThat(formatter.format(gregorian), is("10.01.1393 AP"));
- Since:
- 3.9/4.6
- Author:
- Meno Hochschild
- See Also:
- Serialized Form
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classStatic view of calendar date taking into account possibly different calendar algorithms.static classDefines some calendar units for the Persian calendar. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic StdCalendarElement<Integer,PersianCalendar>Equivalent toCommonElements.boundedWeekOfMonth(PersianCalendar.axis(), PersianCalendar.getDefaultWeekmodel()).static StdCalendarElement<Integer,PersianCalendar>Equivalent toCommonElements.boundedWeekOfYear(PersianCalendar.axis(), PersianCalendar.getDefaultWeekmodel()).static StdCalendarElement<Integer,PersianCalendar>Represents the Persian day of month.static StdCalendarElement<Weekday,PersianCalendar>Represents the Persian day of week.static StdCalendarElement<Integer,PersianCalendar>Represents the Persian day of year.static ChronoElement<PersianEra>Represents the Persian era.static StdCalendarElement<Weekday,PersianCalendar>Equivalent toCommonElements.localDayOfWeek(PersianCalendar.axis(), PersianCalendar.getDefaultWeekmodel()).Represents the Persian month.static StdCalendarElement<Integer,PersianCalendar>Equivalent toCommonElements.weekOfMonth(PersianCalendar.axis(), PersianCalendar.getDefaultWeekmodel()).static StdCalendarElement<Integer,PersianCalendar>Equivalent toCommonElements.weekOfYear(PersianCalendar.axis(), PersianCalendar.getDefaultWeekmodel()).static OrdinalWeekdayElement<PersianCalendar>Element with the ordinal day-of-week within given calendar month.static StdCalendarElement<Integer,PersianCalendar>Represents the Persian 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)).static TimeAxis<PersianCalendar.Unit,PersianCalendar>axis()Returns the associated time axis.booleanBased on the epoch day number and the calendar system.getDate(PersianAlgorithm algorithm)Obtains an alternative date view specific for given algorithm.getDate(ZonalOffset offset)Obtains an astronomical date view specific for given timezone offset.intYields the Persian day of month.Determines the day of week.intYields the Persian day of year.static WeekmodelObtains the standard week model of this calendar.getEra()Yields the Persian era.getMonth()Yields the Persian month.intgetYear()Yields the Persian year.inthashCode()Based on the epoch day number.booleanIs the year of this date a leap year?static booleanisValid(int yearOfEra, int month, int dayOfMonth)Queries if given parameter values form a well defined calendar date.intYields the length of current Persian month in days.intYields the length of current Persian year in days.static PersianCalendarObtains the current calendar date in system time.static PersianCalendarof(int pyear, int pmonth, int pdom)Creates a new instance of a Persian calendar date.static PersianCalendarof(int pyear, PersianMonth pmonth, int pdom)Creates a new instance of a Persian calendar date.toString()Provides a complete textual representation of the state of this time point.Methods inherited from class net.time4j.engine.Calendrical
compareTo, getDaysSinceEpochUTC, isAfter, isBefore, isSimultaneous, minus, plusMethods inherited from class net.time4j.engine.TimePoint
max, min, minus, minus, plus, plus, until, untilMethods inherited from class net.time4j.engine.ChronoEntity
contains, get, get, getInt, getMaximum, getMinimum, getRegisteredElements, getTimezone, hasTimezone, isValid, isValid, isValid, matches, with, with, with, withMethods inherited from interface net.time4j.engine.CalendarDate
transform, transform, transform, transform, transform, transformMethods inherited from interface net.time4j.format.LocalizedPatternSupport
getFormatPattern, getFormatPattern, useDynamicFormatPatternMethods inherited from interface net.time4j.engine.Temporal
isAfterAll, isAfterOrEqual, isBeforeAll, isBeforeOrEqual
-
Field Details
-
ERA
Represents the Persian era.
-
YEAR_OF_ERA
@FormattableElement(format="y") public static final StdCalendarElement<Integer,PersianCalendar> YEAR_OF_ERARepresents the Persian year.
-
MONTH_OF_YEAR
@FormattableElement(format="M", alt="L") public static final StdCalendarElement<PersianMonth,PersianCalendar> MONTH_OF_YEARRepresents the Persian month.
-
DAY_OF_MONTH
@FormattableElement(format="d") public static final StdCalendarElement<Integer,PersianCalendar> DAY_OF_MONTHRepresents the Persian day of month.
-
DAY_OF_YEAR
@FormattableElement(format="D") public static final StdCalendarElement<Integer,PersianCalendar> DAY_OF_YEARRepresents the Persian day of year.
-
DAY_OF_WEEK
@FormattableElement(format="E") public static final StdCalendarElement<Weekday,PersianCalendar> DAY_OF_WEEKRepresents the Persian day of week.
If the day-of-week is set to a new value then Time4J handles the Persian calendar week as starting on Saturday.
-
WEEKDAY_IN_MONTH
@FormattableElement(format="F") public static final OrdinalWeekdayElement<PersianCalendar> WEEKDAY_IN_MONTHElement with the ordinal day-of-week within given calendar month.
-
LOCAL_DAY_OF_WEEK
Equivalent to
CommonElements.localDayOfWeek(PersianCalendar.axis(), PersianCalendar.getDefaultWeekmodel()).- Since:
- 3.40/4.35
- See Also:
CommonElements.localDayOfWeek(Chronology, Weekmodel),getDefaultWeekmodel()
-
WEEK_OF_YEAR
Equivalent to
CommonElements.weekOfYear(PersianCalendar.axis(), PersianCalendar.getDefaultWeekmodel()).- Since:
- 3.40/4.35
- See Also:
CommonElements.weekOfYear(Chronology, Weekmodel),getDefaultWeekmodel()
-
WEEK_OF_MONTH
Equivalent to
CommonElements.weekOfMonth(PersianCalendar.axis(), PersianCalendar.getDefaultWeekmodel()).- Since:
- 3.40/4.35
- See Also:
CommonElements.weekOfMonth(Chronology, Weekmodel),getDefaultWeekmodel()
-
BOUNDED_WEEK_OF_YEAR
Equivalent to
CommonElements.boundedWeekOfYear(PersianCalendar.axis(), PersianCalendar.getDefaultWeekmodel()).- Since:
- 3.40/4.35
- See Also:
CommonElements.boundedWeekOfYear(Chronology, Weekmodel),getDefaultWeekmodel()
-
BOUNDED_WEEK_OF_MONTH
Equivalent to
CommonElements.boundedWeekOfMonth(PersianCalendar.axis(), PersianCalendar.getDefaultWeekmodel()).- Since:
- 3.40/4.35
- See Also:
CommonElements.boundedWeekOfMonth(Chronology, Weekmodel),getDefaultWeekmodel()
-
-
Method Details
-
of
Creates a new instance of a Persian calendar date.
- Parameters:
pyear- Persian year in the range 1-3000pmonth- Persian monthpdom- Persian day of month- Returns:
- new instance of
PersianCalendar - Throws:
IllegalArgumentException- in case of any inconsistencies- Since:
- 3.9/4.6
-
of
Creates a new instance of a Persian calendar date.
- Parameters:
pyear- Persian year in the range 1-3000pmonth- Persian monthpdom- Persian day of month- Returns:
- new instance of
PersianCalendar - Throws:
IllegalArgumentException- in case of any inconsistencies- Since:
- 3.9/4.6
-
nowInSystemTime
Obtains the current calendar date in system time.
Convenient short-cut for:
SystemClock.inLocalView().now(PersianCalendar.axis()).- Returns:
- current calendar date in system time zone using the system clock
- Since:
- 3.23/4.19
- See Also:
SystemClock.inLocalView(),ZonalClock.now(net.time4j.engine.Chronology)
-
getEra
Yields the Persian era.
- Returns:
PersianEra.ANNO_PERSICO- Since:
- 3.9/4.6
-
getYear
public int getYear()Yields the Persian year.
- Returns:
- int
- Since:
- 3.9/4.6
-
getMonth
Yields the Persian month.
- Returns:
- enum
- Since:
- 3.9/4.6
-
getDayOfMonth
public int getDayOfMonth()Yields the Persian day of month.
- Returns:
- int
- Since:
- 3.9/4.6
-
getDayOfWeek
Determines the day of week.
The Persian calendar also uses a 7-day-week.
- Returns:
- Weekday
- Since:
- 3.9/4.6
-
getDayOfYear
public int getDayOfYear()Yields the Persian day of year.
- Returns:
- int
- Since:
- 3.9/4.6
-
getDate
Obtains an alternative date view specific for given algorithm.
- Parameters:
algorithm- calendar computation- Returns:
- Persian date (possibly modified)
- Throws:
IllegalArgumentException- in case of date overflow- Since:
- 3.33/4.28
-
getDate
Obtains an astronomical date view specific for given timezone offset.
- Parameters:
offset- timezone offset- Returns:
- Persian date based on astronomical calculations for given offset (possibly modified)
- Throws:
IllegalArgumentException- in case of date overflow- Since:
- 3.33/4.28
- See Also:
PersianAlgorithm.ASTRONOMICAL,getDate(PersianAlgorithm)
-
lengthOfMonth
public int lengthOfMonth()Yields the length of current Persian month in days.
- Returns:
- int
- Since:
- 3.9/4.6
-
lengthOfYear
public int lengthOfYear()Yields the length of current Persian year in days.
- Returns:
- int
- Since:
- 3.9/4.6
-
isLeapYear
public boolean isLeapYear()Is the year of this date a leap year?
- Returns:
- boolean
- Since:
- 3.9/4.6
-
isValid
public static boolean isValid(int yearOfEra, int month, int dayOfMonth)Queries if given parameter values form a well defined calendar date.
- Parameters:
yearOfEra- the year of era to be checkedmonth- the month to be checkeddayOfMonth- the day of month to be checked- Returns:
trueif valid elsefalse- Since:
- 3.34/4.29
- See Also:
of(int, int, int)
-
at
Creates a new local timestamp with this date and given wall time.
If the time
T24:00is 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.9/4.6
-
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.9/4.6
-
equals
Description copied from class:CalendricalBased on the epoch day number and the calendar system.
In other words: Two date object are equal if they have the same temporal position on the local timeline and have the same calendrical type. Subclasses which define further state attributes must override this method.
If an only temporal comparison is required then the method
Calendrical.isSimultaneous(CalendarDate)is to be used.- Overrides:
equalsin classCalendrical<PersianCalendar.Unit,PersianCalendar>- See Also:
Chronology.getChronoType()
-
hashCode
public int hashCode()Description copied from class:CalendricalBased on the epoch day number.
- Overrides:
hashCodein classCalendrical<PersianCalendar.Unit,PersianCalendar>
-
toString
Description copied from class:TimePointProvides a complete textual representation of the state of this time point.
The textual description often follows the conventions of ISO-8601. Usually the description starts with the chronological informations which are coarse-grained and ends with those ones which are fine-grained (for example the ISO-notation YYYY-MM-DD).
- Specified by:
toStringin classTimePoint<PersianCalendar.Unit,PersianCalendar>
-
getDefaultWeekmodel
Obtains the standard week model of this calendar.
The persian calendar usually starts on Saturday.
- Returns:
- Weekmodel
- Since:
- 3.24/4.20
-
axis
Returns the associated time axis.
- Returns:
- chronology
- Since:
- 3.9/4.6
-