Class PersianChronology

java.lang.Object
java.time.chrono.AbstractChronology
com.github.mfathi91.time.PersianChronology
All Implemented Interfaces:
java.lang.Comparable<java.time.chrono.Chronology>, java.time.chrono.Chronology

@Immutable
public final class PersianChronology
extends java.time.chrono.AbstractChronology
The Persian calendar (also known as Jalali calendar or Iranian calendar) is a solar calendar. PersianChronology follows the rules of Persian Calendar.

Length of each month is between 29 to 31 days. Details of each month is implemented in PersianMonth enum.

Normal yeras have 365 days and leap years have 366 days.

This is an immutable and thread-safe enum.

Author:
Mahmoud Fathi
  • Field Summary

    Fields
    Modifier and Type Field Description
    static PersianChronology INSTANCE
    Single instance of this class.
  • Method Summary

    Modifier and Type Method Description
    PersianDate date​(int prolepticYear, int month, int dayOfMonth)
    Obtains a local date in this chronology from the proleptic-year, month-of-year and day-of-month fields.
    PersianDate date​(java.time.temporal.TemporalAccessor temporal)
    Obtains a local date in this chronology from another temporal object.
    PersianDate dateEpochDay​(long epochDay)
    Obtains a local date in this chronology from the epoch-day.
    PersianDate dateYearDay​(int prolepticYear, int dayOfYear)
    Obtains a local date in this chronology from the proleptic-year and day-of-year fields.
    java.time.chrono.Era eraOf​(int eraValue)
    Creates the chronology era object from the numeric value.
    java.util.List<java.time.chrono.Era> eras()
    Gets the list of eras for the chronology.
    java.lang.String getCalendarType()
    Gets the calendar type of the Persian calendar.
    java.lang.String getId()
    Gets the ID of the chronology.
    boolean isLeapYear​(long year)
    Returns true if year is a leap year in Persian calendar.
    int prolepticYear​(java.time.chrono.Era era, int yearOfEra)
    Calculates the proleptic-year given the era and year-of-era.
    java.time.temporal.ValueRange range​(java.time.temporal.ChronoField field)
    Gets the range of valid values for the specified field.

    Methods inherited from class java.time.chrono.AbstractChronology

    compareTo, equals, hashCode, resolveDate, toString

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface java.time.chrono.Chronology

    date, dateNow, dateNow, dateNow, dateYearDay, epochSecond, epochSecond, getDisplayName, localDateTime, period, zonedDateTime, zonedDateTime
  • Field Details

    • INSTANCE

      public static final PersianChronology INSTANCE
      Single instance of this class.
  • Method Details

    • getId

      public java.lang.String getId()
      Gets the ID of the chronology.
      Returns:
      the chronology ID, non-null
      See Also:
      getCalendarType()
    • getCalendarType

      public java.lang.String getCalendarType()
      Gets the calendar type of the Persian calendar.
      Returns:
      the calendar system type; non-null if the calendar has a standard type, otherwise null
      See Also:
      getId()
    • date

      public PersianDate date​(int prolepticYear, int month, int dayOfMonth)
      Obtains a local date in this chronology from the proleptic-year, month-of-year and day-of-month fields.
      Parameters:
      prolepticYear - the chronology proleptic-year
      month - the chronology month-of-year
      dayOfMonth - the chronology day-of-month
      Returns:
      the local date in this chronology, not null
      Throws:
      java.time.DateTimeException - if unable to create the date
    • dateYearDay

      public PersianDate dateYearDay​(int prolepticYear, int dayOfYear)
      Obtains a local date in this chronology from the proleptic-year and day-of-year fields.
      Parameters:
      prolepticYear - the chronology proleptic-year
      dayOfYear - the chronology day-of-year
      Returns:
      the local date in this chronology, not null
      Throws:
      java.time.DateTimeException - if unable to create the date
    • dateEpochDay

      public PersianDate dateEpochDay​(long epochDay)
      Obtains a local date in this chronology from the epoch-day.

      The definition of EPOCH_DAY is the same for all calendar systems, thus it can be used for conversion.

      Parameters:
      epochDay - the epoch day
      Returns:
      the local date in this chronology, not null
      Throws:
      java.time.DateTimeException - if unable to create the date
    • date

      public PersianDate date​(java.time.temporal.TemporalAccessor temporal)
      Obtains a local date in this chronology from another temporal object.

      This obtains a date in this chronology based on the specified temporal. A TemporalAccessor represents an arbitrary set of date and time information, which this factory converts to an instance of ChronoLocalDate.

      The conversion typically uses the EPOCH_DAY field, which is standardized across calendar systems.

      This method matches the signature of the functional interface TemporalQuery allowing it to be used as a query via method reference, aChronology::date.

      Parameters:
      temporal - the temporal object to convert, not null
      Returns:
      the local date in this chronology, not null
      Throws:
      java.time.DateTimeException - if unable to create the date
      See Also:
      ChronoLocalDate.from(TemporalAccessor)
    • isLeapYear

      public boolean isLeapYear​(long year)
      Returns true if year is a leap year in Persian calendar.
      Parameters:
      year - the year to be checked whether is a leap year or not. For valid range, check range(ChronoField YEAR).
      Returns:
      true if year is a leap year in Persian calendar
    • prolepticYear

      public int prolepticYear​(java.time.chrono.Era era, int yearOfEra)
      Calculates the proleptic-year given the era and year-of-era.

      This combines the era and year-of-era into the single proleptic-year field.

      Parameters:
      era - the era of the correct type for the chronology, not null
      yearOfEra - the chronology year-of-era
      Returns:
      the proleptic-year
      Throws:
      java.time.DateTimeException - if unable to convert to a proleptic-year, such as if the year is invalid for the era
      java.lang.ClassCastException - if the era is not of the correct type for the chronology
    • eraOf

      public java.time.chrono.Era eraOf​(int eraValue)
      Creates the chronology era object from the numeric value.

      The era is, conceptually, the largest division of the time-line. Most calendar systems have a single epoch dividing the time-line into two eras. However, some have multiple eras, such as one for the reign of each leader. The exact meaning is determined by the chronology according to the following constraints.

      This method returns the singleton era of the correct type for the specified era value.

      Parameters:
      eraValue - the era value
      Returns:
      the calendar system era, not null
      Throws:
      java.time.DateTimeException - if unable to create the era
    • eras

      public java.util.List<java.time.chrono.Era> eras()
      Gets the list of eras for the chronology.
      Returns:
      the list of eras for the chronology, may be immutable, not null
    • range

      public java.time.temporal.ValueRange range​(java.time.temporal.ChronoField field)
      Gets the range of valid values for the specified field.

      All fields can be expressed as a long integer. This method returns an object that describes the valid range for that value.

      Note that the result only describes the minimum and maximum valid values and it is important not to read too much into them. For example, there could be values within the range that are invalid for the field.

      This method will return a result whether or not the chronology supports the field.

      Parameters:
      field - the field to get the range for, not null
      Returns:
      the range of valid values for the field, not null
      Throws:
      java.time.DateTimeException - if the range for the field cannot be obtained