Enum PersianMonth

java.lang.Object
java.lang.Enum<PersianMonth>
com.github.mfathi91.time.PersianMonth
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<PersianMonth>, java.lang.constant.Constable

@Immutable
public enum PersianMonth
extends java.lang.Enum<PersianMonth>
A month-of-year, such as Mehr.

PersianMonth is an enum representing the 12 months of the year Farvardin, Ordibehesht, Khordad, Tir, Mordad, Shahrivar, Mehr, Aban, Azar, Dey, Bahman and Esfand.

In addition to the textual enum name, each month-of-year has an int value. The int value follows normal usage and the ISO-8601 standard, from 1 (January) to 12 (December). It is recommended that applications use the enum rather than the int value to ensure code clarity.

Do not use ordinal() to obtain the numeric representation of Month. Use getValue() instead.

This is an immutable enum and can be used in concurrent programs.

Author:
Mahmoud Fathi
  • Nested Class Summary

    Nested classes/interfaces inherited from class java.lang.Enum

    java.lang.Enum.EnumDesc<E extends java.lang.Enum<E>>
  • Enum Constant Summary

    Enum Constants
    Enum Constant Description
    ABAN
    The singleton instance for the month of Aban with 30 days.
    AZAR
    The singleton instance for the month of Azar with 30 days.
    BAHMAN
    The singleton instance for the month of Bahman with 30 days.
    DEY
    The singleton instance for the month of Dey with 30 days.
    ESFAND
    The singleton instance for the month of Farvardin with 29 days in non-leap year and 30 days in leap year.
    FARVARDIN
    The singleton instance for the month of Farvardin with 31 days.
    KHORDAD
    The singleton instance for the month of Khordad with 31 days.
    MEHR
    The singleton instance for the month of Mehr with 30 days.
    MORDAD
    The singleton instance for the month of Mordad with 31 days.
    ORDIBEHESHT
    The singleton instance for the month of Ordibehesht with 31 days.
    SHAHRIVAR
    The singleton instance for the month of Shahrivar with 31 days.
    TIR
    The singleton instance for the month of Tir with 31 days.
  • Method Summary

    Modifier and Type Method Description
    int daysToFirstOfMonth()
    Returns elapsed days from first of the year to first of this month.
    java.lang.String getPersianName()
    Returns name of month in persian alphabe.
    int getValue()  
    int length​(boolean leapYear)
    Returns length of month.
    int maxLength()
    Returns length of month in a leap year.
    int minLength()
    Returns length of month in a non-leap year.
    PersianMonth minus​(long months)
    Returns a month-of-year that is months before current month.
    PersianMonth plus​(long months)
    Returns a month-of-year that is months after current month.
    static PersianMonth valueOf​(java.lang.String name)
    Returns the enum constant of this type with the specified name.
    static PersianMonth[] values()
    Returns an array containing the constants of this enum type, in the order they are declared.

    Methods inherited from class java.lang.Enum

    clone, compareTo, describeConstable, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf

    Methods inherited from class java.lang.Object

    getClass, notify, notifyAll, wait, wait, wait
  • Enum Constant Details

    • FARVARDIN

      public static final PersianMonth FARVARDIN
      The singleton instance for the month of Farvardin with 31 days. This has the numeric value of 1.
    • ORDIBEHESHT

      public static final PersianMonth ORDIBEHESHT
      The singleton instance for the month of Ordibehesht with 31 days. This has the numeric value of 2.
    • KHORDAD

      public static final PersianMonth KHORDAD
      The singleton instance for the month of Khordad with 31 days. This has the numeric value of 3.
    • TIR

      public static final PersianMonth TIR
      The singleton instance for the month of Tir with 31 days. This has the numeric value of 4.
    • MORDAD

      public static final PersianMonth MORDAD
      The singleton instance for the month of Mordad with 31 days. This has the numeric value of 5.
    • SHAHRIVAR

      public static final PersianMonth SHAHRIVAR
      The singleton instance for the month of Shahrivar with 31 days. This has the numeric value of 6.
    • MEHR

      public static final PersianMonth MEHR
      The singleton instance for the month of Mehr with 30 days. This has the numeric value of 7.
    • ABAN

      public static final PersianMonth ABAN
      The singleton instance for the month of Aban with 30 days. This has the numeric value of 8.
    • AZAR

      public static final PersianMonth AZAR
      The singleton instance for the month of Azar with 30 days. This has the numeric value of 9.
    • DEY

      public static final PersianMonth DEY
      The singleton instance for the month of Dey with 30 days. This has the numeric value of 10.
    • BAHMAN

      public static final PersianMonth BAHMAN
      The singleton instance for the month of Bahman with 30 days. This has the numeric value of 11.
    • ESFAND

      public static final PersianMonth ESFAND
      The singleton instance for the month of Farvardin with 29 days in non-leap year and 30 days in leap year. This has the numeric value of 12.
  • Method Details

    • values

      public static PersianMonth[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      Returns:
      an array containing the constants of this enum type, in the order they are declared
    • valueOf

      public static PersianMonth valueOf​(java.lang.String name)
      Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
      java.lang.NullPointerException - if the argument is null
    • getPersianName

      public java.lang.String getPersianName()
      Returns name of month in persian alphabe.
      Returns:
      persian name of month.
    • getValue

      public int getValue()
      Returns:
      number of month, from 1 (Farvardin) to 12 (Esfand)
    • length

      public int length​(boolean leapYear)
      Returns length of month. For the first six months of year, 31 is returned. For the second six months of year except Esfand, 30 is returned. Finlally For Esfand, if leapYear is true, it returns 30, otherwise it returns 29.
      Parameters:
      leapYear - true, if length of months in leap year is required
      Returns:
      length of months of Persian calendar
    • maxLength

      public int maxLength()
      Returns length of month in a leap year. For the first six months of year, 31 is returned. For the second six months of year 30 is returned.
      Returns:
      length of months of Persian calendar
    • minLength

      public int minLength()
      Returns length of month in a non-leap year. For the first six months of year, 31 is returned. For the second six months of year except Esfand, 30 is returned. For Esfand 29 is returned.
      Returns:
      length of months of Persian calendar
    • plus

      public PersianMonth plus​(long months)
      Returns a month-of-year that is months after current month. The calculation rolls around end of year from Esfand to Farvardin.

      This enum is immutable and unaffected by calling this method.

      Parameters:
      months - the months to add, positive or negative
      Returns:
      the resulting month, not null
    • minus

      public PersianMonth minus​(long months)
      Returns a month-of-year that is months before current month. The calculation rolls around the start of year from Farvardin to Esfand.

      This enum is immutable and unaffected by calling this method.

      Parameters:
      months - the months to subtract, positive or negative
      Returns:
      the resulting month, not null
    • daysToFirstOfMonth

      public int daysToFirstOfMonth()
      Returns elapsed days from first of the year to first of this month.
      Returns:
      elapsed days from first of the year to first of this month.