Serializable
, Comparable<Chronology>
, Chronology
public final class IsoChronology extends AbstractChronology implements Serializable
This chronology defines the rules of the ISO calendar system. This calendar system is based on the ISO-8601 standard, which is the de facto world calendar.
The fields are defined as follows:
Modifier and Type | Field | Description |
---|---|---|
static final IsoChronology |
INSTANCE |
Singleton instance of the ISO chronology. |
Modifier and Type | Method | Description |
---|---|---|
LocalDate |
date |
Obtains an ISO local date from the proleptic-year, month-of-year and day-of-month fields. |
LocalDate |
date |
Obtains an ISO local date from the era, year-of-era, month-of-year and day-of-month fields. |
LocalDate |
date |
Obtains an ISO local date from another date-time object. |
LocalDate |
dateEpochDay |
Obtains an ISO local date from the epoch-day. |
LocalDate |
dateNow() |
Obtains the current ISO local date from the system clock in the default time-zone. |
LocalDate |
dateNow |
Obtains the current ISO local date from the specified clock. |
LocalDate |
dateNow |
Obtains the current ISO local date from the system clock in the specified time-zone. |
LocalDate |
dateYearDay |
Obtains an ISO local date from the proleptic-year and day-of-year fields. |
LocalDate |
dateYearDay |
Obtains an ISO local date from the era, year-of-era and day-of-year fields. |
long |
epochSecond |
Gets the number of seconds from the epoch of 1970-01-01T00:00:00Z. |
IsoEra |
eraOf |
Creates the chronology era object from the numeric value. |
List |
eras() |
Gets the list of eras for the chronology. |
String |
getCalendarType() |
Gets the calendar type of the underlying calendar system - 'iso8601'. |
String |
getId() |
Gets the ID of the chronology - 'ISO'. |
boolean |
isIsoBased() |
IsoChronology is an ISO based chronology, which supports fields in IsoFields , such as DAY_OF_QUARTER and QUARTER_OF_YEAR . |
boolean |
isLeapYear |
Checks if the year is a leap year, according to the ISO proleptic calendar system rules. |
LocalDateTime |
localDateTime |
Obtains an ISO local date-time from another date-time object. |
Period |
period |
Obtains a period for this chronology based on years, months and days. |
int |
prolepticYear |
Calculates the proleptic-year given the era and year-of-era. |
ValueRange |
range |
Gets the range of valid values for the specified field. |
LocalDate |
resolveDate |
Resolves parsed ChronoField values into a date during parsing. |
ZonedDateTime |
zonedDateTime |
Obtains an ISO zoned date-time in this chronology from an Instant . |
ZonedDateTime |
zonedDateTime |
Obtains an ISO zoned date-time from another date-time object. |
compareTo, equals, hashCode, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
epochSecond, getDisplayName
public static final IsoChronology INSTANCE
public String getId()
The ID uniquely identifies the Chronology
. It can be used to lookup the Chronology
using Chronology.of(String)
.
getId
in interface Chronology
public String getCalendarType()
The calendar type is an identifier defined by the Unicode Locale Data Markup Language (LDML) specification. It can be used to lookup the Chronology
using Chronology.of(String)
. It can also be used as part of a locale, accessible via Locale.getUnicodeLocaleType(String)
with the key 'ca'.
getCalendarType
in interface Chronology
public LocalDate date(Era era, int yearOfEra, int month, int dayOfMonth)
date
in interface Chronology
era
- the ISO era, not nullyearOfEra
- the ISO year-of-eramonth
- the ISO month-of-yeardayOfMonth
- the ISO day-of-monthDateTimeException
- if unable to create the dateClassCastException
- if the type of era
is not IsoEra
public LocalDate date(int prolepticYear, int month, int dayOfMonth)
This is equivalent to LocalDate.of(int, int, int)
.
date
in interface Chronology
prolepticYear
- the ISO proleptic-yearmonth
- the ISO month-of-yeardayOfMonth
- the ISO day-of-monthDateTimeException
- if unable to create the datepublic LocalDate dateYearDay(Era era, int yearOfEra, int dayOfYear)
dateYearDay
in interface Chronology
era
- the ISO era, not nullyearOfEra
- the ISO year-of-eradayOfYear
- the ISO day-of-yearDateTimeException
- if unable to create the datepublic LocalDate dateYearDay(int prolepticYear, int dayOfYear)
This is equivalent to LocalDate.ofYearDay(int, int)
.
dateYearDay
in interface Chronology
prolepticYear
- the ISO proleptic-yeardayOfYear
- the ISO day-of-yearDateTimeException
- if unable to create the datepublic LocalDate dateEpochDay(long epochDay)
This is equivalent to LocalDate.ofEpochDay(long)
.
dateEpochDay
in interface Chronology
epochDay
- the epoch dayDateTimeException
- if unable to create the datepublic LocalDate date(TemporalAccessor temporal)
This is equivalent to LocalDate.from(TemporalAccessor)
.
date
in interface Chronology
temporal
- the date-time object to convert, not nullDateTimeException
- if unable to create the datepublic long epochSecond(int prolepticYear, int month, int dayOfMonth, int hour, int minute, int second, ZoneOffset zoneOffset)
The number of seconds is calculated using the year, month, day-of-month, hour, minute, second, and zoneOffset.
epochSecond
in interface Chronology
prolepticYear
- the year, from MIN_YEAR to MAX_YEARmonth
- the month-of-year, from 1 to 12dayOfMonth
- the day-of-month, from 1 to 31hour
- the hour-of-day, from 0 to 23minute
- the minute-of-hour, from 0 to 59second
- the second-of-minute, from 0 to 59zoneOffset
- the zone offset, not nullDateTimeException
- if the value of any argument is out of range, or if the day-of-month is invalid for the month-of-yearpublic LocalDateTime localDateTime(TemporalAccessor temporal)
This is equivalent to LocalDateTime.from(TemporalAccessor)
.
localDateTime
in interface Chronology
temporal
- the date-time object to convert, not nullDateTimeException
- if unable to create the date-timepublic ZonedDateTime zonedDateTime(TemporalAccessor temporal)
This is equivalent to ZonedDateTime.from(TemporalAccessor)
.
zonedDateTime
in interface Chronology
temporal
- the date-time object to convert, not nullDateTimeException
- if unable to create the date-timepublic ZonedDateTime zonedDateTime(Instant instant, ZoneId zone)
Instant
. This is equivalent to ZonedDateTime.ofInstant(Instant, ZoneId)
.
zonedDateTime
in interface Chronology
instant
- the instant to create the date-time from, not nullzone
- the time-zone, not nullDateTimeException
- if the result exceeds the supported rangepublic LocalDate dateNow()
This will query the system clock
in the default time-zone to obtain the current date.
Using this method will prevent the ability to use an alternate clock for testing because the clock is hard-coded.
dateNow
in interface Chronology
DateTimeException
- if unable to create the datepublic LocalDate dateNow(ZoneId zone)
This will query the system clock
to obtain the current date. Specifying the time-zone avoids dependence on the default time-zone.
Using this method will prevent the ability to use an alternate clock for testing because the clock is hard-coded.
dateNow
in interface Chronology
zone
- the zone ID to use, not nullDateTimeException
- if unable to create the datepublic LocalDate dateNow(Clock clock)
This will query the specified clock to obtain the current date - today. Using this method allows the use of an alternate clock for testing. The alternate clock may be introduced using dependency injection
.
dateNow
in interface Chronology
clock
- the clock to use, not nullDateTimeException
- if unable to create the datepublic boolean isLeapYear(long prolepticYear)
This method applies the current rules for leap years across the whole time-line. In general, a year is a leap year if it is divisible by four without remainder. However, years divisible by 100, are not leap years, with the exception of years divisible by 400 which are.
For example, 1904 is a leap year it is divisible by 4. 1900 was not a leap year as it is divisible by 100, however 2000 was a leap year as it is divisible by 400.
The calculation is proleptic - applying the same rules into the far future and far past. This is historically inaccurate, but is correct for the ISO-8601 standard.
isLeapYear
in interface Chronology
prolepticYear
- the ISO proleptic year to checkpublic int prolepticYear(Era era, int yearOfEra)
Chronology
This combines the era and year-of-era into the single proleptic-year field.
If the chronology makes active use of eras, such as JapaneseChronology
then the year-of-era will be validated against the era. For other chronologies, validation is optional.
prolepticYear
in interface Chronology
era
- the era of the correct type for the chronology, not nullyearOfEra
- the chronology year-of-erapublic IsoEra eraOf(int eraValue)
Chronology
The era is, conceptually, the largest division of the time-line. Most calendar systems have a single epoch dividing the time-line into two eras. However, some have multiple eras, such as one for the reign of each leader. The exact meaning is determined by the chronology according to the following constraints.
The era in use at 1970-01-01 must have the value 1. Later eras must have sequentially higher values. Earlier eras must have sequentially lower values. Each chronology must refer to an enum or similar singleton to provide the era values.
This method returns the singleton era of the correct type for the specified era value.
eraOf
in interface Chronology
eraValue
- the era valuepublic List<Era> eras()
Chronology
Most calendar systems have an era, within which the year has meaning. If the calendar system does not support the concept of eras, an empty list must be returned.
eras
in interface Chronology
public LocalDate resolveDate(Map<TemporalField,Long> fieldValues, ResolverStyle resolverStyle)
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 on the ISO calendar system are resolved as follows.
EPOCH_DAY
- If present, this is converted to a LocalDate
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 current era (CE/AD) 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 LocalDate
. In all three modes, the YEAR
is validated. If the mode is smart or strict, then the month and day are validated, with the day validated from 1 to 31. If the mode is lenient, then the date is combined in a manner equivalent to creating a date on the first of January 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 LocalDate
. 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 of January in 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 LocalDate
. 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 of January 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 LocalDate
. 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 LocalDate
. 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 of January in 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 LocalDate
. 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. resolveDate
in interface Chronology
resolveDate
in class AbstractChronology
fieldValues
- the map of fields to values, which can be updated, not nullresolverStyle
- the requested type of resolve, not nullDateTimeException
- if the date cannot be resolved, typically because of a conflict in the input datapublic ValueRange range(ChronoField field)
Chronology
All fields can be expressed as a long
integer. This method returns an object that describes the valid range for that value.
Note that the result only describes the minimum and maximum valid values and it is important not to read too much into them. For example, there could be values within the range that are invalid for the field.
This method will return a result whether or not the chronology supports the field.
range
in interface Chronology
field
- the field to get the range for, not nullpublic Period period(int years, int months, int days)
This returns a period tied to the ISO chronology using the specified years, months and days. See Period
for further details.
period
in interface Chronology
years
- the number of years, may be negativemonths
- the number of years, may be negativedays
- the number of years, may be negativepublic boolean isIsoBased()
IsoChronology
is an ISO based chronology, which supports fields in IsoFields
, such as DAY_OF_QUARTER
and QUARTER_OF_YEAR
.isIsoBased
in interface Chronology
true
© 1993, 2023, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/time/chrono/IsoChronology.html