public final class HistoricDate extends Object implements DateProvider, Calendrical, Comparable<HistoricDate>, Serializable
HistoricDate is an immutable class that represents a date in the Historic calendar system.
The rules of the calendar system are described in HistoricChronology
.
The date has a precision of one day and a range within the era from
year 1 to year 999,999,999 (inclusive).
Instances of this class may be created from any other object that implements
DateProvider
including LocalDate
. Similarly, instances of
this class may be passed into the factory method of any other implementation
of DateProvider
.
HistoricDate is immutable and thread-safe.
Modifier and Type | Field and Description |
---|---|
static int |
MAX_YEAR
The maximum valid year of era.
|
static LocalDate |
STANDARD_CUTOVER
The standard cutover date between the Julian and Gregorian calendar system of 1582-10-15.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(HistoricDate otherDate)
Compares this date to the specified date.
|
boolean |
equals(Object otherDate)
Checks is this date is equal to the specified date.
|
<T> T |
get(CalendricalRule<T> rule)
Gets the value of the specified calendar field.
|
HistoricChronology |
getChronology()
Gets the chronology that this date uses, which is the historic calendar system.
|
int |
getDayOfMonth()
Gets the historic day-of-month value.
|
DayOfWeek |
getDayOfWeek()
Gets the historic day-of-week.
|
int |
getDayOfYear()
Gets the historic day-of-year value.
|
HistoricEra |
getEra()
Gets the historic era.
|
MonthOfYear |
getMonthOfYear()
Gets the historic month-of-year value.
|
int |
getYear()
Gets the historic year value, which can be negative.
|
int |
getYearOfEra()
Gets the historic year-of-era value.
|
int |
hashCode()
A hash code for this date.
|
boolean |
isAfter(HistoricDate otherDate)
Checks is this date is after the specified date.
|
boolean |
isBefore(HistoricDate otherDate)
Checks is this date is before the specified date.
|
boolean |
isLeapYear()
Checks if the date represented is a leap year.
|
static HistoricDate |
of(Calendrical calendrical)
Obtains an instance of
HistoricDate from a calendrical. |
static HistoricDate |
of(int historicYear,
MonthOfYear monthOfYear,
int dayOfMonth)
Obtains an instance of
LocalDate from a year, month and day
using the standard cutover of 1582-10-15. |
static HistoricDate |
of(LocalDate cutover,
int historicYear,
MonthOfYear monthOfYear,
int dayOfMonth)
Obtains an instance of
LocalDate from a year, month and day
specifying the cutover date to use. |
HistoricDate |
plusDays(int days)
Returns a copy of this date with the specified number of days added.
|
HistoricDate |
plusMonths(int months)
Returns a copy of this date with the specified number of months added.
|
HistoricDate |
plusYears(int years)
Returns a copy of this date with the specified number of years added.
|
static CalendricalRule<HistoricDate> |
rule()
Gets the field rule for
HistoricDate . |
LocalDate |
toLocalDate()
Converts this date to an ISO-8601 calendar system
LocalDate . |
String |
toString()
Outputs the date as a
String , such as '1723-13-01 (Historic 2010-10-15)'. |
HistoricDate |
withDayOfMonth(int dayOfMonth)
Returns a copy of this date with the day-of-month value altered.
|
HistoricDate |
withDayOfYear(int dayOfYear)
Returns a copy of this date with the day-of-year value altered.
|
HistoricDate |
withMonthOfYear(MonthOfYear monthOfYear)
Returns a copy of this date with the month-of-year value altered.
|
HistoricDate |
withYear(int historicYear)
Returns a copy of this date with the year value altered.
|
public static final LocalDate STANDARD_CUTOVER
public static final int MAX_YEAR
public static HistoricDate of(int historicYear, MonthOfYear monthOfYear, int dayOfMonth)
LocalDate
from a year, month and day
using the standard cutover of 1582-10-15.
The day must be valid for the year and month or an exception will be thrown.
historicYear
- the year to represent, from -(MAX_YEAR-1) to MAX_YEARmonthOfYear
- 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 HistoricDate of(LocalDate cutover, int historicYear, MonthOfYear monthOfYear, int dayOfMonth)
LocalDate
from a year, month and day
specifying the cutover date to use.
The day must be valid for the year and month or an exception will be thrown.
historicYear
- the year to represent, from -(MAX_YEAR-1) to MAX_YEARmonthOfYear
- 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 HistoricDate of(Calendrical calendrical)
HistoricDate
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 nullUnsupportedRuleException
- if the day-of-week cannot be obtainedpublic HistoricChronology getChronology()
public <T> T get(CalendricalRule<T> rule)
This method queries the value of the specified calendar field. If the calendar field is not supported then an exception is thrown.
get
in interface Calendrical
rule
- the field to query, not nullUnsupportedRuleException
- if no value for the field is foundpublic HistoricEra getEra()
The era provides a context for the year-of-era. This calendar system defines two eras, BCE and CE.
public int getYearOfEra()
The year-of-era is a value that matches the historic definition. Thus, both 1 AD and 1 BCE are represented as year-of-era 1.
public int getYear()
The year is value that is continuous. Thus, 1 AD is represented as year 1, and 1 BCE is represented as year 0.
public MonthOfYear getMonthOfYear()
public int getDayOfMonth()
public int getDayOfYear()
public DayOfWeek getDayOfWeek()
public boolean isLeapYear()
public HistoricDate withYear(int historicYear)
The result of setting the year may leave the day-of-month invalid. To avoid this, the day-of-month is changed to the largest valid value.
This instance is immutable and unaffected by this method call.
historicYear
- the year to represent, from MIN_YEAR to MAX_YEARHistoricDate
based on this date with the specified year, never nullIllegalCalendarFieldValueException
- if the year is out of rangepublic HistoricDate withMonthOfYear(MonthOfYear monthOfYear)
The result of setting the month may leave the day-of-month invalid. To avoid this, the day-of-month is changed to the largest valid value.
This instance is immutable and unaffected by this method call.
monthOfYear
- the month-of-year to represent, from 1 to 12HistoricDate
based on this date with the specified month, never nullpublic HistoricDate withDayOfMonth(int dayOfMonth)
The specified day-of-month must be valid for the month and year.
This instance is immutable and unaffected by this method call.
dayOfMonth
- the day-of-month to represent, from 1 to 31HistoricDate
based on this date with the specified day, never nullIllegalCalendarFieldValueException
- if the day is out of rangeInvalidCalendarFieldException
- if the day-of-month is invalid for the year and monthpublic HistoricDate withDayOfYear(int dayOfYear)
This instance is immutable and unaffected by this method call.
dayOfYear
- the day-of-year to represent, from 1 to 366HistoricDate
based on this date with the specified day, never nullIllegalCalendarFieldValueException
- if the day-of-year is out of rangeInvalidCalendarFieldException
- if the day-of-year is invalid for the yearpublic HistoricDate plusYears(int years)
The result of changing the year may leave the day-of-month invalid. To avoid this, the day-of-month is changed to the largest valid value.
This instance is immutable and unaffected by this method call.
years
- the years to add, positive or negativeHistoricDate
based on this date with the specified years added, never nullIllegalCalendarFieldValueException
- if the year range is exceededpublic HistoricDate plusMonths(int months)
The result of changing the month may leave the day-of-month invalid. To avoid this, the day-of-month is changed to the largest valid value.
This instance is immutable and unaffected by this method call.
months
- the months to add, positive or negativeHistoricDate
based on this date with the specified months added, never nullIllegalCalendarFieldValueException
- if the year range is exceededpublic HistoricDate plusDays(int days)
This instance is immutable and unaffected by this method call.
days
- the days to add, positive or negativeHistoricDate
based on this date with the specified days added, never nullIllegalCalendarFieldValueException
- if the year range is exceededpublic LocalDate toLocalDate()
LocalDate
.toLocalDate
in interface DateProvider
public int compareTo(HistoricDate otherDate)
The comparison is based on the year, month, day and cutover date.
compareTo
in interface Comparable<HistoricDate>
otherDate
- the other date instance to compare to, not nullpublic boolean isAfter(HistoricDate otherDate)
The comparison is based on the year, month, day and cutover date.
otherDate
- the other date instance to compare to, not nullpublic boolean isBefore(HistoricDate otherDate)
The comparison is based on the year, month, day and cutover date.
otherDate
- the other date instance to compare to, not nullpublic boolean equals(Object otherDate)
The comparison is based on the year, month, day and cutover date.
public int hashCode()
public String toString()
String
, such as '1723-13-01 (Historic 2010-10-15)'.
The output will be in the format 'yyyy-MM-dd (Historic 2010-10-15)' where 2010-10-15 is the cutover date.
public static CalendricalRule<HistoricDate> rule()
HistoricDate
.Copyright © 2014. All rights reserved.