public final class CopticDate extends Object implements DateProvider, Calendrical, Comparable<CopticDate>, Serializable
CopticDate
is an immutable class that represents a date in the Coptic calendar system.
The rules of the calendar system are described in CopticChronology
.
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.
CopticDate is immutable and thread-safe.
Modifier and Type | Field and Description |
---|---|
static int |
MAX_YEAR
The maximum valid year.
|
static int |
MIN_YEAR
The minimum valid year.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(CopticDate other)
Compares this date to another date.
|
boolean |
equals(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.
|
CopticChronology |
getChronology()
Gets the chronology that this date uses, which is the Coptic calendar system.
|
int |
getDayOfMonth()
Gets the Coptic day-of-month field.
|
DayOfWeek |
getDayOfWeek()
Gets the day-of-week field, which is an enum
DayOfWeek . |
int |
getDayOfYear()
Gets the Coptic day-of-year field.
|
int |
getMonthOfYear()
Gets the Coptic month-of-year field.
|
int |
getYear()
Gets the Coptic year field.
|
int |
hashCode()
A hash code for this date.
|
boolean |
isAfter(CopticDate other)
Checks if this date is after the specified date.
|
boolean |
isBefore(CopticDate other)
Checks if this date is before the specified date.
|
boolean |
isLeapYear()
Checks if the year is a leap year, according to the Coptic calendar system rules.
|
static CopticDate |
of(Calendrical calendrical)
Obtains an instance of
CopticDate from a calendrical. |
static CopticDate |
of(int copticYear,
int copticMonthOfYear,
int copticDayOfMonth)
Obtains an instance of
CopticDate from the Coptic year,
month-of-year and day-of-month. |
CopticDate |
plusDays(int days)
Returns a copy of this date with the specified number of days added.
|
CopticDate |
plusMonths(int months)
Returns a copy of this date with the specified number of months added.
|
CopticDate |
plusWeeks(int weeks)
Returns a copy of this date with the specified number of weeks added.
|
CopticDate |
plusYears(int years)
Returns a copy of this date with the specified number of years added.
|
static CalendricalRule<CopticDate> |
rule()
Gets the rule for
CopticDate . |
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. |
String |
toString()
Outputs this date as a
String , such as 1723-13-01 (Coptic) . |
CopticDate |
withDayOfMonth(int dayOfMonth)
Returns a copy of this date with the day-of-month altered.
|
CopticDate |
withDayOfYear(int dayOfYear)
Returns a copy of this date with the day-of-year altered.
|
CopticDate |
withMonthOfYear(int monthOfYear)
Returns a copy of this date with the month-of-year altered.
|
CopticDate |
withYear(int year)
Returns a copy of this date with the year altered.
|
public static final int MIN_YEAR
public static final int MAX_YEAR
public static CopticDate of(int copticYear, int copticMonthOfYear, int copticDayOfMonth)
CopticDate
from the Coptic year,
month-of-year and day-of-month.copticYear
- the year to represent, from 1 to 9999copticMonthOfYear
- the month-of-year to represent, from 1 to 13copticDayOfMonth
- the day-of-month to represent, from 1 to 30IllegalCalendarFieldValueException
- if the value of any field is out of rangeInvalidCalendarFieldException
- if the day-of-month is invalid for the month-yearpublic static CopticDate of(Calendrical calendrical)
CopticDate
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 CopticChronology 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 int getYear()
public int 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 CopticDate withYear(int year)
This method changes the year of the date. If this date is the leap day (month 13, day 6) and the new year is not a leap year, the resulting date will be invalid. To avoid this, the result day-of-month is changed from 6 to 5.
This instance is immutable and unaffected by this method call.
year
- the year to set in the returned date, from 1 to 9999CopticDate
based on this date with the requested year, never nullIllegalCalendarFieldValueException
- if the year value is invalidpublic CopticDate withMonthOfYear(int monthOfYear)
This method changes the month-of-year of the date. If this month is from 1 to 12 and the new month is 13 then the resulting date might be invalid. In this case, the last valid day-of-the month will be returned.
This instance is immutable and unaffected by this method call.
monthOfYear
- the month-of-year to set in the returned date, from 1 to 13CopticDate
based on this date with the requested month, never nullIllegalCalendarFieldValueException
- if the month value is invalidpublic CopticDate 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 30CopticDate
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 CopticDate 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-366CopticDate
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 CopticDate 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 negativeCopticDate
based on this date with the years added, never nullCalendricalException
- if the result exceeds the supported date rangepublic CopticDate 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 negativeCopticDate
based on this date with the months added, never nullCalendricalException
- if the result exceeds the supported date rangepublic CopticDate 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 negativeCopticDate
based on this date with the weeks added, never nullCalendricalException
- if the result exceeds the supported date rangepublic CopticDate plusDays(int 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 negativeCopticDate
based on this date with the days added, 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(CopticDate other)
The comparison is based on the time-line position of the dates.
compareTo
in interface Comparable<CopticDate>
other
- the other date to compare to, not nullpublic boolean isAfter(CopticDate other)
The comparison is based on the time-line position of the dates.
other
- the other date to compare to, not nullpublic boolean isBefore(CopticDate other)
The comparison is based on the time-line position of the dates.
other
- the other date to compare to, not nullpublic boolean equals(Object other)
The comparison is based on the time-line position of the dates.
public int hashCode()
public String toString()
String
, such as 1723-13-01 (Coptic)
.
The output will be in the format yyyy-MM-dd (Coptic)
.
public static CalendricalRule<CopticDate> rule()
CopticDate
.Copyright © 2014. All rights reserved.