Class CopticDate

    • Field Detail

      • 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 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
      • 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
      • 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