Class GregorianChronology

All Implemented Interfaces:
Serializable

public final class GregorianChronology extends AssembledChronology
Implements a pure proleptic Gregorian calendar system, which defines every fourth year as leap, unless the year is divisible by 100 and not by 400. This improves upon the Julian calendar leap year rule.

Although the Gregorian calendar did not exist before 1582 CE, this chronology assumes it did, thus it is proleptic. This implementation also fixes the start of the year at January 1, and defines the year zero.

GregorianChronology is thread-safe and immutable.

Since:
1.0
Author:
Guy Allard, Stephen Colebourne, Brian S O'Neill
See Also:
  • Method Details

    • getInstanceUTC

      public static GregorianChronology getInstanceUTC()
      Gets an instance of the GregorianChronology. The time zone of the returned instance is UTC.
      Returns:
      a singleton UTC instance of the chronology
    • getInstance

      public static GregorianChronology getInstance()
      Gets an instance of the GregorianChronology in the default time zone.
      Returns:
      a chronology in the default time zone
    • getInstance

      public static GregorianChronology getInstance(DateTimeZone zone)
      Gets an instance of the GregorianChronology in the given time zone.
      Parameters:
      zone - the time zone to get the chronology in, null is default
      Returns:
      a chronology in the specified time zone
    • getInstance

      public static GregorianChronology getInstance(DateTimeZone zone, int minDaysInFirstWeek)
      Gets an instance of the GregorianChronology in the given time zone.
      Parameters:
      zone - the time zone to get the chronology in, null is default
      minDaysInFirstWeek - minimum number of days in first week of the year; default is 4
      Returns:
      a chronology in the specified time zone
    • withUTC

      public Chronology withUTC()
      Gets the Chronology in the UTC time zone.
      Specified by:
      withUTC in class BaseChronology
      Returns:
      the chronology in UTC
    • withZone

      public Chronology withZone(DateTimeZone zone)
      Gets the Chronology in a specific time zone.
      Specified by:
      withZone in class BaseChronology
      Parameters:
      zone - the zone to get the chronology in, null is default
      Returns:
      the chronology
      See Also:
    • 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.
      Parameters:
      fields - container of fields
    • 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
    • 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