Class CopticDate
- java.lang.Object
-
- javax.time.i18n.CopticDate
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<CopticDate>
,Calendrical
,DateProvider
public final class CopticDate extends java.lang.Object implements DateProvider, Calendrical, java.lang.Comparable<CopticDate>, java.io.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.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
CopticDate.Rule
Rule implementation.
-
Field Summary
Fields Modifier and Type Field Description private int
day
The Coptic day.private int
epochDays
The Coptic epoch day count, 0001-01-01 = 0.private static int
MAX_EPOCH_DAY
The maximum epoch day that is valid.static int
MAX_YEAR
The maximum valid year.private static int
MIN_EPOCH_DAY
The minimum epoch day that is valid.static int
MIN_YEAR
The minimum valid year.private static int
MJD_TO_COPTIC
The number of days to add to MJD to get the Coptic epoch day.private int
month
The Coptic month.private static long
serialVersionUID
A serialization identifier for this class.private int
year
The Coptic year.
-
Constructor Summary
Constructors Modifier Constructor Description private
CopticDate(int epochDays, int year, int month, int day)
Constructs an instance with the specified date.
-
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.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
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.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.private java.lang.Object
readResolve()
Replaces the date instance from the stream with a valid one.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.java.lang.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
-
serialVersionUID
private static final long serialVersionUID
A serialization identifier for this class.- See Also:
- Constant Field Values
-
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
-
MJD_TO_COPTIC
private static final int MJD_TO_COPTIC
The number of days to add to MJD to get the Coptic epoch day.- See Also:
- Constant Field Values
-
MIN_EPOCH_DAY
private static final int MIN_EPOCH_DAY
The minimum epoch day that is valid. The avoidance of negatives makes calculation easier.- See Also:
- Constant Field Values
-
MAX_EPOCH_DAY
private static final int MAX_EPOCH_DAY
The maximum epoch day that is valid. The low maximum year means that overflows don't happen.- See Also:
- Constant Field Values
-
epochDays
private final int epochDays
The Coptic epoch day count, 0001-01-01 = 0.
-
year
private final transient int year
The Coptic year.
-
month
private final transient int month
The Coptic month.
-
day
private final transient int day
The Coptic day.
-
-
Constructor Detail
-
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 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
-
copticDatePreviousValid
private static CopticDate copticDatePreviousValid(int year, int monthOfYear, int dayOfMonth)
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
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
-
copticDateFromEpochDays
private static CopticDate copticDateFromEpochDays(int epochDays)
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
private java.lang.Object readResolve()
Replaces the date instance from the stream with a valid one.- Returns:
- the resolved date, never null
-
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 interfacejava.lang.Comparable<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(java.lang.Object other)
Checks if this date is equal to the specified date.The comparison is based on the time-line position of the dates.
- Overrides:
equals
in classjava.lang.Object
- Parameters:
other
- the other date to compare to, null returns false- Returns:
- true if this is equal to the specified date
-
hashCode
public int hashCode()
A hash code for this date.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- a suitable hash code
-
toString
public java.lang.String toString()
Outputs this date as aString
, such as1723-13-01 (Coptic)
.The output will be in the format
yyyy-MM-dd (Coptic)
.- Overrides:
toString
in classjava.lang.Object
- Returns:
- the formatted date, never null
-
rule
public static CalendricalRule<CopticDate> rule()
Gets the rule forCopticDate
.- Returns:
- the rule for the date, never null
-
-