Class CopticDate
- java.lang.Object
-
- javax.time.i18n.CopticDate
-
- All Implemented Interfaces:
Serializable
,Comparable<CopticDate>
,Calendrical
,DateProvider
public final class CopticDate extends Object implements DateProvider, Calendrical, Comparable<CopticDate>, Serializable
A date in the Coptic calendar system.CopticDate
is an immutable class that represents a date in the Coptic calendar system. The rules of the calendar system are described inCopticChronology
.Instances of this class may be created from other date objects that implement
Calendrical
. Notably this includesLocalDate
and all other date classes from other calendar systems.CopticDate is immutable and thread-safe.
- Author:
- Michael Nascimento Santos, Stephen Colebourne
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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 enumDayOfWeek
.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(int copticYear, int copticMonthOfYear, int copticDayOfMonth)
Obtains an instance ofCopticDate
from the Coptic year, month-of-year and day-of-month.static CopticDate
of(Calendrical calendrical)
Obtains an instance ofCopticDate
from a calendrical.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 forCopticDate
.LocalDate
toLocalDate()
Converts this date to aLocalDate
, which is the default representation of a date, and provides values in the ISO-8601 calendar system.String
toString()
Outputs this date as aString
, such as1723-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.
-
-
-
Field Detail
-
MIN_YEAR
public static final int MIN_YEAR
The minimum valid year.- See Also:
- Constant Field Values
-
MAX_YEAR
public static final int MAX_YEAR
The maximum valid year. This is currently set to 9999 but may be changed to increase the valid range in a future version of the specification.- See Also:
- Constant Field Values
-
-
Method Detail
-
of
public static CopticDate of(int copticYear, int copticMonthOfYear, int copticDayOfMonth)
Obtains an instance ofCopticDate
from the Coptic year, month-of-year and day-of-month.- Parameters:
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 30- Returns:
- the Coptic date, never null
- Throws:
IllegalCalendarFieldValueException
- if the value of any field is out of rangeInvalidCalendarFieldException
- if the day-of-month is invalid for the month-year
-
of
public static CopticDate of(Calendrical calendrical)
Obtains an instance ofCopticDate
from a calendrical.This can be used extract the date directly from any implementation of
Calendrical
, including those in other calendar systems.- Parameters:
calendrical
- the calendrical to extract from, not null- Returns:
- the Coptic date, never null
- Throws:
CalendricalException
- if the date cannot be obtained
-
getChronology
public CopticChronology getChronology()
Gets the chronology that this date uses, which is the Coptic calendar system.- Returns:
- the Coptic chronology, never null
-
get
public <T> T get(CalendricalRule<T> rule)
Gets the value of the specified calendrical 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.- Specified by:
get
in interfaceCalendrical
- Parameters:
rule
- the rule to use, not null- Returns:
- the value for the rule, null if the value cannot be returned
-
getYear
public int getYear()
Gets the Coptic year field.- Returns:
- the year, from MIN_YEAR to MAX_YEAR
-
getMonthOfYear
public int getMonthOfYear()
Gets the Coptic month-of-year field.- Returns:
- the month-of-year, from 1 to 13
-
getDayOfMonth
public int getDayOfMonth()
Gets the Coptic day-of-month field.- Returns:
- the day-of-month, from 1 to 30
-
getDayOfYear
public int getDayOfYear()
Gets the Coptic day-of-year field.- Returns:
- the day-of-year, from 1 to 365, or 366 in a leap year
-
getDayOfWeek
public DayOfWeek getDayOfWeek()
Gets the day-of-week field, which is an enumDayOfWeek
.This method returns the enum
DayOfWeek
for the day-of-week. This avoids confusion as to whatint
values mean. If you need access to the primitiveint
value then the enum provides theint value
.Additional information can be obtained from the
DayOfWeek
. This includes textual names of the values.- Returns:
- the day-of-week, never null
-
isLeapYear
public boolean isLeapYear()
Checks if the year is a leap year, according to the Coptic calendar system rules.- Returns:
- true if this date is in a leap year
-
withYear
public CopticDate withYear(int year)
Returns a copy of this date with the year altered.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.
- Parameters:
year
- the year to set in the returned date, from 1 to 9999- Returns:
- a
CopticDate
based on this date with the requested year, never null - Throws:
IllegalCalendarFieldValueException
- if the year value is invalid
-
withMonthOfYear
public CopticDate withMonthOfYear(int monthOfYear)
Returns a copy of this date with the month-of-year altered.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.
- Parameters:
monthOfYear
- the month-of-year to set in the returned date, from 1 to 13- Returns:
- a
CopticDate
based on this date with the requested month, never null - Throws:
IllegalCalendarFieldValueException
- if the month value is invalid
-
withDayOfMonth
public CopticDate withDayOfMonth(int dayOfMonth)
Returns a copy of this date with the day-of-month altered.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.
- Parameters:
dayOfMonth
- the day-of-month to set in the returned date, from 1 to 30- Returns:
- a
CopticDate
based on this date with the requested day, never null - Throws:
IllegalCalendarFieldValueException
- if the day-of-month value is invalidInvalidCalendarFieldException
- if the day-of-month is invalid for the month-year
-
withDayOfYear
public CopticDate withDayOfYear(int dayOfYear)
Returns a copy of this date with the day-of-year altered.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.
- Parameters:
dayOfYear
- the day-of-year to set in the returned date, from 1 to 365-366- Returns:
- a
CopticDate
based on this date with the requested day, never null - Throws:
IllegalCalendarFieldValueException
- if the day-of-year value is invalidInvalidCalendarFieldException
- if the day-of-year is invalid for the year
-
plusYears
public CopticDate plusYears(int years)
Returns a copy of this date with the specified number of years added.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.
- Parameters:
years
- the years to add, may be negative- Returns:
- a
CopticDate
based on this date with the years added, never null - Throws:
CalendricalException
- if the result exceeds the supported date range
-
plusMonths
public CopticDate plusMonths(int months)
Returns a copy of this date with the specified number of months added.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.
- Parameters:
months
- the months to add, may be negative- Returns:
- a
CopticDate
based on this date with the months added, never null - Throws:
CalendricalException
- if the result exceeds the supported date range
-
plusWeeks
public CopticDate plusWeeks(int weeks)
Returns a copy of this date with the specified number of weeks added.This method adds the specified amount in weeks to the date.
This instance is immutable and unaffected by this method call.
- Parameters:
weeks
- the weeks to add, may be negative- Returns:
- a
CopticDate
based on this date with the weeks added, never null - Throws:
CalendricalException
- if the result exceeds the supported date range
-
plusDays
public CopticDate plusDays(int days)
Returns a copy of this date with the specified number of days added.This method adds the specified amount in days to the date.
This instance is immutable and unaffected by this method call.
- Parameters:
days
- the days to add, may be negative- Returns:
- a
CopticDate
based on this date with the days added, never null - Throws:
CalendricalException
- if the result exceeds the supported date range
-
toLocalDate
public LocalDate toLocalDate()
Converts this date to aLocalDate
, which is the default representation of a date, and provides values in the ISO-8601 calendar system.- Specified by:
toLocalDate
in interfaceDateProvider
- Returns:
- the equivalent date in the ISO-8601 calendar system, never null
-
compareTo
public int compareTo(CopticDate other)
Compares this date to another date.The comparison is based on the time-line position of the dates.
- Specified by:
compareTo
in interfaceComparable<CopticDate>
- Parameters:
other
- the other date to compare to, not null- Returns:
- the comparator value, negative if less, positive if greater
-
isAfter
public boolean isAfter(CopticDate other)
Checks if this date is after the specified date.The comparison is based on the time-line position of the dates.
- Parameters:
other
- the other date to compare to, not null- Returns:
- true if this is after the specified date
-
isBefore
public boolean isBefore(CopticDate other)
Checks if this date is before the specified date.The comparison is based on the time-line position of the dates.
- Parameters:
other
- the other date to compare to, not null- Returns:
- true if this is before the specified date
-
equals
public boolean equals(Object other)
Checks if this date is equal to the specified date.The comparison is based on the time-line position of the dates.
-
hashCode
public int hashCode()
A hash code for this date.
-
toString
public String toString()
Outputs this date as aString
, such as1723-13-01 (Coptic)
.The output will be in the format
yyyy-MM-dd (Coptic)
.
-
rule
public static CalendricalRule<CopticDate> rule()
Gets the rule forCopticDate
.- Returns:
- the rule for the date, never null
-
-