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