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 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 Classes
    Modifier and Type
    Class
    Description
    (package private) static final class 
    Rule implementation.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private 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

    Constructors
    Modifier
    Constructor
    Description
    private
    CopticDate(int epochDays, int year, int month, int day)
    Constructs an instance with the specified date.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Compares this date to another date.
    private static CopticDate
    copticDateFromEpochDays(int epochDays)
    Obtains an instance of CopticDate from a number of epoch days.
    private static CopticDate
    copticDatePreviousValid(int year, int monthOfYear, int dayOfMonth)
    Obtains an instance of CopticDate using the previous valid algorithm.
    boolean
    equals(Object other)
    Checks if this date is equal to the specified date.
    <T> T
    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 enum DayOfWeek.
    int
    Gets the Coptic day-of-year field.
    int
    Gets the Coptic month-of-year field.
    int
    Gets the Coptic year field.
    int
    A hash code for this date.
    boolean
    Checks if this date is after the specified date.
    boolean
    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 of CopticDate from the Coptic year, month-of-year and day-of-month.
    static CopticDate
    of(Calendrical calendrical)
    Obtains an instance of CopticDate 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.
    Gets the rule for CopticDate.
    Converts this date to a LocalDate, which is the default representation of a date, and provides values in the ISO-8601 calendar system.
    Outputs this date as a String, such as 1723-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.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      A serialization identifier for this class.
      See Also:
    • MIN_YEAR

      public static final int MIN_YEAR
      The minimum valid year.
      See Also:
    • 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:
    • 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:
    • 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:
    • 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:
    • 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 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 greater
      year - the year to represent, caller calculated
      month - the month-of-year to represent, caller calculated
      day - the day-of-month to represent, caller calculated
  • Method Details

    • of

      public 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.
      Parameters:
      copticYear - the year to represent, from 1 to 9999
      copticMonthOfYear - the month-of-year to represent, from 1 to 13
      copticDayOfMonth - 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 range
      InvalidCalendarFieldException - 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 of CopticDate using the previous valid algorithm.
      Parameters:
      year - the year to represent
      monthOfYear - the month-of-year to represent
      dayOfMonth - the day-of-month to represent
      Returns:
      the Coptic date, never null
    • of

      public static CopticDate of(Calendrical calendrical)
      Obtains an instance of CopticDate 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 of CopticDate 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 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 interface Calendrical
      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 enum 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.

      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 invalid
      InvalidCalendarFieldException - 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 invalid
      InvalidCalendarFieldException - 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 a LocalDate, which is the default representation of a date, and provides values in the ISO-8601 calendar system.
      Specified by:
      toLocalDate in interface DateProvider
      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 interface 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(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 class 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 class Object
      Returns:
      a suitable hash code
    • toString

      public String toString()
      Outputs this date as a String, such as 1723-13-01 (Coptic).

      The output will be in the format yyyy-MM-dd (Coptic).

      Overrides:
      toString in class Object
      Returns:
      the formatted date, never null
    • rule

      public static CalendricalRule<CopticDate> rule()
      Gets the rule for CopticDate.
      Returns:
      the rule for the date, never null