Class AccountingChronology

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

    public final class AccountingChronology
    extends java.time.chrono.AbstractChronology
    implements java.io.Serializable
    An Accounting calendar system.

    This chronology defines the rules of a proleptic 52/53-week Accounting calendar system. This calendar system follows the rules as laid down in IRS Publication 538 and the International Financial Reporting Standards. The start of the Accounting calendar will vary against the ISO calendar. Depending on options chosen, it can start as early as 0000-01-26 (ISO) or as late as 0001-01-04 (ISO).

    This class is proleptic. It implements Accounting chronology rules for 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 12 or 13 months (periods) in an Accounting year, numbered from 1 to 12 or 13.
    • day-of-month - There are 28 or 35 days in each Accounting month, numbered from 1 to 35. Month length depends on how the year has been divided. When the Accounting leap year occurs, a week (7 days) is added to a specific month; this increases to maximum day-of-month numbering to 35 or 42.
    • day-of-year - There are 364 days in a standard Accounting year and 371 in a leap year. The days are numbered from 1 to 364 or 1 to 371.
    • leap-year - Leap years usually occur every 5 or 6 years. Timing depends on settings chosen.

    Implementation Requirements

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

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      AccountingDate date​(int prolepticYear, int month, int dayOfMonth)
      Obtains a local date in Accounting calendar system from the proleptic-year, month-of-year and day-of-month fields.
      AccountingDate date​(java.time.chrono.Era era, int yearOfEra, int month, int dayOfMonth)
      Obtains a local date in Accounting calendar system from the era, year-of-era, month-of-year and day-of-month fields.
      AccountingDate date​(java.time.temporal.TemporalAccessor temporal)
      Obtains a Accounting local date from another date-time object.
      AccountingDate dateEpochDay​(long epochDay)
      Obtains a local date in the Accounting calendar system from the epoch-day.
      AccountingDate dateNow()
      Obtains the current Accounting local date from the system clock in the default time-zone.
      AccountingDate dateNow​(java.time.Clock clock)
      Obtains the current Accounting local date from the specified clock.
      AccountingDate dateNow​(java.time.ZoneId zone)
      Obtains the current Accounting local date from the system clock in the specified time-zone.
      AccountingDate dateYearDay​(int prolepticYear, int dayOfYear)
      Obtains a local date in Accounting calendar system from the proleptic-year and day-of-year fields.
      AccountingDate dateYearDay​(java.time.chrono.Era era, int yearOfEra, int dayOfYear)
      Obtains a local date in Accounting calendar system from the era, year-of-era and day-of-year fields.
      boolean equals​(java.lang.Object obj)  
      AccountingEra eraOf​(int era)  
      java.util.List<java.time.chrono.Era> eras()  
      java.lang.String getCalendarType()
      Gets the calendar type of the underlying calendar system, which is null.
      java.lang.String getId()
      Gets the ID of the chronology - 'Accounting'.
      int hashCode()  
      boolean isLeapYear​(long prolepticYear)
      Checks if the specified year is a leap year.
      java.time.chrono.ChronoLocalDateTime<AccountingDate> localDateTime​(java.time.temporal.TemporalAccessor temporal)
      Obtains a Accounting 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)  
      java.lang.String toString()  
      java.time.chrono.ChronoZonedDateTime<AccountingDate> zonedDateTime​(java.time.Instant instant, java.time.ZoneId zone)
      Obtains a Accounting zoned date-time in this chronology from an Instant.
      java.time.chrono.ChronoZonedDateTime<AccountingDate> zonedDateTime​(java.time.temporal.TemporalAccessor temporal)
      Obtains a Accounting zoned date-time from another date-time object.
      • Methods inherited from class java.time.chrono.AbstractChronology

        compareTo, resolveDate
      • 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
    • Method Detail

      • getId

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

        The ID uniquely identifies the Chronology, but does not differentiate between instances of AccountingChronology. It cannot be used to lookup the Chronology using Chronology.of(String), because each instance requires setup.

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

        public java.lang.String getCalendarType()
        Gets the calendar type of the underlying calendar system, which is null.

        The Unicode Locale Data Markup Language (LDML) specification does not define an identifier for 52/53 week calendars used for accounting purposes, and given that setup required is unlikely to do so. For this reason, the calendar type is null.

        Specified by:
        getCalendarType in interface java.time.chrono.Chronology
        Returns:
        null, as the calendar is unlikely to be specified in LDML
        See Also:
        getId()
      • date

        public AccountingDate date​(java.time.chrono.Era era,
                                   int yearOfEra,
                                   int month,
                                   int dayOfMonth)
        Obtains a local date in Accounting 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 Accounting era, not null
        yearOfEra - the year-of-era
        month - the month-of-year
        dayOfMonth - the day-of-month
        Returns:
        the Accounting local date, not null
        Throws:
        java.time.DateTimeException - if unable to create the date
        java.lang.ClassCastException - if the era is not a AccountingEra
      • date

        public AccountingDate date​(int prolepticYear,
                                   int month,
                                   int dayOfMonth)
        Obtains a local date in Accounting 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 Accounting local date, not null
        Throws:
        java.time.DateTimeException - if unable to create the date
      • dateYearDay

        public AccountingDate dateYearDay​(java.time.chrono.Era era,
                                          int yearOfEra,
                                          int dayOfYear)
        Obtains a local date in Accounting 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 Accounting era, not null
        yearOfEra - the year-of-era
        dayOfYear - the day-of-year
        Returns:
        the Accounting local date, not null
        Throws:
        java.time.DateTimeException - if unable to create the date
        java.lang.ClassCastException - if the era is not a AccountingEra
      • dateYearDay

        public AccountingDate dateYearDay​(int prolepticYear,
                                          int dayOfYear)
        Obtains a local date in Accounting 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 Accounting local date, not null
        Throws:
        java.time.DateTimeException - if unable to create the date
      • dateEpochDay

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

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

        public AccountingDate dateNow​(java.time.ZoneId zone)
        Obtains the current Accounting 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 Accounting local date using the system clock, not null
        Throws:
        java.time.DateTimeException - if unable to create the date
      • dateNow

        public AccountingDate dateNow​(java.time.Clock clock)
        Obtains the current Accounting 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 Accounting local date, not null
        Throws:
        java.time.DateTimeException - if unable to create the date
      • date

        public AccountingDate date​(java.time.temporal.TemporalAccessor temporal)
        Obtains a Accounting 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 Accounting local date, not null
        Throws:
        java.time.DateTimeException - if unable to create the date
      • localDateTime

        public java.time.chrono.ChronoLocalDateTime<AccountingDate> localDateTime​(java.time.temporal.TemporalAccessor temporal)
        Obtains a Accounting 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 Accounting local date-time, not null
        Throws:
        java.time.DateTimeException - if unable to create the date-time
      • zonedDateTime

        public java.time.chrono.ChronoZonedDateTime<AccountingDate> zonedDateTime​(java.time.temporal.TemporalAccessor temporal)
        Obtains a Accounting 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 Accounting zoned date-time, not null
        Throws:
        java.time.DateTimeException - if unable to create the date-time
      • zonedDateTime

        public java.time.chrono.ChronoZonedDateTime<AccountingDate> zonedDateTime​(java.time.Instant instant,
                                                                                  java.time.ZoneId zone)
        Obtains a Accounting 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 Accounting 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.

        An Accounting proleptic-year is leap if the time between the end of the previous year and the end of the current year is 371 days. This method does not validate the year passed in, and only has a well-defined result for years in the supported range.

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

        public boolean equals​(java.lang.Object obj)
        Specified by:
        equals in interface java.time.chrono.Chronology
        Overrides:
        equals in class java.time.chrono.AbstractChronology
      • hashCode

        public int hashCode()
        Specified by:
        hashCode in interface java.time.chrono.Chronology
        Overrides:
        hashCode in class java.time.chrono.AbstractChronology
      • toString

        public java.lang.String toString()
        Specified by:
        toString in interface java.time.chrono.Chronology
        Overrides:
        toString in class java.time.chrono.AbstractChronology