Class PaxChronology

  • All Implemented Interfaces:
    Serializable, Comparable<Chronology>, Chronology

    public final class PaxChronology
    extends AbstractChronology
    implements Serializable
    The Pax calendar system.

    This chronology defines the rules of the proleptic Pax calendar system. This calendar system is a proposed reform calendar system, and is not in common use. The Pax differs from the Gregorian in terms of month count and length, and the leap year rule. Dates are aligned such that 0001-01-01 (Pax) is 0000-12-31 (ISO).

    This class is proleptic. It implements Pax rules to the entire time-line.

    The fields are defined as follows:

    • era - There are two eras, the current 'Current Era' (CE) and the previous era 'Before Current Era' (BCE).
    • year-of-era - The year-of-era for the current era increases uniformly from the epoch at year one. For the previous era the year increases from one as time goes backwards.
    • proleptic-year - The proleptic year is the same as the year-of-era for the current era. For the previous era, years have zero, then negative values.
    • month-of-year - There are 13 or 14 months in a Pax year, numbered from 1 to 13 (or 14).
    • day-of-month - There are 28 days in each Pax month, numbered from 1 to 28. In a leap year a one-week month ('Pax') is inserted between months 12 and 13, shifting 13 to 14.
    • day-of-year - There are 364 days in a standard Pax year and 371 in a leap year. The days are numbered from 1 to 364 or 1 to 371.
    • leap-year - Leap years occur in every year whose last two digits are divisible by 6, are 99, or are 00 and the year is not divisible by 400.

    For more information, please read the Pax Calendar Wikipedia article.

    Implementation Requirements

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

      • INSTANCE

        public static final PaxChronology INSTANCE
        Singleton instance for the Pax chronology.
    • Constructor Detail

      • PaxChronology

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

      • getCalendarType

        public String getCalendarType()
        Gets the calendar type of the underlying calendar system - 'pax'.

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

        Specified by:
        getCalendarType in interface Chronology
        Returns:
        the calendar system type - 'pax'
        See Also:
        getId()
      • date

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

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

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

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

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

        public PaxDate dateNow()
        Obtains the current Pax 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 Chronology
        Returns:
        the current Pax local date using the system clock and default time-zone, not null
        Throws:
        DateTimeException - if unable to create the date
      • dateNow

        public PaxDate dateNow​(ZoneId zone)
        Obtains the current Pax 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 Chronology
        Parameters:
        zone - the ZoneId to use, not null
        Returns:
        the current Pax local date using the system clock, not null
        Throws:
        DateTimeException - if unable to create the date
      • dateNow

        public PaxDate dateNow​(Clock clock)
        Obtains the current Pax 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 Chronology
        Parameters:
        clock - the clock to use, not null
        Returns:
        the current Pax local date, not null
        Throws:
        DateTimeException - if unable to create the date
      • date

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

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

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

        In general, a year is a leap year if the last two digits are divisible by 6 without remainder, or are 99. Years with the last two digits of 00 are also leap years, with the exception of years divisible by 400, which are not.

        For example, 2012 is a leap year because the last two digits (12) are divisible by 6. 1999 is a leap year as the last two digits are both 9's (99). 1900 is a leap year as the last two digits are both 0's (00), however 2000 was not a leap year as it is divisible by 400. The year 0 is not a leap year.

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