public final class ThaiBuddhistDate extends java.lang.Object implements DateProvider, Calendrical, java.lang.Comparable<ThaiBuddhistDate>, java.io.Serializable
ThaiBuddhistDate
is an immutable class that represents a date in the Thai Buddhist calendar system.
The rules of the calendar system are described in ThaiBuddhistChronology
.
Instances of this class may be created from other date objects that implement Calendrical
.
Notably this includes LocalDate
and all other date classes from other calendar systems.
ThaiBuddhistDate is immutable and thread-safe.
Modifier and Type | Field and Description |
---|---|
static int |
MAX_YEAR_OF_ERA
The maximum valid year-of-era.
|
static int |
MIN_YEAR_OF_ERA
The minimum valid year-of-era.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(ThaiBuddhistDate other)
Compares this date to another date.
|
boolean |
equals(java.lang.Object other)
Checks if this date is equal to the specified date.
|
<T> T |
get(CalendricalRule<T> rule)
Gets the value of the specified calendrical rule.
|
ThaiBuddhistChronology |
getChronology()
Gets the chronology that this date uses, which is the Thai Buddhist calendar system.
|
int |
getDayOfMonth()
Gets the day-of-month field.
|
DayOfWeek |
getDayOfWeek()
Gets the day-of-week field, which is an enum
DayOfWeek . |
int |
getDayOfYear()
Gets the day-of-year field.
|
ThaiBuddhistEra |
getEra()
Gets the Thai Buddhist era field.
|
MonthOfYear |
getMonthOfYear()
Gets the month-of-year field.
|
int |
getYearOfEra()
Gets the Thai Buddhist year-of-era field.
|
int |
hashCode()
A hash code for this date.
|
boolean |
isAfter(ThaiBuddhistDate other)
Checks if this date is after the specified date.
|
boolean |
isBefore(ThaiBuddhistDate other)
Checks if this date is before the specified date.
|
boolean |
isLeapYear()
Checks if the year is a leap year, according to the Thai Buddhist calendar system rules.
|
ThaiBuddhistDate |
minusDays(long days)
Returns a copy of this date with the specified number of days subtracted.
|
ThaiBuddhistDate |
minusMonths(int months)
Returns a copy of this date with the specified number of months subtracted.
|
ThaiBuddhistDate |
minusWeeks(int weeks)
Returns a copy of this date with the specified number of weeks subtracted.
|
ThaiBuddhistDate |
minusYears(int years)
Returns a copy of this date with the specified number of years subtracted.
|
static ThaiBuddhistDate |
of(Calendrical calendrical)
Obtains an instance of
ThaiBuddhistDate from a calendrical. |
static ThaiBuddhistDate |
of(int yearOfThaiBuddhistEra,
MonthOfYear monthOfYear,
int dayOfMonth)
Obtains an instance of
ThaiBuddhistDate from the Thai Buddhist year,
month-of-year and day-of-month. |
static ThaiBuddhistDate |
of(ThaiBuddhistEra era,
int yearOfEra,
MonthOfYear monthOfYear,
int dayOfMonth)
Obtains an instance of
ThaiBuddhistDate from the era, year-of-era,
month-of-year and day-of-month. |
ThaiBuddhistDate |
plusDays(long days)
Returns a copy of this date with the specified number of days added.
|
ThaiBuddhistDate |
plusMonths(int months)
Returns a copy of this date with the specified number of months added.
|
ThaiBuddhistDate |
plusWeeks(int weeks)
Returns a copy of this date with the specified number of weeks added.
|
ThaiBuddhistDate |
plusYears(int years)
Returns a copy of this date with the specified number of years added.
|
static CalendricalRule<ThaiBuddhistDate> |
rule()
Gets the rule for
ThaiBuddhistDate . |
LocalDate |
toLocalDate()
Converts this date to a
LocalDate , which is the default representation
of a date, and provides values in the ISO-8601 calendar system. |
java.lang.String |
toString()
Outputs this date as a
String , such as 2551-12-01 (ThaiBuddhist) . |
ThaiBuddhistDate |
withDayOfMonth(int dayOfMonth)
Returns a copy of this date with the day-of-month altered.
|
ThaiBuddhistDate |
withDayOfYear(int dayOfYear)
Returns a copy of this date with the day-of-year altered.
|
ThaiBuddhistDate |
withMonthOfYear(MonthOfYear monthOfYear)
Returns a copy of this date with the month-of-year altered.
|
ThaiBuddhistDate |
withYear(ThaiBuddhistEra era,
int yearOfEra)
Returns a copy of this date with the year altered.
|
ThaiBuddhistDate |
withYearOfEra(int yearOfEra)
Returns a copy of this date with the year-of-era altered.
|
public static final int MIN_YEAR_OF_ERA
public static final int MAX_YEAR_OF_ERA
public static ThaiBuddhistDate of(int yearOfThaiBuddhistEra, MonthOfYear monthOfYear, int dayOfMonth)
ThaiBuddhistDate
from the Thai Buddhist year,
month-of-year and day-of-month. This uses the Thai Buddhist era.yearOfThaiBuddhistEra
- the year to represent in the Thai Buddhist era, from 1 to 9999monthOfYear
- the month-of-year to represent, not nulldayOfMonth
- the day-of-month to represent, from 1 to 31IllegalCalendarFieldValueException
- if the value of any field is out of rangeInvalidCalendarFieldException
- if the day-of-month is invalid for the month-yearpublic static ThaiBuddhistDate of(ThaiBuddhistEra era, int yearOfEra, MonthOfYear monthOfYear, int dayOfMonth)
ThaiBuddhistDate
from the era, year-of-era,
month-of-year and day-of-month.era
- the era to represent, not nullyearOfEra
- the year-of-era to represent, from 1 to 9999monthOfYear
- the month-of-year to represent, not nulldayOfMonth
- the day-of-month to represent, from 1 to 31IllegalCalendarFieldValueException
- if the value of any field is out of rangeInvalidCalendarFieldException
- if the day-of-month is invalid for the month-yearpublic static ThaiBuddhistDate of(Calendrical calendrical)
ThaiBuddhistDate
from a calendrical.
This can be used extract the date directly from any implementation
of Calendrical
, including those in other calendar systems.
calendrical
- the calendrical to extract from, not nullCalendricalException
- if the date cannot be obtainedpublic ThaiBuddhistChronology getChronology()
public <T> T get(CalendricalRule<T> rule)
This method queries the value of the specified calendrical rule.
If the value cannot be returned for the rule from this date then
null
will be returned.
get
in interface Calendrical
rule
- the rule to use, not nullpublic ThaiBuddhistEra getEra()
public int getYearOfEra()
public MonthOfYear getMonthOfYear()
public int getDayOfMonth()
public int getDayOfYear()
public DayOfWeek getDayOfWeek()
DayOfWeek
.
This method returns the enum DayOfWeek
for the day-of-week.
This avoids confusion as to what int
values mean.
If you need access to the primitive int
value then the enum
provides the int value
.
Additional information can be obtained from the DayOfWeek
.
This includes textual names of the values.
public boolean isLeapYear()
public ThaiBuddhistDate withYear(ThaiBuddhistEra era, int yearOfEra)
This method changes the year of the date. If the month-day is invalid for the year, then the previous valid day will be selected instead.
This instance is immutable and unaffected by this method call.
era
- the era to set in the returned date, not nullyearOfEra
- the year-of-era to set in the returned date, from 1 to 9999ThaiBuddhistDate
based on this date with the requested year, never nullIllegalCalendarFieldValueException
- if the year-of-era value is invalidpublic ThaiBuddhistDate withYearOfEra(int yearOfEra)
This method changes the year-of-era of the date. If the month-day is invalid for the year, then the previous valid day will be selected instead.
This instance is immutable and unaffected by this method call.
yearOfEra
- the year to set in the returned date, from 1 to 9999ThaiBuddhistDate
based on this date with the requested year-of-era, never nullIllegalCalendarFieldValueException
- if the year-of-era value is invalidpublic ThaiBuddhistDate withMonthOfYear(MonthOfYear monthOfYear)
This method changes the month-of-year of the date. If the month-day is invalid for the year, then the previous valid day will be selected instead.
This instance is immutable and unaffected by this method call.
monthOfYear
- the month-of-year to set in the returned date, not nullThaiBuddhistDate
based on this date with the requested month, never nullpublic ThaiBuddhistDate withDayOfMonth(int dayOfMonth)
This method changes the day-of-month of the date. If the resulting date is invalid, an exception is thrown.
This instance is immutable and unaffected by this method call.
dayOfMonth
- the day-of-month to set in the returned date, from 1 to 28-31ThaiBuddhistDate
based on this date with the requested day, never nullIllegalCalendarFieldValueException
- if the day-of-month value is invalidInvalidCalendarFieldException
- if the day-of-month is invalid for the month-yearpublic ThaiBuddhistDate withDayOfYear(int dayOfYear)
This method changes the day-of-year of the date. If the resulting date is invalid, an exception is thrown.
This instance is immutable and unaffected by this method call.
dayOfYear
- the day-of-year to set in the returned date, from 1 to 365-366ThaiBuddhistDate
based on this date with the requested day, never nullIllegalCalendarFieldValueException
- if the day-of-year value is invalidInvalidCalendarFieldException
- if the day-of-year is invalid for the yearpublic ThaiBuddhistDate plusYears(int years)
This method adds the specified amount in years to the date. If the month-day is invalid for the year, then the previous valid day will be selected instead.
This instance is immutable and unaffected by this method call.
years
- the years to add, may be negativeThaiBuddhistDate
based on this date with the years added, never nullCalendricalException
- if the result exceeds the supported date rangepublic ThaiBuddhistDate plusMonths(int months)
This method adds the specified amount in months to the date. If the month-day is invalid for the year, then the previous valid day will be selected instead.
This instance is immutable and unaffected by this method call.
months
- the months to add, may be negativeThaiBuddhistDate
based on this date with the months added, never nullCalendricalException
- if the result exceeds the supported date rangepublic ThaiBuddhistDate plusWeeks(int weeks)
This method adds the specified amount in weeks to the date.
This instance is immutable and unaffected by this method call.
weeks
- the weeks to add, may be negativeThaiBuddhistDate
based on this date with the weeks added, never nullCalendricalException
- if the result exceeds the supported date rangepublic ThaiBuddhistDate plusDays(long days)
This method adds the specified amount in days to the date.
This instance is immutable and unaffected by this method call.
days
- the days to add, may be negativeThaiBuddhistDate
based on this date with the days added, never nullCalendricalException
- if the result exceeds the supported date rangepublic ThaiBuddhistDate minusYears(int years)
This method subtracts the specified amount in years from the date. If the month-day is invalid for the year, then the previous valid day will be selected instead.
This instance is immutable and unaffected by this method call.
years
- the years to subtract, may be negativeThaiBuddhistDate
based on this date with the years subtracted, never nullCalendricalException
- if the result exceeds the supported date rangepublic ThaiBuddhistDate minusMonths(int months)
This method subtracts the specified amount in months from the date. If the month-day is invalid for the year, then the previous valid day will be selected instead.
This instance is immutable and unaffected by this method call.
months
- the months to subtract, may be negativeThaiBuddhistDate
based on this date with the months subtracted, never nullCalendricalException
- if the result exceeds the supported date rangepublic ThaiBuddhistDate minusWeeks(int weeks)
This method subtracts the specified amount in weeks from the date.
This instance is immutable and unaffected by this method call.
weeks
- the weeks to subtract, may be negativeThaiBuddhistDate
based on this date with the weeks subtracted, never nullCalendricalException
- if the result exceeds the supported date rangepublic ThaiBuddhistDate minusDays(long days)
This method subtracts the specified amount in days from the date.
This instance is immutable and unaffected by this method call.
days
- the days to subtract, may be negativeThaiBuddhistDate
based on this date with the days subtracted, never nullCalendricalException
- if the result exceeds the supported date rangepublic LocalDate toLocalDate()
LocalDate
, which is the default representation
of a date, and provides values in the ISO-8601 calendar system.toLocalDate
in interface DateProvider
public int compareTo(ThaiBuddhistDate other)
The comparison is based on the time-line position of the dates.
compareTo
in interface java.lang.Comparable<ThaiBuddhistDate>
other
- the other date to compare to, not nullpublic boolean isAfter(ThaiBuddhistDate other)
The comparison is based on the time-line position of the dates.
other
- the other date to compare to, not nullpublic boolean isBefore(ThaiBuddhistDate other)
The comparison is based on the time-line position of the dates.
other
- the other date to compare to, not nullpublic boolean equals(java.lang.Object other)
The comparison is based on the time-line position of the dates.
equals
in class java.lang.Object
other
- the other date to compare to, null returns falsepublic int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
String
, such as 2551-12-01 (ThaiBuddhist)
.
The output will be in the format yyyy-MM-dd (ThaiBuddhist)
.
The year will be negative for the era BEFORE_BUDDHIST.
There is no year zero.
toString
in class java.lang.Object
public static CalendricalRule<ThaiBuddhistDate> rule()
ThaiBuddhistDate
.