org.joda.time.chrono

Class GJChronology

Implemented Interfaces:
Serializable

public final class GJChronology
extends AssembledChronology

Implements the Gregorian/Julian calendar system which is the calendar system used in most of the world. Wherever possible, it is recommended to use the ISOChronology instead.

The Gregorian calendar replaced the Julian calendar, and the point in time when this chronology switches can be controlled using the second parameter of the getInstance method. By default this cutover is set to the date the Gregorian calendar was first instituted, October 15, 1582.

Before this date, this chronology uses the proleptic Julian calendar (proleptic means extending indefinitely). The Julian calendar has leap years every four years, whereas the Gregorian has special rules for 100 and 400 years. A meaningful result will thus be obtained for all input values. However before 8 CE, Julian leap years were irregular, and before 45 BCE there was no Julian calendar.

This chronology differs from GregorianCalendar in that years in BCE are returned correctly. Thus year 1 BCE is returned as -1 instead of 1. The yearOfEra field produces results compatible with GregorianCalendar.

The Julian calendar does not have a year zero, and so year -1 is followed by year 1. If the Gregorian cutover date is specified at or before year -1 (Julian), year zero is defined. In other words, the proleptic Gregorian chronology used by this class has a year zero.

To create a pure proleptic Julian chronology, use JulianChronology, and to create a pure proleptic Gregorian chronology, use GregorianChronology.

GJChronology is thread-safe and immutable.

Authors:
Brian S O'Neill
Stephen Colebourne
Since:
1.0

Nested Class Summary

Nested classes/interfaces inherited from class org.joda.time.chrono.AssembledChronology

AssembledChronology.Fields

Method Summary

protected void
assemble(AssembledChronology.Fields fields)
boolean
equals(Object obj)
Checks if this chronology instance equals another.
long
getDateTimeMillis(int year, int monthOfYear, int dayOfMonth, int millisOfDay)
Returns a datetime millisecond instant, formed from the given year, month, day, and millisecond values.
long
getDateTimeMillis(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond)
Returns a datetime millisecond instant, formed from the given year, month, day, hour, minute, second, and millisecond values.
Instant
getGregorianCutover()
Gets the cutover instant between Gregorian and Julian chronologies.
static GJChronology
getInstance()
Factory method returns instances of the default GJ cutover chronology.
static GJChronology
getInstance(DateTimeZone zone)
Factory method returns instances of the GJ cutover chronology.
static GJChronology
getInstance(DateTimeZone zone, long gregorianCutover, int minDaysInFirstWeek)
Factory method returns instances of the GJ cutover chronology.
static GJChronology
getInstance(DateTimeZone zone, ReadableInstant gregorianCutover)
Factory method returns instances of the GJ cutover chronology.
static GJChronology
getInstance(DateTimeZone zone, ReadableInstant gregorianCutover, int minDaysInFirstWeek)
Factory method returns instances of the GJ cutover chronology.
static GJChronology
getInstanceUTC()
Factory method returns instances of the default GJ cutover chronology.
int
getMinimumDaysInFirstWeek()
Gets the minimum days needed for a week to be the first week in a year.
DateTimeZone
getZone()
Returns the DateTimeZone that this Chronology operates in, or null if unspecified.
int
hashCode()
A suitable hash code for the chronology.
String
toString()
Gets a debugging toString.
Chronology
withUTC()
Gets the Chronology in the UTC time zone.
Chronology
withZone(DateTimeZone zone)
Gets the Chronology in a specific time zone.

Methods inherited from class org.joda.time.chrono.AssembledChronology

assemble, centuries, centuryOfEra, clockhourOfDay, clockhourOfHalfday, dayOfMonth, dayOfWeek, dayOfYear, days, era, eras, getBase, getDateTimeMillis, getDateTimeMillis, getDateTimeMillis, getParam, getZone, halfdayOfDay, halfdays, hourOfDay, hourOfHalfday, hours, millis, millisOfDay, millisOfSecond, minuteOfDay, minuteOfHour, minutes, monthOfYear, months, secondOfDay, secondOfMinute, seconds, weekOfWeekyear, weeks, weekyear, weekyearOfCentury, weekyears, year, yearOfCentury, yearOfEra, years

Methods inherited from class org.joda.time.chrono.BaseChronology

add, add, centuries, centuryOfEra, clockhourOfDay, clockhourOfHalfday, dayOfMonth, dayOfWeek, dayOfYear, days, era, eras, get, get, get, getDateTimeMillis, getDateTimeMillis, getDateTimeMillis, getZone, halfdayOfDay, halfdays, hourOfDay, hourOfHalfday, hours, millis, millisOfDay, millisOfSecond, minuteOfDay, minuteOfHour, minutes, monthOfYear, months, secondOfDay, secondOfMinute, seconds, set, toString, validate, weekOfWeekyear, weeks, weekyear, weekyearOfCentury, weekyears, withUTC, withZone, year, yearOfCentury, yearOfEra, years

Methods inherited from class org.joda.time.Chronology

add, add, centuries, centuryOfEra, clockhourOfDay, clockhourOfHalfday, dayOfMonth, dayOfWeek, dayOfYear, days, era, eras, get, get, get, getBuddhist, getBuddhist, getBuddhistUTC, getCoptic, getCoptic, getCopticUTC, getDateTimeMillis, getDateTimeMillis, getDateTimeMillis, getGJ, getGJ, getGJUTC, getGregorian, getGregorian, getGregorianUTC, getISO, getISO, getISOUTC, getJulian, getJulian, getJulianUTC, getZone, halfdayOfDay, halfdays, hourOfDay, hourOfHalfday, hours, millis, millisOfDay, millisOfSecond, minuteOfDay, minuteOfHour, minutes, monthOfYear, months, secondOfDay, secondOfMinute, seconds, set, toString, validate, weekOfWeekyear, weeks, weekyear, weekyearOfCentury, weekyears, withUTC, withZone, year, yearOfCentury, yearOfEra, years

Method Details

assemble

protected void assemble(AssembledChronology.Fields fields)
Overrides:
assemble in interface AssembledChronology

equals

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

getDateTimeMillis

public long getDateTimeMillis(int year,
                              int monthOfYear,
                              int dayOfMonth,
                              int millisOfDay)
            throws IllegalArgumentException
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 interface 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

getDateTimeMillis

public long getDateTimeMillis(int year,
                              int monthOfYear,
                              int dayOfMonth,
                              int hourOfDay,
                              int minuteOfHour,
                              int secondOfMinute,
                              int millisOfSecond)
            throws IllegalArgumentException
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 interface 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

getGregorianCutover

public Instant getGregorianCutover()
Gets the cutover instant between Gregorian and Julian chronologies.
Returns:
the cutover instant

getInstance

public static GJChronology getInstance()
Factory method returns instances of the default GJ cutover chronology. This uses a cutover date of October 15, 1582 (Gregorian) 00:00:00 UTC. For this value, October 4, 1582 (Julian) is followed by October 15, 1582 (Gregorian).

The first day of the week is designated to be Monday, and the minimum days in the first week of the year is 4.

The returned chronology is in the default time zone.


getInstance

public static GJChronology getInstance(DateTimeZone zone)
Factory method returns instances of the GJ cutover chronology. This uses a cutover date of October 15, 1582 (Gregorian) 00:00:00 UTC. For this value, October 4, 1582 (Julian) is followed by October 15, 1582 (Gregorian).

The first day of the week is designated to be Monday, and the minimum days in the first week of the year is 4.

Parameters:
zone - the time zone to use, null is default

getInstance

public static GJChronology getInstance(DateTimeZone zone,
                                       long gregorianCutover,
                                       int minDaysInFirstWeek)
Factory method returns instances of the GJ cutover chronology. Any cutover date may be specified.
Parameters:
zone - the time zone to use, null is default
gregorianCutover - the cutover to use
minDaysInFirstWeek - minimum number of days in first week of the year; default is 4

getInstance

public static GJChronology getInstance(DateTimeZone zone,
                                       ReadableInstant gregorianCutover)
Factory method returns instances of the GJ cutover chronology. Any cutover date may be specified.

The first day of the week is designated to be Monday, and the minimum days in the first week of the year is 4.

Parameters:
zone - the time zone to use, null is default
gregorianCutover - the cutover to use, null means default

getInstance

public static GJChronology getInstance(DateTimeZone zone,
                                       ReadableInstant gregorianCutover,
                                       int minDaysInFirstWeek)
Factory method returns instances of the GJ cutover chronology. Any cutover date may be specified.
Parameters:
zone - the time zone to use, null is default
gregorianCutover - the cutover to use, null means default
minDaysInFirstWeek - minimum number of days in first week of the year; default is 4

getInstanceUTC

public static GJChronology getInstanceUTC()
Factory method returns instances of the default GJ cutover chronology. This uses a cutover date of October 15, 1582 (Gregorian) 00:00:00 UTC. For this value, October 4, 1582 (Julian) is followed by October 15, 1582 (Gregorian).

The first day of the week is designated to be Monday, and the minimum days in the first week of the year is 4.

The time zone of the returned instance is UTC.


getMinimumDaysInFirstWeek

public int getMinimumDaysInFirstWeek()
Gets the minimum days needed for a week to be the first week in a year.
Returns:
the minimum days

getZone

public DateTimeZone getZone()
Returns the DateTimeZone that this Chronology operates in, or null if unspecified.
Overrides:
getZone in interface AssembledChronology
Returns:
DateTimeZone null if unspecified

hashCode

public int hashCode()
A suitable hash code for the chronology.
Returns:
the hash code
Since:
1.6

toString

public String toString()
Gets a debugging toString.
Overrides:
toString in interface BaseChronology
Returns:
a debugging string

withUTC

public Chronology withUTC()
Gets the Chronology in the UTC time zone.
Overrides:
withUTC in interface BaseChronology
Returns:
the chronology in UTC

withZone

public Chronology withZone(DateTimeZone zone)
Gets the Chronology in a specific time zone.
Overrides:
withZone in interface BaseChronology
Parameters:
zone - the zone to get the chronology in, null is default
Returns:
the chronology

Copyright (c) 2001-2006 - Joda.org