Class AccountingDate

  • All Implemented Interfaces:
    Serializable, Comparable<ChronoLocalDate>, ChronoLocalDate, Temporal, TemporalAccessor, TemporalAdjuster

    public final class AccountingDate
    extends Object
    implements ChronoLocalDate, Serializable
    A date in an Accounting calendar system.

    This date operates using a given Accounting calendar. An Accounting calendar differs greatly from the ISO calendar. 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).

    Implementation Requirements

    This class is immutable and thread-safe.

    This class must be treated as a value type. Do not synchronize, rely on the identity hash code or use the distinction between equals() and ==.

    See Also:
    Serialized Form
    • Method Detail

      • now

        public static AccountingDate now​(AccountingChronology chronology)
        Obtains the current AccountingDate from the system clock in the default time-zone, translated with the given AccountingChronology.

        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.

        Parameters:
        chronology - the Accounting chronology to base the date on, not null
        Returns:
        the current date using the system clock and default time-zone, not null
        Throws:
        DateTimeException - if the current date cannot be obtained, NullPointerException if an AccountingChronology was not provided
      • now

        public static AccountingDate now​(AccountingChronology chronology,
                                         ZoneId zone)
        Obtains the current AccountingDate from the system clock in the specified time-zone, translated with the given AccountingChronology.

        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.

        Parameters:
        chronology - the Accounting chronology to base the date on, not null
        zone - the zone ID to use, not null
        Returns:
        the current date using the system clock, not null
        Throws:
        DateTimeException - if the current date cannot be obtained, NullPointerException if an AccountingChronology was not provided
      • now

        public static AccountingDate now​(AccountingChronology chronology,
                                         Clock clock)
        Obtains the current AccountingDate from the specified clock, translated with the given AccountingChronology.

        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.

        Parameters:
        chronology - the Accounting chronology to base the date on, not null
        clock - the clock to use, not null
        Returns:
        the current date, not null
        Throws:
        DateTimeException - if the current date cannot be obtained, NullPointerException if an AccountingChronology was not provided
      • of

        public static AccountingDate of​(AccountingChronology chronology,
                                        int prolepticYear,
                                        int month,
                                        int dayOfMonth)
        Obtains a AccountingDate representing a date in the given accounting calendar system from the proleptic-year, month-of-year and day-of-month fields.

        This returns a AccountingDate with the specified fields. The day must be valid for the year and month, otherwise an exception will be thrown.

        Parameters:
        chronology - the Accounting chronology to base the date on, not null
        prolepticYear - the Accounting proleptic-year
        month - the Accounting month-of-year, from 1 to 12 or 1 to 13
        dayOfMonth - the Accounting day-of-month, from 1 to 35 or 1 to 42
        Returns:
        the date in the given Accounting calendar system, not null
        Throws:
        DateTimeException - if the value of any field is out of range, if the day-of-month is invalid for the month-year, or if an AccountingChronology was not provided
      • from

        public static AccountingDate from​(AccountingChronology chronology,
                                          TemporalAccessor temporal)
        Obtains an AccountingDate from a temporal object.

        This obtains a date in the specified Accounting calendar system based on the specified temporal. A TemporalAccessor represents an arbitrary set of date and time information, which this factory converts to an instance of AccountingDate.

        The conversion typically uses the EPOCH_DAY field, which is standardized across calendar systems.

        This method almost matches the signature of the functional interface TemporalQuery and must be used as a query via something that supplies the missing parameter, such as a curried method reference, temporal -> AccountingDate.from(chronology, temporal) (where chronology resolves to a set up AccountingChronology).

        Parameters:
        chronology - the Accounting chronology to base the date on, not null
        temporal - the temporal object to convert, not null
        Returns:
        the date in Accounting calendar system, not null
        Throws:
        DateTimeException - if unable to convert to an AccountingDate, NullPointerException if an AccountingChronology was not provided
      • getChronology

        public AccountingChronology getChronology()
        Gets the chronology of this date, which is an Accounting calendar system.

        The Chronology represents the calendar system in use. The era and other fields in ChronoField are defined by the chronology.

        Specified by:
        getChronology in interface ChronoLocalDate
        Returns:
        the Accounting chronology, not null
      • equals

        public boolean equals​(Object obj)
        Compares this date to another date, including the chronology.

        Compares this date with another ensuring that the date is the same.

        Only objects of this concrete type are compared, other types return false. To compare the dates of two TemporalAccessor instances, including dates in two different chronologies, use ChronoField.EPOCH_DAY as a comparator.

        Specified by:
        equals in interface ChronoLocalDate
        Parameters:
        obj - the object to check, null returns false
        Returns:
        true if this is equal to the other date
      • hashCode

        public int hashCode()
        A hash code for this date.
        Specified by:
        hashCode in interface ChronoLocalDate
        Returns:
        a suitable hash code based only on the Chronology and the date