@Immutable public final class PersianDate extends Object implements Comparable<PersianDate>
PersianDate is an immutable date-time object that represents a date,
often viewed as year-month-day.
In order to simplify usage of this class, it is tried to make API of this class
the same as JDK8 LocalDate class.
This class is immutable and can be used in multi-threaded programs.
| Modifier and Type | Field and Description |
|---|---|
static PersianDate |
MAX
The minimum supported persian date.
|
static PersianDate |
MIN
The maximum supported persian date.
|
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(PersianDate other)
Compares this persian date to another persian date.
|
boolean |
equals(Object obj)
Checks if this date is equal to another date.
|
int |
getDayOfMonth() |
DayOfWeek |
getDayOfWeek()
Returns day-of-week as an enum
DayOfWeek. |
int |
getDayOfYear() |
PersianMonth |
getMonth() |
int |
getMonthValue() |
int |
getYear() |
static PersianDate |
gregorianToPersian(LocalDate ld)
Returns an equivalent Persian date and time as an instance of
PersianDate. |
int |
hashCode()
A hash code for this persian date.
|
boolean |
isAfter(PersianDate other)
Checks whether this persian date is after the specified persian date.
|
boolean |
isBefore(PersianDate other)
Checks whether this persian date is before the specified persian date.
|
boolean |
isEqual(PersianDate other)
Checks whether this persian date has the same date with the specified persian date.
|
boolean |
isLeapYear()
Returns true if
year is a leap year in Persian calendar. |
static boolean |
isLeapYear(int year)
Returns true if
year is a leap year in Persian calendar. |
static PersianDate |
now()
Obtains current Persian date from the system clock in the default time zone.
|
static PersianDate |
of(int year,
int month,
int dayOfMonth)
Obtains an instance of
PersianDate with year, month, day of month, hour,
minute and second. |
static PersianDate |
of(int year,
PersianMonth month,
int dayOfMonth)
Obtains an instance of
PersianDate with year, month, day of month, hour,
minute and second. |
LocalDate |
toGregorian()
Returns an equivalent Gregorian date and time as an instance of
LocalDate. |
String |
toString()
Returns the string representation of this persian date.
|
public static final PersianDate MIN
public static final PersianDate MAX
public int getYear()
public PersianMonth getMonth()
Month enum.getMonthValue()public int getMonthValue()
getMonth()public int getDayOfMonth()
public int getDayOfYear()
public DayOfWeek getDayOfWeek()
DayOfWeek. This avoids confusion as to what
int means. If you need access to the primitive int value then the
enum provides the int value.DayOfWeekpublic static PersianDate now()
public static PersianDate of(int year, int month, int dayOfMonth)
PersianDate with year, month, day of month, hour,
minute and second. The value of month must be between 1 and 12.
Value 1 would be PersianMonth.FARVARDIN and value 12 represents
PersianMonth.ESFAND.year - the year to represent, from 1 to MAX_YEARmonth - the value of month, from 1 to 12dayOfMonth - the dayOfMonth to represent, from 1 to 31PersianDateDateTimeException - if the passed parameters do not form a valid date or time.public static PersianDate of(int year, PersianMonth month, int dayOfMonth)
PersianDate with year, month, day of month, hour,
minute and second.year - the year to represent, from 1 to MAX_YEARmonth - the month-of-year to represent, an instance of PersianMonthdayOfMonth - the dayOfMonth to represent, from 1 to 31PersianDateDateTimeException - if the passed parameters do not form a valid date or time.public LocalDate toGregorian()
LocalDate.
Calling this method has no effect on the object that calls this.LocalDatepublic static PersianDate gregorianToPersian(LocalDate ld)
PersianDate.
Calling this method has no effect on the class and other instances of this class.ld - Gregorian date and timePersianDatepublic boolean isLeapYear()
year is a leap year in Persian calendar.year is a leap year in Persian calendarpublic static boolean isLeapYear(int year)
year is a leap year in Persian calendar.year - the year to be checked whether is a leap year or notyear is a leap year in Persian calendarIllegalArgumentException - if argument is a negative valuepublic int compareTo(PersianDate other)
Newer persian date is considered greater.
compareTo in interface Comparable<PersianDate>other - the other persian date to compare to, not nullpublic boolean isEqual(PersianDate other)
other - instance of persian date to compare topublic boolean isBefore(PersianDate other)
PersianDate a = PersianDate.of(1396, 3, 15);
PersianDate b = PersianDate.of(1396, 6, 10);
a.isBefore(b) - true
a.isBefore(a) - false
b.isBefore(a) - false
other - instance of PersianDate to compare topublic boolean isAfter(PersianDate other)
PersianDate a = PersianDate.of(1396, 3, 15);
PersianDate b = PersianDate.of(1396, 6, 10);
a.isAfter(b) - false
a.isAfter(a) - false
b.isAfter(a) - true
other - instance of PersianDate to compare topublic boolean equals(Object obj)
Compares this LocalDate with another ensuring that the date is the same.
public int hashCode()
public String toString()
If any of the three parts of this persian date is too small to fill up its field, the field is padded with leading zeros.
Copyright © 2017. All rights reserved.