Class GJChronology
- java.lang.Object
-
- org.joda.time.Chronology
-
- org.joda.time.chrono.BaseChronology
-
- org.joda.time.chrono.AssembledChronology
-
- org.joda.time.chrono.GJChronology
-
- All Implemented Interfaces:
java.io.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 theISOChronology
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, useGregorianChronology
.GJChronology is thread-safe and immutable.
- Since:
- 1.0
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
GJChronology.CutoverField
This basic cutover field adjusts calls to 'get' and 'set' methods, and assumes that calls to add and addWrapField are unaffected by the cutover.private class
GJChronology.ImpreciseCutoverField
Cutover field for variable length fields.private static class
GJChronology.LinkedDurationField
Links the duration back to a ImpreciseCutoverField.-
Nested classes/interfaces inherited from class org.joda.time.chrono.AssembledChronology
AssembledChronology.Fields
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.concurrent.ConcurrentHashMap<GJCacheKey,GJChronology>
cCache
Cache of zone to chronology list(package private) static Instant
DEFAULT_CUTOVER
The default GregorianJulian cutover point.private Instant
iCutoverInstant
private long
iCutoverMillis
private long
iGapDuration
private GregorianChronology
iGregorianChronology
private JulianChronology
iJulianChronology
private static long
serialVersionUID
Serialization lock
-
Constructor Summary
Constructors Modifier Constructor Description private
GJChronology(JulianChronology julian, GregorianChronology gregorian, Instant cutoverInstant)
private
GJChronology(Chronology base, JulianChronology julian, GregorianChronology gregorian, Instant cutoverInstant)
Called when applying a time zone.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
assemble(AssembledChronology.Fields fields)
Invoked by the constructor and after deserialization to allow subclasses to define all of its supported fields.private static long
convertByWeekyear(long instant, Chronology from, Chronology to)
Convert a datetime from one chronology to another.private static long
convertByYear(long instant, Chronology from, Chronology to)
Convert a datetime from one chronology to another.boolean
equals(java.lang.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.(package private) long
gregorianToJulianByWeekyear(long instant)
(package private) long
gregorianToJulianByYear(long instant)
int
hashCode()
A suitable hash code for the chronology.(package private) long
julianToGregorianByWeekyear(long instant)
(package private) long
julianToGregorianByYear(long instant)
private java.lang.Object
readResolve()
Serialization singletonjava.lang.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
centuries, centuryOfEra, clockhourOfDay, clockhourOfHalfday, dayOfMonth, dayOfWeek, dayOfYear, days, era, eras, getBase, getDateTimeMillis, getParam, 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
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
Serialization lock- See Also:
- Constant Field Values
-
DEFAULT_CUTOVER
static final Instant DEFAULT_CUTOVER
The default GregorianJulian cutover point.
-
cCache
private static final java.util.concurrent.ConcurrentHashMap<GJCacheKey,GJChronology> cCache
Cache of zone to chronology list
-
iJulianChronology
private JulianChronology iJulianChronology
-
iGregorianChronology
private GregorianChronology iGregorianChronology
-
iCutoverInstant
private Instant iCutoverInstant
-
iCutoverMillis
private long iCutoverMillis
-
iGapDuration
private long iGapDuration
-
-
Constructor Detail
-
GJChronology
private GJChronology(JulianChronology julian, GregorianChronology gregorian, Instant cutoverInstant)
- Parameters:
julian
- chronology used before the cutover instantgregorian
- chronology used at and after the cutover instantcutoverInstant
- instant when the gregorian chronology began
-
GJChronology
private GJChronology(Chronology base, JulianChronology julian, GregorianChronology gregorian, Instant cutoverInstant)
Called when applying a time zone.
-
-
Method Detail
-
convertByYear
private static long convertByYear(long instant, Chronology from, Chronology to)
Convert a datetime from one chronology to another.
-
convertByWeekyear
private static long convertByWeekyear(long instant, Chronology from, Chronology to)
Convert a datetime from one chronology to another.
-
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.
-
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, 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 defaultgregorianCutover
- 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 defaultgregorianCutover
- the cutover to use, null means defaultminDaysInFirstWeek
- minimum number of days in first week of the year; default is 4
-
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 defaultgregorianCutover
- the cutover to useminDaysInFirstWeek
- minimum number of days in first week of the year; default is 4
-
readResolve
private java.lang.Object readResolve()
Serialization singleton
-
getZone
public DateTimeZone getZone()
Description copied from class:BaseChronology
Returns the DateTimeZone that this Chronology operates in, or null if unspecified.- Overrides:
getZone
in classAssembledChronology
- Returns:
- DateTimeZone null if unspecified
-
withUTC
public Chronology withUTC()
Gets the Chronology in the UTC time zone.- Specified by:
withUTC
in classBaseChronology
- Returns:
- the chronology in UTC
-
withZone
public Chronology withZone(DateTimeZone zone)
Gets the Chronology in a specific time zone.- Specified by:
withZone
in classBaseChronology
- Parameters:
zone
- the zone to get the chronology in, null is default- Returns:
- the chronology
- See Also:
ZonedChronology
-
getDateTimeMillis
public long getDateTimeMillis(int year, int monthOfYear, int dayOfMonth, int millisOfDay) throws java.lang.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 classAssembledChronology
- Parameters:
year
- year to usemonthOfYear
- month to usedayOfMonth
- day of month to usemillisOfDay
- millisecond to use- Returns:
- millisecond instant from 1970-01-01T00:00:00Z
- Throws:
java.lang.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 java.lang.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 classAssembledChronology
- Parameters:
year
- year to usemonthOfYear
- month to usedayOfMonth
- day of month to usehourOfDay
- hour to useminuteOfHour
- minute to usesecondOfMinute
- second to usemillisOfSecond
- millisecond to use- Returns:
- millisecond instant from 1970-01-01T00:00:00Z
- Throws:
java.lang.IllegalArgumentException
- if the values are invalid
-
getGregorianCutover
public Instant getGregorianCutover()
Gets the cutover instant between Gregorian and Julian chronologies.- Returns:
- the cutover instant
-
getMinimumDaysInFirstWeek
public int getMinimumDaysInFirstWeek()
Gets the minimum days needed for a week to be the first week in a year.- Returns:
- the minimum days
-
equals
public boolean equals(java.lang.Object obj)
Checks if this chronology instance equals another.- Overrides:
equals
in classjava.lang.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 classjava.lang.Object
- Returns:
- the hash code
- Since:
- 1.6
-
toString
public java.lang.String toString()
Gets a debugging toString.- Specified by:
toString
in classBaseChronology
- 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 classAssembledChronology
- Parameters:
fields
- container of fields
-
julianToGregorianByYear
long julianToGregorianByYear(long instant)
-
gregorianToJulianByYear
long gregorianToJulianByYear(long instant)
-
julianToGregorianByWeekyear
long julianToGregorianByWeekyear(long instant)
-
gregorianToJulianByWeekyear
long gregorianToJulianByWeekyear(long instant)
-
-