Class DiscordianChronology

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<java.time.chrono.Chronology>, java.time.chrono.Chronology

    public final class DiscordianChronology
    extends java.time.chrono.AbstractChronology
    implements java.io.Serializable
    The Discordian calendar system.

    This chronology defines the rules of the proleptic Discordian calendar system. The Discordian differs from the Gregorian in terms of month and week lengths, with an offset year. Dates are aligned such that each Discordian year starts with each ISO year, with an offset index.

    This class is not proleptic. It implements Discordian rules only since YOLD 1 (ISO BCE 1166).

    The fields are defined as follows:

    • era - There is one era, the current 'Year of Our Lady of Discord' (YOLD).
    • year-of-era - The year-of-era for the current era increases uniformly from the epoch at year one.
    • proleptic-year - The proleptic year is the same as the year-of-era for the current era.
    • month-of-year - There are 5 months in a Discordian year, numbered from 1 to 5.
    • day-of-week - There are 5 days in a Discordian week, numbered from 1 to 5.
    • day-of-month - There are 73 days in each Discordian month, numbered from 1 to 73.
    • day-of-year - There are 365 days in a standard Discordian year and 366 in a leap year. The days are numbered from 1 to 365 or 1 to 366.
    • leap-year - Leap years occur in sync with ISO leap-years; that is, they occur every 4 ISO years, excepting when that ISO year is divisible by 100 but not 400.
    • St. Tib's Day - St. Tib's Day occurs each leap-year, and is inserted between the 59th and 60th day of the first month. St. Tib's Day is not part of any month, nor is it part of the Discordian week. It is aligned with the ISO calendar leap-day (February 29th).

    Implementation Requirements

    This class is immutable and thread-safe.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static DiscordianChronology INSTANCE
      Singleton instance for the Discordian chronology.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      DiscordianDate date​(int prolepticYear, int month, int dayOfMonth)
      Obtains a local date in Discordian calendar system from the proleptic-year, month-of-year and day-of-month fields.
      DiscordianDate date​(java.time.chrono.Era era, int yearOfEra, int month, int dayOfMonth)
      Obtains a local date in Discordian calendar system from the era, year-of-era, month-of-year and day-of-month fields.
      DiscordianDate date​(java.time.temporal.TemporalAccessor temporal)
      Obtains a Discordian local date from another date-time object.
      DiscordianDate dateEpochDay​(long epochDay)
      Obtains a local date in the Discordian calendar system from the epoch-day.
      DiscordianDate dateNow()
      Obtains the current Discordian local date from the system clock in the default time-zone.
      DiscordianDate dateNow​(java.time.Clock clock)
      Obtains the current Discordian local date from the specified clock.
      DiscordianDate dateNow​(java.time.ZoneId zone)
      Obtains the current Discordian local date from the system clock in the specified time-zone.
      DiscordianDate dateYearDay​(int prolepticYear, int dayOfYear)
      Obtains a local date in the Discordian calendar system from the proleptic-year and day-of-year fields.
      DiscordianDate dateYearDay​(java.time.chrono.Era era, int yearOfEra, int dayOfYear)
      Obtains a local date in Discordian calendar system from the era, year-of-era and day-of-year fields.
      DiscordianEra eraOf​(int era)  
      java.util.List<java.time.chrono.Era> eras()  
      java.lang.String getCalendarType()
      Gets the calendar type of the underlying calendar system - 'discordian'.
      java.lang.String getId()
      Gets the ID of the chronology - 'Discordian'.
      boolean isLeapYear​(long prolepticYear)
      Checks if the specified year is a leap year.
      java.time.chrono.ChronoLocalDateTime<DiscordianDate> localDateTime​(java.time.temporal.TemporalAccessor temporal)
      Obtains a Discordian local date-time from another date-time object.
      int prolepticYear​(java.time.chrono.Era era, int yearOfEra)  
      java.time.temporal.ValueRange range​(java.time.temporal.ChronoField field)  
      DiscordianDate resolveDate​(java.util.Map<java.time.temporal.TemporalField,​java.lang.Long> fieldValues, java.time.format.ResolverStyle resolverStyle)  
      java.time.chrono.ChronoZonedDateTime<DiscordianDate> zonedDateTime​(java.time.Instant instant, java.time.ZoneId zone)
      Obtains a Discordian zoned date-time in this chronology from an Instant.
      java.time.chrono.ChronoZonedDateTime<DiscordianDate> zonedDateTime​(java.time.temporal.TemporalAccessor temporal)
      Obtains a Discordian zoned date-time from another date-time object.
      • Methods inherited from class java.time.chrono.AbstractChronology

        compareTo, equals, hashCode, toString
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.time.chrono.Chronology

        epochSecond, epochSecond, getDisplayName, period
    • Field Detail

      • INSTANCE

        public static final DiscordianChronology INSTANCE
        Singleton instance for the Discordian chronology.
    • Constructor Detail

      • DiscordianChronology

        @Deprecated
        public DiscordianChronology()
        Deprecated.
        Use the singleton INSTANCE instead.
        Private constructor, that is public to satisfy the ServiceLoader.
    • Method Detail

      • getId

        public java.lang.String getId()
        Gets the ID of the chronology - 'Discordian'.

        The ID uniquely identifies the Chronology. It can be used to lookup the Chronology using Chronology.of(String).

        Specified by:
        getId in interface java.time.chrono.Chronology
        Returns:
        the chronology ID - 'Discordian'
        See Also:
        getCalendarType()
      • getCalendarType

        public java.lang.String getCalendarType()
        Gets the calendar type of the underlying calendar system - 'discordian'.

        The Unicode Locale Data Markup Language (LDML) specification does not define an identifier for the Discordian calendar, but were it to do so, 'discordian' is highly likely to be chosen.

        Specified by:
        getCalendarType in interface java.time.chrono.Chronology
        Returns:
        the calendar system type - 'discordian'
        See Also:
        getId()
      • date

        public DiscordianDate date​(java.time.chrono.Era era,
                                   int yearOfEra,
                                   int month,
                                   int dayOfMonth)
        Obtains a local date in Discordian calendar system from the era, year-of-era, month-of-year and day-of-month fields.
        Specified by:
        date in interface java.time.chrono.Chronology
        Parameters:
        era - the Discordian era, not null
        yearOfEra - the year-of-era
        month - the month-of-year
        dayOfMonth - the day-of-month
        Returns:
        the Discordian local date, not null
        Throws:
        java.time.DateTimeException - if unable to create the date
        java.lang.ClassCastException - if the era is not a DiscordianEra
      • date

        public DiscordianDate date​(int prolepticYear,
                                   int month,
                                   int dayOfMonth)
        Obtains a local date in Discordian calendar system from the proleptic-year, month-of-year and day-of-month fields.
        Specified by:
        date in interface java.time.chrono.Chronology
        Parameters:
        prolepticYear - the proleptic-year
        month - the month-of-year
        dayOfMonth - the day-of-month
        Returns:
        the Discordian local date, not null
        Throws:
        java.time.DateTimeException - if unable to create the date
      • dateYearDay

        public DiscordianDate dateYearDay​(java.time.chrono.Era era,
                                          int yearOfEra,
                                          int dayOfYear)
        Obtains a local date in Discordian calendar system from the era, year-of-era and day-of-year fields.
        Specified by:
        dateYearDay in interface java.time.chrono.Chronology
        Parameters:
        era - the Discordian era, not null
        yearOfEra - the year-of-era
        dayOfYear - the day-of-year
        Returns:
        the Discordian local date, not null
        Throws:
        java.time.DateTimeException - if unable to create the date
        java.lang.ClassCastException - if the era is not a DiscordianEra
      • dateYearDay

        public DiscordianDate dateYearDay​(int prolepticYear,
                                          int dayOfYear)
        Obtains a local date in the Discordian calendar system from the proleptic-year and day-of-year fields.
        Specified by:
        dateYearDay in interface java.time.chrono.Chronology
        Parameters:
        prolepticYear - the proleptic-year
        dayOfYear - the day-of-year
        Returns:
        the Discordian local date, not null
        Throws:
        java.time.DateTimeException - if unable to create the date
      • dateEpochDay

        public DiscordianDate dateEpochDay​(long epochDay)
        Obtains a local date in the Discordian calendar system from the epoch-day.
        Specified by:
        dateEpochDay in interface java.time.chrono.Chronology
        Parameters:
        epochDay - the epoch day
        Returns:
        the Discordian local date, not null
        Throws:
        java.time.DateTimeException - if unable to create the date
      • dateNow

        public DiscordianDate dateNow()
        Obtains the current Discordian local date from the system clock in the default time-zone.

        This will query the system clock in the default time-zone to obtain the current date.

        Using this method will prevent the ability to use an alternate clock for testing because the clock is hard-coded.

        Specified by:
        dateNow in interface java.time.chrono.Chronology
        Returns:
        the current Discordian local date using the system clock and default time-zone, not null
        Throws:
        java.time.DateTimeException - if unable to create the date
      • dateNow

        public DiscordianDate dateNow​(java.time.ZoneId zone)
        Obtains the current Discordian local date from the system clock in the specified time-zone.

        This will query the system clock to obtain the current date. Specifying the time-zone avoids dependence on the default time-zone.

        Using this method will prevent the ability to use an alternate clock for testing because the clock is hard-coded.

        Specified by:
        dateNow in interface java.time.chrono.Chronology
        Parameters:
        zone - the zone ID to use, not null
        Returns:
        the current Discordian local date using the system clock, not null
        Throws:
        java.time.DateTimeException - if unable to create the date
      • dateNow

        public DiscordianDate dateNow​(java.time.Clock clock)
        Obtains the current Discordian local date from the specified clock.

        This will query the specified clock to obtain the current date - today. Using this method allows the use of an alternate clock for testing. The alternate clock may be introduced using dependency injection.

        Specified by:
        dateNow in interface java.time.chrono.Chronology
        Parameters:
        clock - the clock to use, not null
        Returns:
        the current Discordian local date, not null
        Throws:
        java.time.DateTimeException - if unable to create the date
      • date

        public DiscordianDate date​(java.time.temporal.TemporalAccessor temporal)
        Obtains a Discordian local date from another date-time object.
        Specified by:
        date in interface java.time.chrono.Chronology
        Parameters:
        temporal - the date-time object to convert, not null
        Returns:
        the Discordian local date, not null
        Throws:
        java.time.DateTimeException - if unable to create the date
      • localDateTime

        public java.time.chrono.ChronoLocalDateTime<DiscordianDate> localDateTime​(java.time.temporal.TemporalAccessor temporal)
        Obtains a Discordian local date-time from another date-time object.
        Specified by:
        localDateTime in interface java.time.chrono.Chronology
        Parameters:
        temporal - the date-time object to convert, not null
        Returns:
        the Discordian local date-time, not null
        Throws:
        java.time.DateTimeException - if unable to create the date-time
      • zonedDateTime

        public java.time.chrono.ChronoZonedDateTime<DiscordianDate> zonedDateTime​(java.time.temporal.TemporalAccessor temporal)
        Obtains a Discordian zoned date-time from another date-time object.
        Specified by:
        zonedDateTime in interface java.time.chrono.Chronology
        Parameters:
        temporal - the date-time object to convert, not null
        Returns:
        the Discordian zoned date-time, not null
        Throws:
        java.time.DateTimeException - if unable to create the date-time
      • zonedDateTime

        public java.time.chrono.ChronoZonedDateTime<DiscordianDate> zonedDateTime​(java.time.Instant instant,
                                                                                  java.time.ZoneId zone)
        Obtains a Discordian zoned date-time in this chronology from an Instant.
        Specified by:
        zonedDateTime in interface java.time.chrono.Chronology
        Parameters:
        instant - the instant to create the date-time from, not null
        zone - the time-zone, not null
        Returns:
        the Discordian zoned date-time, not null
        Throws:
        java.time.DateTimeException - if the result exceeds the supported range
      • isLeapYear

        public boolean isLeapYear​(long prolepticYear)
        Checks if the specified year is a leap year.

        A Discordian proleptic-year is leap if the remainder after division by four equals zero. There are two special cases. If the year minus 1166 is divisible by 100 it is not a leap year, unless it is also divisible by 400, when it is a leap year. These rules produce leap days on the same dates as the ISO-8601 calendar system.

        Specified by:
        isLeapYear in interface java.time.chrono.Chronology
        Parameters:
        prolepticYear - the proleptic-year to check, not validated for range
        Returns:
        true if the year is a leap year
      • prolepticYear

        public int prolepticYear​(java.time.chrono.Era era,
                                 int yearOfEra)
        Specified by:
        prolepticYear in interface java.time.chrono.Chronology
      • eraOf

        public DiscordianEra eraOf​(int era)
        Specified by:
        eraOf in interface java.time.chrono.Chronology
      • eras

        public java.util.List<java.time.chrono.Era> eras()
        Specified by:
        eras in interface java.time.chrono.Chronology
      • range

        public java.time.temporal.ValueRange range​(java.time.temporal.ChronoField field)
        Specified by:
        range in interface java.time.chrono.Chronology
      • resolveDate

        public DiscordianDate resolveDate​(java.util.Map<java.time.temporal.TemporalField,​java.lang.Long> fieldValues,
                                          java.time.format.ResolverStyle resolverStyle)
        Specified by:
        resolveDate in interface java.time.chrono.Chronology
        Overrides:
        resolveDate in class java.time.chrono.AbstractChronology