Class CopticDate
- All Implemented Interfaces:
Serializable
,Comparable<CopticDate>
,Calendrical
,DateProvider
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.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final class
Rule implementation. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final int
The Coptic day.private final int
The Coptic epoch day count, 0001-01-01 = 0.private static final int
The maximum epoch day that is valid.static final int
The maximum valid year.private static final int
The minimum epoch day that is valid.static final int
The minimum valid year.private static final int
The number of days to add to MJD to get the Coptic epoch day.private final int
The Coptic month.private static final long
A serialization identifier for this class.private final int
The Coptic year. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
CopticDate
(int epochDays, int year, int month, int day) Constructs an instance with the specified date. -
Method Summary
Modifier and TypeMethodDescriptionint
compareTo
(CopticDate other) Compares this date to another date.private static CopticDate
copticDateFromEpochDays
(int epochDays) Obtains an instance ofCopticDate
from a number of epoch days.private static CopticDate
copticDatePreviousValid
(int year, int monthOfYear, int dayOfMonth) Obtains an instance ofCopticDate
using the previous valid algorithm.boolean
Checks if this date is equal to the specified date.<T> T
get
(CalendricalRule<T> rule) Gets the value of the specified calendrical rule.Gets the chronology that this date uses, which is the Coptic calendar system.int
Gets the Coptic day-of-month field.Gets the day-of-week field, which is an enumDayOfWeek
.int
Gets the Coptic day-of-year field.int
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
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.plusDays
(int days) Returns a copy of this date with the specified number of days added.plusMonths
(int months) Returns a copy of this date with the specified number of months added.plusWeeks
(int weeks) Returns a copy of this date with the specified number of weeks added.plusYears
(int years) Returns a copy of this date with the specified number of years added.private Object
Replaces the date instance from the stream with a valid one.static CalendricalRule
<CopticDate> rule()
Gets the rule forCopticDate
.Converts this date to aLocalDate
, which is the default representation of a date, and provides values in the ISO-8601 calendar system.toString()
Outputs this date as aString
, such as1723-13-01 (Coptic)
.withDayOfMonth
(int dayOfMonth) Returns a copy of this date with the day-of-month altered.withDayOfYear
(int dayOfYear) Returns a copy of this date with the day-of-year altered.withMonthOfYear
(int monthOfYear) Returns a copy of this date with the month-of-year altered.withYear
(int year) Returns a copy of this date with the year altered.
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDA serialization identifier for this class.- See Also:
-
MIN_YEAR
public static final int MIN_YEARThe minimum valid year.- See Also:
-
MAX_YEAR
public static final int MAX_YEARThe 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:
-
MJD_TO_COPTIC
private static final int MJD_TO_COPTICThe number of days to add to MJD to get the Coptic epoch day.- See Also:
-
MIN_EPOCH_DAY
private static final int MIN_EPOCH_DAYThe minimum epoch day that is valid. The avoidance of negatives makes calculation easier.- See Also:
-
MAX_EPOCH_DAY
private static final int MAX_EPOCH_DAYThe maximum epoch day that is valid. The low maximum year means that overflows don't happen.- See Also:
-
epochDays
private final int epochDaysThe Coptic epoch day count, 0001-01-01 = 0. -
year
private final transient int yearThe Coptic year. -
month
private final transient int monthThe Coptic month. -
day
private final transient int dayThe Coptic day.
-
-
Constructor Details
-
CopticDate
private CopticDate(int epochDays, int year, int month, int day) Constructs an instance with the specified date.- Parameters:
epochDays
- the Coptic epoch days, caller checked to be one or greateryear
- the year to represent, caller calculatedmonth
- the month-of-year to represent, caller calculatedday
- the day-of-month to represent, caller calculated
-
-
Method Details
-
of
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
-
copticDatePreviousValid
Obtains an instance ofCopticDate
using the previous valid algorithm.- Parameters:
year
- the year to representmonthOfYear
- the month-of-year to representdayOfMonth
- the day-of-month to represent- Returns:
- the Coptic date, never null
-
of
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
-
copticDateFromEpochDays
Obtains an instance ofCopticDate
from a number of epoch days.- Parameters:
epochDays
- the epoch days to use, not null- Returns:
- a CopticDate object, never null
- Throws:
IllegalCalendarFieldValueException
- if the year range is exceeded
-
readResolve
Replaces the date instance from the stream with a valid one.- Returns:
- the resolved date, never null
-
getChronology
Gets the chronology that this date uses, which is the Coptic calendar system.- Returns:
- the Coptic chronology, never null
-
get
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Outputs this date as aString
, such as1723-13-01 (Coptic)
.The output will be in the format
yyyy-MM-dd (Coptic)
. -
rule
Gets the rule forCopticDate
.- Returns:
- the rule for the date, never null
-