@CalendarType(value="persian") public final class PersianCalendar extends Calendrical<PersianCalendar.Unit,PersianCalendar> implements LocalizedPatternSupport
Represents the Solar Hijri calendar which is officially used in Iran and Afghanistan.
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.
Furthermore, all elements defined in EpochDays and CommonElements are supported.
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));
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"));
| Modifier and Type | Class and Description |
|---|---|
static class |
PersianCalendar.Date
Static view of calendar date taking into account possibly different calendar algorithms.
|
static class |
PersianCalendar.Unit
Defines some calendar units for the Persian calendar.
|
| Modifier and Type | Field and Description |
|---|---|
static StdCalendarElement<Integer,PersianCalendar> |
BOUNDED_WEEK_OF_MONTH
Equivalent to
CommonElements.boundedWeekOfMonth(PersianCalendar.axis(), PersianCalendar.getDefaultWeekmodel()). |
static StdCalendarElement<Integer,PersianCalendar> |
BOUNDED_WEEK_OF_YEAR
Equivalent to
CommonElements.boundedWeekOfYear(PersianCalendar.axis(), PersianCalendar.getDefaultWeekmodel()). |
static StdCalendarElement<Integer,PersianCalendar> |
DAY_OF_MONTH
Represents the Persian day of month.
|
static StdCalendarElement<Weekday,PersianCalendar> |
DAY_OF_WEEK
Represents the Persian day of week.
|
static StdCalendarElement<Integer,PersianCalendar> |
DAY_OF_YEAR
Represents the Persian day of year.
|
static ChronoElement<PersianEra> |
ERA
Represents the Persian era.
|
static StdCalendarElement<Weekday,PersianCalendar> |
LOCAL_DAY_OF_WEEK
Equivalent to
CommonElements.localDayOfWeek(PersianCalendar.axis(), PersianCalendar.getDefaultWeekmodel()). |
static StdCalendarElement<PersianMonth,PersianCalendar> |
MONTH_OF_YEAR
Represents the Persian month.
|
static StdCalendarElement<Integer,PersianCalendar> |
WEEK_OF_MONTH
Equivalent to
CommonElements.weekOfMonth(PersianCalendar.axis(), PersianCalendar.getDefaultWeekmodel()). |
static StdCalendarElement<Integer,PersianCalendar> |
WEEK_OF_YEAR
Equivalent to
CommonElements.weekOfYear(PersianCalendar.axis(), PersianCalendar.getDefaultWeekmodel()). |
static OrdinalWeekdayElement<PersianCalendar> |
WEEKDAY_IN_MONTH
Element with the ordinal day-of-week within given calendar month.
|
static StdCalendarElement<Integer,PersianCalendar> |
YEAR_OF_ERA
Represents the Persian year.
|
| Modifier and Type | Method and Description |
|---|---|
GeneralTimestamp<PersianCalendar> |
at(PlainTime time)
Creates a new local timestamp with this date and given wall time.
|
GeneralTimestamp<PersianCalendar> |
atTime(int hour,
int minute)
Is equivalent to
at(PlainTime.of(hour, minute)). |
static TimeAxis<PersianCalendar.Unit,PersianCalendar> |
axis()
Returns the associated time axis.
|
boolean |
equals(Object obj)
Based on the epoch day number and the calendar system.
|
PersianCalendar.Date |
getDate(PersianAlgorithm algorithm)
Obtains an alternative date view specific for given algorithm.
|
PersianCalendar.Date |
getDate(ZonalOffset offset)
Obtains an astronomical date view specific for given timezone offset.
|
int |
getDayOfMonth()
Yields the Persian day of month.
|
Weekday |
getDayOfWeek()
Determines the day of week.
|
int |
getDayOfYear()
Yields the Persian day of year.
|
static Weekmodel |
getDefaultWeekmodel()
Obtains the standard week model of this calendar.
|
PersianEra |
getEra()
Yields the Persian era.
|
PersianMonth |
getMonth()
Yields the Persian month.
|
int |
getYear()
Yields the Persian year.
|
int |
hashCode()
Based on the epoch day number.
|
boolean |
isLeapYear()
Is the year of this date a leap year?
|
static boolean |
isValid(int yearOfEra,
int month,
int dayOfMonth)
Queries if given parameter values form a well defined calendar date.
|
int |
lengthOfMonth()
Yields the length of current Persian month in days.
|
int |
lengthOfYear()
Yields the length of current Persian year in days.
|
static PersianCalendar |
nowInSystemTime()
Obtains the current calendar date in system time.
|
static PersianCalendar |
of(int pyear,
int pmonth,
int pdom)
Creates a new instance of a Persian calendar date.
|
static PersianCalendar |
of(int pyear,
PersianMonth pmonth,
int pdom)
Creates a new instance of a Persian calendar date.
|
String |
toString()
Provides a complete textual representation of the state of
this time point.
|
compareTo, getDaysSinceEpochUTC, isAfter, isBefore, isSimultaneous, minus, plusmax, min, minus, minus, plus, plus, until, untilcontains, 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<PersianEra> ERA
Represents the Persian era.
@FormattableElement(format="y") public static final StdCalendarElement<Integer,PersianCalendar> YEAR_OF_ERA
Represents the Persian year.
@FormattableElement(format="M", alt="L") public static final StdCalendarElement<PersianMonth,PersianCalendar> MONTH_OF_YEAR
Represents the Persian month.
@FormattableElement(format="d") public static final StdCalendarElement<Integer,PersianCalendar> DAY_OF_MONTH
Represents the Persian day of month.
@FormattableElement(format="D") public static final StdCalendarElement<Integer,PersianCalendar> DAY_OF_YEAR
Represents the Persian day of year.
@FormattableElement(format="E") public static final StdCalendarElement<Weekday,PersianCalendar> DAY_OF_WEEK
Represents 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.
@FormattableElement(format="F") public static final OrdinalWeekdayElement<PersianCalendar> WEEKDAY_IN_MONTH
Element with the ordinal day-of-week within given calendar month.
public static final StdCalendarElement<Weekday,PersianCalendar> LOCAL_DAY_OF_WEEK
Equivalent to
CommonElements.localDayOfWeek(PersianCalendar.axis(), PersianCalendar.getDefaultWeekmodel()).
CommonElements.localDayOfWeek(Chronology, Weekmodel),
getDefaultWeekmodel()public static final StdCalendarElement<Integer,PersianCalendar> WEEK_OF_YEAR
Equivalent to
CommonElements.weekOfYear(PersianCalendar.axis(), PersianCalendar.getDefaultWeekmodel()).
CommonElements.weekOfYear(Chronology, Weekmodel),
getDefaultWeekmodel()public static final StdCalendarElement<Integer,PersianCalendar> WEEK_OF_MONTH
Equivalent to
CommonElements.weekOfMonth(PersianCalendar.axis(), PersianCalendar.getDefaultWeekmodel()).
CommonElements.weekOfMonth(Chronology, Weekmodel),
getDefaultWeekmodel()public static final StdCalendarElement<Integer,PersianCalendar> BOUNDED_WEEK_OF_YEAR
Equivalent to
CommonElements.boundedWeekOfYear(PersianCalendar.axis(), PersianCalendar.getDefaultWeekmodel()).
CommonElements.boundedWeekOfYear(Chronology, Weekmodel),
getDefaultWeekmodel()public static final StdCalendarElement<Integer,PersianCalendar> BOUNDED_WEEK_OF_MONTH
Equivalent to
CommonElements.boundedWeekOfMonth(PersianCalendar.axis(), PersianCalendar.getDefaultWeekmodel()).
CommonElements.boundedWeekOfMonth(Chronology, Weekmodel),
getDefaultWeekmodel()public static PersianCalendar of(int pyear, PersianMonth pmonth, int pdom)
Creates a new instance of a Persian calendar date.
pyear - Persian year in the range 1-3000pmonth - Persian monthpdom - Persian day of monthPersianCalendarIllegalArgumentException - in case of any inconsistenciespublic static PersianCalendar of(int pyear, int pmonth, int pdom)
Creates a new instance of a Persian calendar date.
pyear - Persian year in the range 1-3000pmonth - Persian monthpdom - Persian day of monthPersianCalendarIllegalArgumentException - in case of any inconsistenciespublic static PersianCalendar nowInSystemTime()
Obtains the current calendar date in system time.
Convenient short-cut for: SystemClock.inLocalView().now(PersianCalendar.axis()).
SystemClock.inLocalView(),
ZonalClock.now(net.time4j.engine.Chronology)public PersianEra getEra()
Yields the Persian era.
PersianEra.ANNO_PERSICOpublic int getYear()
Yields the Persian year.
public PersianMonth getMonth()
Yields the Persian month.
public int getDayOfMonth()
Yields the Persian day of month.
public Weekday getDayOfWeek()
Determines the day of week.
The Persian calendar also uses a 7-day-week.
public int getDayOfYear()
Yields the Persian day of year.
public PersianCalendar.Date getDate(PersianAlgorithm algorithm)
Obtains an alternative date view specific for given algorithm.
algorithm - calendar computationIllegalArgumentException - in case of date overflowpublic PersianCalendar.Date getDate(ZonalOffset offset)
Obtains an astronomical date view specific for given timezone offset.
offset - timezone offsetIllegalArgumentException - in case of date overflowPersianAlgorithm.ASTRONOMICAL,
getDate(PersianAlgorithm)public int lengthOfMonth()
Yields the length of current Persian month in days.
public int lengthOfYear()
Yields the length of current Persian year in days.
public boolean isLeapYear()
Is the year of this date a leap year?
public static boolean isValid(int yearOfEra,
int month,
int dayOfMonth)
Queries if given parameter values form a well defined calendar date.
yearOfEra - the year of era to be checkedmonth - the month to be checkeddayOfMonth - the day of month to be checkedtrue if valid else falseof(int, int, int)public GeneralTimestamp<PersianCalendar> 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<PersianCalendar> 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 boolean equals(Object obj)
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.
equals in class Calendrical<PersianCalendar.Unit,PersianCalendar>Chronology.getChronoType()public int hashCode()
CalendricalBased on the epoch day number.
hashCode in class Calendrical<PersianCalendar.Unit,PersianCalendar>public String toString()
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).
toString in class TimePoint<PersianCalendar.Unit,PersianCalendar>public static Weekmodel getDefaultWeekmodel()
Obtains the standard week model of this calendar.
The persian calendar usually starts on Saturday.
public static TimeAxis<PersianCalendar.Unit,PersianCalendar> axis()
Returns the associated time axis.
Copyright © 2014–2021. All rights reserved.