public final class JapaneseDate extends java.lang.Object implements DateProvider, Calendrical, java.lang.Comparable<JapaneseDate>, java.io.Serializable
JapaneseDate
is an immutable class that represents a date in the Japanese calendar system.
The rules of the calendar system are described in JapaneseChronology
.
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.
JapaneseDate 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(JapaneseDate 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.
|
JapaneseChronology |
getChronology()
Gets the chronology that this date uses, which is the Japanese 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.
|
JapaneseEra |
getEra()
Gets the Japanese era field.
|
MonthOfYear |
getMonthOfYear()
Gets the month-of-year field.
|
int |
getYearOfEra()
Gets the Japanese year-of-era field.
|
int |
hashCode()
A hash code for this date.
|
boolean |
isAfter(JapaneseDate other)
Checks if this date is after the specified date.
|
boolean |
isBefore(JapaneseDate other)
Checks if this date is before the specified date.
|
boolean |
isLeapYear()
Checks if the year is a leap year, according to the Japanese calendar system rules.
|
JapaneseDate |
minusDays(long days)
Returns a copy of this date with the specified number of days subtracted.
|
JapaneseDate |
minusMonths(int months)
Returns a copy of this date with the specified number of months subtracted.
|
JapaneseDate |
minusWeeks(int weeks)
Returns a copy of this date with the specified number of weeks subtracted.
|
JapaneseDate |
minusYears(int years)
Returns a copy of this date with the specified number of years subtracted.
|
static JapaneseDate |
of(Calendrical calendrical)
Obtains an instance of
JapaneseDate from a calendrical. |
static JapaneseDate |
of(int yearOfHeiseiEra,
MonthOfYear monthOfYear,
int dayOfMonth)
Obtains an instance of
JapaneseDate from the Heisei era year,
month-of-year and day-of-month. |
static JapaneseDate |
of(JapaneseEra era,
int yearOfEra,
MonthOfYear monthOfYear,
int dayOfMonth)
Obtains an instance of
JapaneseDate from the era, year-of-era,
month-of-year and day-of-month. |
JapaneseDate |
plusDays(long days)
Returns a copy of this date with the specified number of days added.
|
JapaneseDate |
plusMonths(int months)
Returns a copy of this date with the specified number of months added.
|
JapaneseDate |
plusWeeks(int weeks)
Returns a copy of this date with the specified number of weeks added.
|
JapaneseDate |
plusYears(int years)
Returns a copy of this date with the specified number of years added.
|
static CalendricalRule<JapaneseDate> |
rule()
Gets the rule for
JapaneseDate . |
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 SHOWA 48-12-01 (Japanese) . |
JapaneseDate |
withDayOfMonth(int dayOfMonth)
Returns a copy of this date with the day-of-month altered.
|
JapaneseDate |
withDayOfYear(int dayOfYear)
Returns a copy of this date with the day-of-year altered.
|
JapaneseDate |
withMonthOfYear(MonthOfYear monthOfYear)
Returns a copy of this date with the month-of-year altered.
|
JapaneseDate |
withYear(JapaneseEra era,
int yearOfEra)
Returns a copy of this date with the year altered.
|
JapaneseDate |
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 JapaneseDate of(int yearOfHeiseiEra, MonthOfYear monthOfYear, int dayOfMonth)
JapaneseDate
from the Heisei era year,
month-of-year and day-of-month. This uses the Heisei era.yearOfHeiseiEra
- the year to represent in the Heisei 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 JapaneseDate of(JapaneseEra era, int yearOfEra, MonthOfYear monthOfYear, int dayOfMonth)
JapaneseDate
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 JapaneseDate of(Calendrical calendrical)
JapaneseDate
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 JapaneseChronology 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 JapaneseEra 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 JapaneseDate withYear(JapaneseEra 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 9999JapaneseDate
based on this date with the requested year, never nullIllegalCalendarFieldValueException
- if the year-of-era value is invalidpublic JapaneseDate 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 9999JapaneseDate
based on this date with the requested year-of-era, never nullIllegalCalendarFieldValueException
- if the year-of-era value is invalidpublic JapaneseDate 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 nullJapaneseDate
based on this date with the requested month, never nullpublic JapaneseDate 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-31JapaneseDate
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 JapaneseDate 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-366JapaneseDate
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 JapaneseDate 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 negativeJapaneseDate
based on this date with the years added, never nullCalendricalException
- if the result exceeds the supported date rangepublic JapaneseDate 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 negativeJapaneseDate
based on this date with the months added, never nullCalendricalException
- if the result exceeds the supported date rangepublic JapaneseDate 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 negativeJapaneseDate
based on this date with the weeks added, never nullCalendricalException
- if the result exceeds the supported date rangepublic JapaneseDate 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 negativeJapaneseDate
based on this date with the days added, never nullCalendricalException
- if the result exceeds the supported date rangepublic JapaneseDate 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 negativeJapaneseDate
based on this date with the years subtracted, never nullCalendricalException
- if the result exceeds the supported date rangepublic JapaneseDate 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 negativeJapaneseDate
based on this date with the months subtracted, never nullCalendricalException
- if the result exceeds the supported date rangepublic JapaneseDate 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 negativeJapaneseDate
based on this date with the weeks subtracted, never nullCalendricalException
- if the result exceeds the supported date rangepublic JapaneseDate 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 negativeJapaneseDate
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(JapaneseDate other)
The comparison is based on the time-line position of the dates.
compareTo
in interface java.lang.Comparable<JapaneseDate>
other
- the other date to compare to, not nullpublic boolean isAfter(JapaneseDate other)
The comparison is based on the time-line position of the dates.
other
- the other date to compare to, not nullpublic boolean isBefore(JapaneseDate 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 SHOWA 48-12-01 (Japanese)
.
The output will be in the format Era yy-MM-dd (Japanese)
.
toString
in class java.lang.Object
public static CalendricalRule<JapaneseDate> rule()
JapaneseDate
.