Class BasicChronology

All Implemented Interfaces:
Serializable
Direct Known Subclasses:
BasicFixedMonthChronology, BasicGJChronology, IslamicChronology

abstract class BasicChronology extends AssembledChronology
Abstract implementation for calendar systems that use a typical day/month/year/leapYear model. Most of the utility methods required by subclasses are package-private, reflecting the intention that they be defined in the same package.

BasicChronology is thread-safe and immutable, and all subclasses must be as well.

Since:
1.2, renamed from BaseGJChronology
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      Serialization lock
      See Also:
    • cMillisField

      private static final DurationField cMillisField
    • cSecondsField

      private static final DurationField cSecondsField
    • cMinutesField

      private static final DurationField cMinutesField
    • cHoursField

      private static final DurationField cHoursField
    • cHalfdaysField

      private static final DurationField cHalfdaysField
    • cDaysField

      private static final DurationField cDaysField
    • cWeeksField

      private static final DurationField cWeeksField
    • cMillisOfSecondField

      private static final DateTimeField cMillisOfSecondField
    • cMillisOfDayField

      private static final DateTimeField cMillisOfDayField
    • cSecondOfMinuteField

      private static final DateTimeField cSecondOfMinuteField
    • cSecondOfDayField

      private static final DateTimeField cSecondOfDayField
    • cMinuteOfHourField

      private static final DateTimeField cMinuteOfHourField
    • cMinuteOfDayField

      private static final DateTimeField cMinuteOfDayField
    • cHourOfDayField

      private static final DateTimeField cHourOfDayField
    • cHourOfHalfdayField

      private static final DateTimeField cHourOfHalfdayField
    • cClockhourOfDayField

      private static final DateTimeField cClockhourOfDayField
    • cClockhourOfHalfdayField

      private static final DateTimeField cClockhourOfHalfdayField
    • cHalfdayOfDayField

      private static final DateTimeField cHalfdayOfDayField
    • CACHE_SIZE

      private static final int CACHE_SIZE
      See Also:
    • CACHE_MASK

      private static final int CACHE_MASK
      See Also:
    • iYearInfoCache

      private final transient BasicChronology.YearInfo[] iYearInfoCache
    • iMinDaysInFirstWeek

      private final int iMinDaysInFirstWeek
  • Constructor Details

    • BasicChronology

      BasicChronology(Chronology base, Object param, int minDaysInFirstWeek)
  • Method Details

    • getZone

      public DateTimeZone getZone()
      Description copied from class: BaseChronology
      Returns the DateTimeZone that this Chronology operates in, or null if unspecified.
      Overrides:
      getZone in class AssembledChronology
      Returns:
      DateTimeZone null if unspecified
    • getDateTimeMillis

      public long getDateTimeMillis(int year, int monthOfYear, int dayOfMonth, int millisOfDay) throws IllegalArgumentException
      Description copied from class: BaseChronology
      Returns a datetime millisecond instant, formed from the given year, month, day, and millisecond values. The set of given values must refer to a valid datetime, or else an IllegalArgumentException is thrown.

      The default implementation calls upon separate DateTimeFields to determine the result. Subclasses are encouraged to provide a more efficient implementation.

      Overrides:
      getDateTimeMillis in class AssembledChronology
      Parameters:
      year - year to use
      monthOfYear - month to use
      dayOfMonth - day of month to use
      millisOfDay - millisecond to use
      Returns:
      millisecond instant from 1970-01-01T00:00:00Z
      Throws:
      IllegalArgumentException - if the values are invalid
    • getDateTimeMillis

      public long getDateTimeMillis(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond) throws IllegalArgumentException
      Description copied from class: BaseChronology
      Returns a datetime millisecond instant, formed from the given year, month, day, hour, minute, second, and millisecond values. The set of given values must refer to a valid datetime, or else an IllegalArgumentException is thrown.

      The default implementation calls upon separate DateTimeFields to determine the result. Subclasses are encouraged to provide a more efficient implementation.

      Overrides:
      getDateTimeMillis in class AssembledChronology
      Parameters:
      year - year to use
      monthOfYear - month to use
      dayOfMonth - day of month to use
      hourOfDay - hour to use
      minuteOfHour - minute to use
      secondOfMinute - second to use
      millisOfSecond - millisecond to use
      Returns:
      millisecond instant from 1970-01-01T00:00:00Z
      Throws:
      IllegalArgumentException - if the values are invalid
    • getDateTimeMillis0

      private long getDateTimeMillis0(int year, int monthOfYear, int dayOfMonth, int millisOfDay)
    • getMinimumDaysInFirstWeek

      public int getMinimumDaysInFirstWeek()
    • equals

      public boolean equals(Object obj)
      Checks if this chronology instance equals another.
      Overrides:
      equals in class Object
      Parameters:
      obj - the object to compare to
      Returns:
      true if equal
      Since:
      1.6
    • hashCode

      public int hashCode()
      A suitable hash code for the chronology.
      Overrides:
      hashCode in class Object
      Returns:
      the hash code
      Since:
      1.6
    • toString

      public String toString()
      Gets a debugging toString.
      Specified by:
      toString in class BaseChronology
      Returns:
      a debugging string
    • assemble

      protected void assemble(AssembledChronology.Fields fields)
      Description copied from class: AssembledChronology
      Invoked by the constructor and after deserialization to allow subclasses to define all of its supported fields. All unset fields default to unsupported instances.
      Specified by:
      assemble in class AssembledChronology
      Parameters:
      fields - container of fields
    • getDaysInYearMax

      int getDaysInYearMax()
      Get the number of days in the year.
      Returns:
      366
    • getDaysInYear

      int getDaysInYear(int year)
      Get the number of days in the year.
      Parameters:
      year - the year to use
      Returns:
      366 if a leap year, otherwise 365
    • getWeeksInYear

      int getWeeksInYear(int year)
      Get the number of weeks in the year.
      Parameters:
      year - the year to use
      Returns:
      number of weeks in the year
    • getFirstWeekOfYearMillis

      long getFirstWeekOfYearMillis(int year)
      Get the millis for the first week of a year.
      Parameters:
      year - the year to use
      Returns:
      millis
    • getYearMillis

      long getYearMillis(int year)
      Get the milliseconds for the start of a year.
      Parameters:
      year - The year to use.
      Returns:
      millis from 1970-01-01T00:00:00Z
    • getYearMonthMillis

      long getYearMonthMillis(int year, int month)
      Get the milliseconds for the start of a month.
      Parameters:
      year - The year to use.
      month - The month to use
      Returns:
      millis from 1970-01-01T00:00:00Z
    • getYearMonthDayMillis

      long getYearMonthDayMillis(int year, int month, int dayOfMonth)
      Get the milliseconds for a particular date.
      Parameters:
      year - The year to use.
      month - The month to use
      dayOfMonth - The day of the month to use
      Returns:
      millis from 1970-01-01T00:00:00Z
    • getYear

      int getYear(long instant)
      Parameters:
      instant - millis from 1970-01-01T00:00:00Z
    • getMonthOfYear

      int getMonthOfYear(long millis)
      Parameters:
      millis - from 1970-01-01T00:00:00Z
    • getMonthOfYear

      abstract int getMonthOfYear(long millis, int year)
      Parameters:
      millis - from 1970-01-01T00:00:00Z
      year - precalculated year of millis
    • getDayOfMonth

      int getDayOfMonth(long millis)
      Parameters:
      millis - from 1970-01-01T00:00:00Z
    • getDayOfMonth

      int getDayOfMonth(long millis, int year)
      Parameters:
      millis - from 1970-01-01T00:00:00Z
      year - precalculated year of millis
    • getDayOfMonth

      int getDayOfMonth(long millis, int year, int month)
      Parameters:
      millis - from 1970-01-01T00:00:00Z
      year - precalculated year of millis
      month - precalculated month of millis
    • getDayOfYear

      int getDayOfYear(long instant)
      Parameters:
      instant - millis from 1970-01-01T00:00:00Z
    • getDayOfYear

      int getDayOfYear(long instant, int year)
      Parameters:
      instant - millis from 1970-01-01T00:00:00Z
      year - precalculated year of millis
    • getWeekyear

      int getWeekyear(long instant)
      Parameters:
      instant - millis from 1970-01-01T00:00:00Z
    • getWeekOfWeekyear

      int getWeekOfWeekyear(long instant)
      Parameters:
      instant - millis from 1970-01-01T00:00:00Z
    • getWeekOfWeekyear

      int getWeekOfWeekyear(long instant, int year)
      Parameters:
      instant - millis from 1970-01-01T00:00:00Z
      year - precalculated year of millis
    • getDayOfWeek

      int getDayOfWeek(long instant)
      Parameters:
      instant - millis from 1970-01-01T00:00:00Z
    • getMillisOfDay

      int getMillisOfDay(long instant)
      Parameters:
      instant - millis from 1970-01-01T00:00:00Z
    • getDaysInMonthMax

      int getDaysInMonthMax()
      Gets the maximum number of days in any month.
      Returns:
      31
    • getDaysInMonthMax

      int getDaysInMonthMax(long instant)
      Gets the maximum number of days in the month specified by the instant.
      Parameters:
      instant - millis from 1970-01-01T00:00:00Z
      Returns:
      the maximum number of days in the month
    • getDaysInMonthMaxForSet

      int getDaysInMonthMaxForSet(long instant, int value)
      Gets the maximum number of days in the month specified by the instant. The value represents what the user is trying to set, and can be used to optimise this method.
      Parameters:
      instant - millis from 1970-01-01T00:00:00Z
      value - the value being set
      Returns:
      the maximum number of days in the month
    • getDateMidnightMillis

      long getDateMidnightMillis(int year, int monthOfYear, int dayOfMonth)
      Gets the milliseconds for a date at midnight.
      Parameters:
      year - the year
      monthOfYear - the month
      dayOfMonth - the day
      Returns:
      the milliseconds
    • getYearDifference

      abstract long getYearDifference(long minuendInstant, long subtrahendInstant)
      Gets the difference between the two instants in years.
      Parameters:
      minuendInstant - the first instant
      subtrahendInstant - the second instant
      Returns:
      the difference
    • isLeapYear

      abstract boolean isLeapYear(int year)
      Is the specified year a leap year?
      Parameters:
      year - the year to test
      Returns:
      true if leap
    • isLeapDay

      boolean isLeapDay(long instant)
      Is the specified instant a leap day?
      Parameters:
      instant - the instant to test
      Returns:
      true if leap, default is false
    • getDaysInYearMonth

      abstract int getDaysInYearMonth(int year, int month)
      Gets the number of days in the specified month and year.
      Parameters:
      year - the year
      month - the month
      Returns:
      the number of days
    • getDaysInMonthMax

      abstract int getDaysInMonthMax(int month)
      Gets the maximum days in the specified month.
      Parameters:
      month - the month
      Returns:
      the max days
    • getTotalMillisByYearMonth

      abstract long getTotalMillisByYearMonth(int year, int month)
      Gets the total number of millis elapsed in this year at the start of the specified month, such as zero for month 1.
      Parameters:
      year - the year
      month - the month
      Returns:
      the elapsed millis at the start of the month
    • calculateFirstDayOfYearMillis

      abstract long calculateFirstDayOfYearMillis(int year)
      Gets the millisecond value of the first day of the year.
      Returns:
      the milliseconds for the first of the year
    • getMinYear

      abstract int getMinYear()
      Gets the minimum supported year.
      Returns:
      the year
    • getMaxYear

      abstract int getMaxYear()
      Gets the maximum supported year.
      Returns:
      the year
    • getMaxMonth

      int getMaxMonth(int year)
      Gets the maximum month for the specified year. This implementation calls getMaxMonth().
      Parameters:
      year - the year
      Returns:
      the maximum month value
    • getMaxMonth

      int getMaxMonth()
      Gets the maximum number of months.
      Returns:
      12
    • getAverageMillisPerYear

      abstract long getAverageMillisPerYear()
      Gets an average value for the milliseconds per year.
      Returns:
      the millis per year
    • getAverageMillisPerYearDividedByTwo

      abstract long getAverageMillisPerYearDividedByTwo()
      Gets an average value for the milliseconds per year, divided by two.
      Returns:
      the millis per year divided by two
    • getAverageMillisPerMonth

      abstract long getAverageMillisPerMonth()
      Gets an average value for the milliseconds per month.
      Returns:
      the millis per month
    • getApproxMillisAtEpochDividedByTwo

      abstract long getApproxMillisAtEpochDividedByTwo()
      Returns a constant representing the approximate number of milliseconds elapsed from year 0 of this chronology, divided by two. This constant must be defined as:
          (yearAtEpoch * averageMillisPerYear + millisOfYearAtEpoch) / 2
       
      where epoch is 1970-01-01 (Gregorian).
    • setYear

      abstract long setYear(long instant, int year)
      Sets the year from an instant and year.
      Parameters:
      instant - millis from 1970-01-01T00:00:00Z
      year - the year to set
      Returns:
      the updated millis
    • getYearInfo

      private BasicChronology.YearInfo getYearInfo(int year)