Top Description Fields Constructors Methods
java.time.chrono

public abstract Class AbstractChronology

extends Object
implements Chronology
Class Inheritance
All Implemented Interfaces
java.time.chrono.Chronology, java.lang.Comparable
Known Direct Subclasses
java.time.chrono.HijrahChronology, java.time.chrono.IsoChronology, java.time.chrono.JapaneseChronology, java.time.chrono.MinguoChronology, java.time.chrono.ThaiBuddhistChronology
Static Imports
java.time.temporal.ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH, .ChronoField.ALIGNED_DAY_OF_WEEK_IN_YEAR, .ChronoField.ALIGNED_WEEK_OF_MONTH, .ChronoField.ALIGNED_WEEK_OF_YEAR, .ChronoField.DAY_OF_MONTH, .ChronoField.DAY_OF_WEEK, .ChronoField.DAY_OF_YEAR, .ChronoField.EPOCH_DAY, .ChronoField.ERA, .ChronoField.MONTH_OF_YEAR, .ChronoField.PROLEPTIC_MONTH, .ChronoField.YEAR, .ChronoField.YEAR_OF_ERA, .ChronoUnit.DAYS, .ChronoUnit.MONTHS, .ChronoUnit.WEEKS, .TemporalAdjusters.nextOrSame

An abstract implementation of a calendar system, used to organize and identify dates.

The main date and time API is built on the ISO calendar system. The chronology operates behind the scenes to represent the general concept of a calendar system.

See Chronology for more details.

Implementation Specification

This class is separated from the Chronology interface so that the static methods are not inherited. While Chronology can be implemented directly, it is strongly recommended to extend this abstract class instead.

This class must be implemented with care to ensure other classes operate correctly. All implementations that can be instantiated must be final, immutable and thread-safe. Subclasses should be Serializable wherever possible.

Since
1.8

Field Summary

Modifier and TypeField and Description
private static final ConcurrentHashMap<String, Chronology>
CHRONOS_BY_ID

Map of available calendars by ID.

private static final ConcurrentHashMap<String, Chronology>
CHRONOS_BY_TYPE

Map of available calendars by calendar type.

Constructor Summary

AccessConstructor and Description
protected
AbstractChronology()

Creates an instance.

Method Summary

Modifier and TypeMethod and Description
pack-priv void
addFieldValue(Map<TemporalField, Long> fieldValues, ChronoField
the field to add, not null
field
,
long
the value to add, not null
value
)

Adds a field-value pair to the map, checking for conflicts.

public int

Returns:

the comparator value, that is this ID string compared with the other's ID string
compareTo
(Chronology
the other chronology to compare to, not null
other
)

Implements java.time.chrono.Chronology.compareTo.

Compares this chronology to another chronology.

public boolean

Returns:

true if this is equal to the other chronology
equals
(Object
the object to check, null returns false
obj
)

Overrides java.lang.Object.equals.

Implements java.time.chrono.Chronology.equals.

Checks if this chronology is equal to another chronology.

pack-priv static Set<Chronology>

Returns:

the independent, modifiable set of the available chronology IDs, not null
getAvailableChronologies
()

Hides java.time.chrono.Chronology.getAvailableChronologies.

Returns the available chronologies.

public int

Returns:

a suitable hash code
hashCode
()

Overrides java.lang.Object.hashCode.

Implements java.time.chrono.Chronology.hashCode.

A hash code for this chronology.

private static boolean

Returns:

true if the cache was initialized
initCache
()

Initialization of the maps from id and type to Chronology.

pack-priv static Chronology

Returns:

the chronology with the identifier requested, not null
of
(String
the chronology ID or calendar system type, not null
id
)

Hides java.time.chrono.Chronology.of.

Obtains an instance of Chronology from a chronology ID or calendar system type.

private static Chronology

Returns:

the chronology with the identifier requested, or null if not found
of0
(String
the chronology ID or calendar system type, not null
id
)

Obtains an instance of Chronology from a chronology ID or calendar system type.

pack-priv static Chronology

Returns:

the calendar system associated with the locale, not null
ofLocale
(Locale
the locale to use to obtain the calendar system, not null
locale
)

Hides java.time.chrono.Chronology.ofLocale.

Obtains an instance of Chronology from a locale.

pack-priv static Chronology
private void
readObject(ObjectInputStream
the stream to read
s
)

Defend against malicious streams.

pack-priv static Chronology

Returns:

the already registered Chronology if any, may be null
registerChrono
(Chronology
the chronology to register; not null
chrono
)

Register a Chronology by its ID and type for lookup by of(String).

pack-priv static Chronology

Returns:

the already registered Chronology if any, may be null
registerChrono
(Chronology
the chronology to register; not null
chrono
,
String
the ID to register the chronology; not null
id
)

Register a Chronology by ID and type for lookup by of(String).

pack-priv ChronoLocalDate
resolveAligned(ChronoLocalDate base, long months, long weeks, long dow)

public ChronoLocalDate

Returns:

the resolved date, null if insufficient information to create a date
resolveDate
(Map<TemporalField, Long>
the map of fields to values, which can be updated, not null
fieldValues
,
ResolverStyle
the requested type of resolve, not null
resolverStyle
)

Implements java.time.chrono.Chronology.resolveDate.

Resolves parsed ChronoField values into a date during parsing.

pack-priv void
pack-priv ChronoLocalDate
resolveYAA(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle)

pack-priv ChronoLocalDate
resolveYAD(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle)

pack-priv ChronoLocalDate
resolveYD(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle)

pack-priv ChronoLocalDate
resolveYearOfEra(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle)

pack-priv ChronoLocalDate
resolveYMAA(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle)

pack-priv ChronoLocalDate
resolveYMAD(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle)

pack-priv ChronoLocalDate
resolveYMD(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle)

public String

Returns:

a string representation of this chronology, not null
toString
()

Overrides java.lang.Object.toString.

Implements java.time.chrono.Chronology.toString.

Outputs this chronology as a String, using the chronology ID.

pack-priv void
pack-priv Object

Returns:

the instance of Ser, not null
writeReplace
()

Writes the Chronology using a dedicated serialized form.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

CHRONOS_BY_IDback to summary
private static final ConcurrentHashMap<String, Chronology> CHRONOS_BY_ID

Map of available calendars by ID.

CHRONOS_BY_TYPEback to summary
private static final ConcurrentHashMap<String, Chronology> CHRONOS_BY_TYPE

Map of available calendars by calendar type.

Constructor Detail

AbstractChronologyback to summary
protected AbstractChronology()

Creates an instance.

Method Detail

addFieldValueback to summary
pack-priv void addFieldValue(Map<TemporalField, Long> fieldValues, ChronoField field, long value)

Adds a field-value pair to the map, checking for conflicts.

If the field is not already present, then the field-value pair is added to the map. If the field is already present and it has the same value as that specified, no action occurs. If the field is already present and it has a different value to that specified, then an exception is thrown.

Parameters
field:ChronoField

the field to add, not null

value:long

the value to add, not null

Exceptions
DateTimeException:
if the field is already present with a different value
compareToback to summary
public int compareTo(Chronology other)

Implements java.time.chrono.Chronology.compareTo.

Compares this chronology to another chronology.

The comparison order first by the chronology ID string, then by any additional information specific to the subclass. It is "consistent with equals", as defined by Comparable.

Implementation Specification

This implementation compares the chronology ID. Subclasses must compare any additional state that they store.

Parameters
other:Chronology

the other chronology to compare to, not null

Returns:int

the comparator value, that is this ID string compared with the other's ID string

Annotations
@Override
equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Implements java.time.chrono.Chronology.equals.

Checks if this chronology is equal to another chronology.

The comparison is based on the entire state of the object.

Implementation Specification

This implementation checks the type and calls compareTo(java.time.chrono.Chronology).

Parameters
obj:Object

the object to check, null returns false

Returns:boolean

true if this is equal to the other chronology

Annotations
@Override
getAvailableChronologiesback to summary
pack-priv static Set<Chronology> getAvailableChronologies()

Hides java.time.chrono.Chronology.getAvailableChronologies.

Returns the available chronologies.

Each returned Chronology is available for use in the system. The set of chronologies includes the system chronologies and any chronologies provided by the application via ServiceLoader configuration.

Returns:Set<Chronology>

the independent, modifiable set of the available chronology IDs, not null

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Implements java.time.chrono.Chronology.hashCode.

A hash code for this chronology.

The hash code should be based on the entire state of the object.

Implementation Specification

This implementation is based on the chronology ID and class. Subclasses should add any additional state that they store.

Returns:int

a suitable hash code

Annotations
@Override
initCacheback to summary
private static boolean initCache()

Initialization of the maps from id and type to Chronology. The ServiceLoader is used to find and register any implementations of java.time.chrono.AbstractChronology found in the bootclass loader. The built-in chronologies are registered explicitly. Calendars configured via the Thread's context classloader are local to that thread and are ignored.

The initialization is done only once using the registration of the IsoChronology as the test and the final step. Multiple threads may perform the initialization concurrently. Only the first registration of each Chronology is retained by the ConcurrentHashMap.

Returns:boolean

true if the cache was initialized

ofback to summary
pack-priv static Chronology of(String id)

Hides java.time.chrono.Chronology.of.

Obtains an instance of Chronology from a chronology ID or calendar system type.

See Chronology#of(String).

Parameters
id:String

the chronology ID or calendar system type, not null

Returns:Chronology

the chronology with the identifier requested, not null

Exceptions
DateTimeException:
if the chronology cannot be found
of0back to summary
private static Chronology of0(String id)

Obtains an instance of Chronology from a chronology ID or calendar system type.

Parameters
id:String

the chronology ID or calendar system type, not null

Returns:Chronology

the chronology with the identifier requested, or null if not found

ofLocaleback to summary
pack-priv static Chronology ofLocale(Locale locale)

Hides java.time.chrono.Chronology.ofLocale.

Obtains an instance of Chronology from a locale.

See Chronology#ofLocale(Locale).

Parameters
locale:Locale

the locale to use to obtain the calendar system, not null

Returns:Chronology

the calendar system associated with the locale, not null

Exceptions
DateTimeException:
if the locale-specified calendar cannot be found
readExternalback to summary
pack-priv static Chronology readExternal(DataInput in) throws IOException
readObjectback to summary
private void readObject(ObjectInputStream s) throws ObjectStreamException

Defend against malicious streams.

Parameters
s:ObjectInputStream

the stream to read

Annotations
@Serial
Exceptions
InvalidObjectException:
always
registerChronoback to summary
pack-priv static Chronology registerChrono(Chronology chrono)

Register a Chronology by its ID and type for lookup by of(String). Chronologies must not be registered until they are completely constructed. Specifically, not in the constructor of Chronology.

Parameters
chrono:Chronology

the chronology to register; not null

Returns:Chronology

the already registered Chronology if any, may be null

registerChronoback to summary
pack-priv static Chronology registerChrono(Chronology chrono, String id)

Register a Chronology by ID and type for lookup by of(String). Chronos must not be registered until they are completely constructed. Specifically, not in the constructor of Chronology.

Parameters
chrono:Chronology

the chronology to register; not null

id:String

the ID to register the chronology; not null

Returns:Chronology

the already registered Chronology if any, may be null

resolveAlignedback to summary
pack-priv ChronoLocalDate resolveAligned(ChronoLocalDate base, long months, long weeks, long dow)
resolveDateback to summary
public ChronoLocalDate resolveDate(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle)

Implements java.time.chrono.Chronology.resolveDate.

Resolves parsed ChronoField values into a date during parsing.

Most TemporalField implementations are resolved using the resolve method on the field. By contrast, the ChronoField class defines fields that only have meaning relative to the chronology. As such, ChronoField date fields are resolved here in the context of a specific chronology.

ChronoField instances are resolved by this method, which may be overridden in subclasses.

  • EPOCH_DAY - If present, this is converted to a date and all other date fields are then cross-checked against the date.
  • PROLEPTIC_MONTH - If present, then it is split into the YEAR and MONTH_OF_YEAR. If the mode is strict or smart then the field is validated.
  • YEAR_OF_ERA and ERA - If both are present, then they are combined to form a YEAR. In lenient mode, the YEAR_OF_ERA range is not validated, in smart and strict mode it is. The ERA is validated for range in all three modes. If only the YEAR_OF_ERA is present, and the mode is smart or lenient, then the last available era is assumed. In strict mode, no era is assumed and the YEAR_OF_ERA is left untouched. If only the ERA is present, then it is left untouched.
  • YEAR, MONTH_OF_YEAR and DAY_OF_MONTH - If all three are present, then they are combined to form a date. In all three modes, the YEAR is validated. If the mode is smart or strict, then the month and day are validated. If the mode is lenient, then the date is combined in a manner equivalent to creating a date on the first day of the first month in the requested year, then adding the difference in months, then the difference in days. If the mode is smart, and the day-of-month is greater than the maximum for the year-month, then the day-of-month is adjusted to the last day-of-month. If the mode is strict, then the three fields must form a valid date.
  • YEAR and DAY_OF_YEAR - If both are present, then they are combined to form a date. In all three modes, the YEAR is validated. If the mode is lenient, then the date is combined in a manner equivalent to creating a date on the first day of the requested year, then adding the difference in days. If the mode is smart or strict, then the two fields must form a valid date.
  • YEAR, MONTH_OF_YEAR, ALIGNED_WEEK_OF_MONTH and ALIGNED_DAY_OF_WEEK_IN_MONTH - If all four are present, then they are combined to form a date. In all three modes, the YEAR is validated. If the mode is lenient, then the date is combined in a manner equivalent to creating a date on the first day of the first month in the requested year, then adding the difference in months, then the difference in weeks, then in days. If the mode is smart or strict, then the all four fields are validated to their outer ranges. The date is then combined in a manner equivalent to creating a date on the first day of the requested year and month, then adding the amount in weeks and days to reach their values. If the mode is strict, the date is additionally validated to check that the day and week adjustment did not change the month.
  • YEAR, MONTH_OF_YEAR, ALIGNED_WEEK_OF_MONTH and DAY_OF_WEEK - If all four are present, then they are combined to form a date. The approach is the same as described above for years, months and weeks in ALIGNED_DAY_OF_WEEK_IN_MONTH. The day-of-week is adjusted as the next or same matching day-of-week once the years, months and weeks have been handled.
  • YEAR, ALIGNED_WEEK_OF_YEAR and ALIGNED_DAY_OF_WEEK_IN_YEAR - If all three are present, then they are combined to form a date. In all three modes, the YEAR is validated. If the mode is lenient, then the date is combined in a manner equivalent to creating a date on the first day of the requested year, then adding the difference in weeks, then in days. If the mode is smart or strict, then the all three fields are validated to their outer ranges. The date is then combined in a manner equivalent to creating a date on the first day of the requested year, then adding the amount in weeks and days to reach their values. If the mode is strict, the date is additionally validated to check that the day and week adjustment did not change the year.
  • YEAR, ALIGNED_WEEK_OF_YEAR and DAY_OF_WEEK - If all three are present, then they are combined to form a date. The approach is the same as described above for years and weeks in ALIGNED_DAY_OF_WEEK_IN_YEAR. The day-of-week is adjusted as the next or same matching day-of-week once the years and weeks have been handled.

The default implementation is suitable for most calendar systems. If java.time.temporal.ChronoField#YEAR_OF_ERA is found without an java.time.temporal.ChronoField#ERA then the last era in eras() is used. The implementation assumes a 7 day week, that the first day-of-month has the value 1, that first day-of-year has the value 1, and that the first of the month and year always exists.

Parameters
fieldValues:Map<TemporalField, Long>

the map of fields to values, which can be updated, not null

resolverStyle:ResolverStyle

the requested type of resolve, not null

Returns:ChronoLocalDate

the resolved date, null if insufficient information to create a date

Annotations
@Override
Exceptions
DateTimeException:
if the date cannot be resolved, typically because of a conflict in the input data
resolveProlepticMonthback to summary
pack-priv void resolveProlepticMonth(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle)
resolveYAAback to summary
pack-priv ChronoLocalDate resolveYAA(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle)
resolveYADback to summary
pack-priv ChronoLocalDate resolveYAD(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle)
resolveYDback to summary
pack-priv ChronoLocalDate resolveYD(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle)
resolveYearOfEraback to summary
pack-priv ChronoLocalDate resolveYearOfEra(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle)
resolveYMAAback to summary
pack-priv ChronoLocalDate resolveYMAA(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle)
resolveYMADback to summary
pack-priv ChronoLocalDate resolveYMAD(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle)
resolveYMDback to summary
pack-priv ChronoLocalDate resolveYMD(Map<TemporalField, Long> fieldValues, ResolverStyle resolverStyle)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Implements java.time.chrono.Chronology.toString.

Outputs this chronology as a String, using the chronology ID.

Returns:String

a string representation of this chronology, not null

Annotations
@Override
writeExternalback to summary
pack-priv void writeExternal(DataOutput out) throws IOException
writeReplaceback to summary
pack-priv Object writeReplace()

Writes the Chronology using a dedicated serialized form.

 out.writeByte(1);  // identifies this as a Chronology
 out.writeUTF(getId());
Returns:Object

the instance of Ser, not null

Annotations
@Serial