APIdia Launch Partner
Top Description Fields Constructors Methods
java.time.chrono

pack-priv abstract Class ChronoLocalDateImpl<D extends ChronoLocalDate>

extends Object
implements ChronoLocalDate, Temporal, TemporalAdjuster, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, java.time.temporal.TemporalAdjuster, java.time.temporal.Temporal, java.time.temporal.TemporalAccessor, java.time.chrono.ChronoLocalDate, java.lang.Comparable
Known Direct Subclasses
java.time.chrono.HijrahDate, java.time.chrono.JapaneseDate, java.time.chrono.MinguoDate, java.time.chrono.ThaiBuddhistDate
Type Parameters
<D>
the ChronoLocalDate of this date-time
Static Imports
java.time.temporal.ChronoField.DAY_OF_MONTH, .ChronoField.ERA, .ChronoField.MONTH_OF_YEAR, .ChronoField.PROLEPTIC_MONTH, .ChronoField.YEAR_OF_ERA

A date expressed in terms of a standard year-month-day calendar system.

This class is used by applications seeking to handle dates in non-ISO calendar systems. For example, the Japanese, Minguo, Thai Buddhist and others.

ChronoLocalDate is built on the generic concepts of year, month and day. The calendar system, represented by a java.time.chrono.Chronology, expresses the relationship between the fields and this class allows the resulting date to be manipulated.

Note that not all calendar systems are suitable for use with this class. For example, the Mayan calendar uses a system that bears no relation to years, months and days.

The API design encourages the use of LocalDate for the majority of the application. This includes code to read and write from a persistent data store, such as a database, and to send dates and times across a network. The ChronoLocalDate instance is then used at the user interface level to deal with localized input/output.

Example:

       System.out.printf("Example()%n");
       // Enumerate the list of available calendars and print today for each
       Set<Chronology> chronos = Chronology.getAvailableChronologies();
       for (Chronology chrono : chronos) {
           ChronoLocalDate date = chrono.dateNow();
           System.out.printf("   %20s: %s%n", chrono.getID(), date.toString());
       }

       // Print the Hijrah date and calendar
       ChronoLocalDate date = Chronology.of("Hijrah").dateNow();
       int day = date.get(ChronoField.DAY_OF_MONTH);
       int dow = date.get(ChronoField.DAY_OF_WEEK);
       int month = date.get(ChronoField.MONTH_OF_YEAR);
       int year = date.get(ChronoField.YEAR);
       System.out.printf("  Today is %s %s %d-%s-%d%n", date.getChronology().getID(),
               dow, day, month, year);

       // Print today's date and the last day of the year
       ChronoLocalDate now1 = Chronology.of("Hijrah").dateNow();
       ChronoLocalDate first = now1.with(ChronoField.DAY_OF_MONTH, 1)
               .with(ChronoField.MONTH_OF_YEAR, 1);
       ChronoLocalDate last = first.plus(1, ChronoUnit.YEARS)
               .minus(1, ChronoUnit.DAYS);
       System.out.printf("  Today is %s: start: %s; end: %s%n", last.getChronology().getID(),
               first, last);

Adding Calendars

The set of calendars is extensible by defining a subclass of ChronoLocalDate to represent a date instance and an implementation of Chronology to be the factory for the ChronoLocalDate subclass.

To permit the discovery of the additional calendar types the implementation of Chronology must be registered as a Service implementing the Chronology interface in the META-INF/Services file as per the specification of java.util.ServiceLoader. The subclass must function according to the Chronology class description and must provide its chronlogy ID and calendar type.

Implementation Specification

This abstract 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 long
serialVersionUID

Serialization version.

Constructor Summary

AccessConstructor and Description
pack-priv
ChronoLocalDateImpl()

Creates an instance.

Method Summary

Modifier and TypeMethod and Description
private long
pack-priv static <D extends ChronoLocalDate> D

Returns:

the date-time checked and cast to ChronoLocalDate, not null
ensureValid
(Chronology
the chronology to check for, not null
chrono
,
Temporal
a date-time to cast, not null
temporal
)

Casts the Temporal to ChronoLocalDate ensuring it bas the specified chronology.

public boolean
equals(Object obj)

Overrides java.lang.Object.equals.

Implements java.time.chrono.ChronoLocalDate.equals.

Checks if this date is equal to another date, including the chronology.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Implements java.time.chrono.ChronoLocalDate.hashCode.

A hash code for this date.

public D
minus(TemporalAmount amount)

Overrides default java.time.chrono.ChronoLocalDate.minus, java.time.temporal.Temporal.minus.

Returns an object of the same type as this object with an amount subtracted.

public D
minus(long amountToSubtract, TemporalUnit unit)

Overrides default java.time.chrono.ChronoLocalDate.minus, java.time.temporal.Temporal.minus.

Returns an object of the same type as this object with the specified period subtracted.

pack-priv D

Returns:

a date based on this one with the days subtracted, not null
minusDays
(long
the days to subtract, may be negative
daysToSubtract
)

Returns a copy of this date with the specified number of days subtracted.

pack-priv D

Returns:

a date based on this one with the months subtracted, not null
minusMonths
(long
the months to subtract, may be negative
monthsToSubtract
)

Returns a copy of this date with the specified number of months subtracted.

pack-priv D

Returns:

a date based on this one with the weeks subtracted, not null
minusWeeks
(long
the weeks to subtract, may be negative
weeksToSubtract
)

Returns a copy of this date with the specified number of weeks subtracted.

pack-priv D

Returns:

a date based on this one with the years subtracted, not null
minusYears
(long
the years to subtract, may be negative
yearsToSubtract
)

Returns a copy of this date with the specified number of years subtracted.

private long
public D
plus(TemporalAmount amount)

Overrides default java.time.chrono.ChronoLocalDate.plus, java.time.temporal.Temporal.plus.

Returns an object of the same type as this object with an amount added.

public D
plus(long amountToAdd, TemporalUnit unit)

Overrides default java.time.chrono.ChronoLocalDate.plus.

Implements java.time.temporal.Temporal.plus.

Returns an object of the same type as this object with the specified period added.

pack-priv abstract D

Returns:

a date based on this one with the days added, not null
plusDays
(long
the days to add, may be negative
daysToAdd
)

Returns a copy of this date with the specified number of days added.

pack-priv abstract D

Returns:

a date based on this one with the months added, not null
plusMonths
(long
the months to add, may be negative
monthsToAdd
)

Returns a copy of this date with the specified number of months added.

pack-priv D

Returns:

a date based on this one with the weeks added, not null
plusWeeks
(long
the weeks to add, may be negative
weeksToAdd
)

Returns a copy of this date with the specified number of weeks added.

pack-priv abstract D

Returns:

a date based on this one with the years added, not null
plusYears
(long
the years to add, may be negative
yearsToAdd
)

Returns a copy of this date with the specified number of years added.

public String
toString()

Overrides java.lang.Object.toString.

Implements java.time.chrono.ChronoLocalDate.toString.

Outputs this date as a String.

public long
until(Temporal endExclusive, TemporalUnit unit)

Implements java.time.chrono.ChronoLocalDate.until, java.time.temporal.Temporal.until.

Calculates the amount of time until another date in terms of the specified unit.

public D
with(TemporalAdjuster adjuster)

Overrides default java.time.chrono.ChronoLocalDate.with, java.time.temporal.Temporal.with.

Returns an adjusted object of the same type as this object with the adjustment made.

public D
with(TemporalField field, long value)

Overrides default java.time.chrono.ChronoLocalDate.with.

Implements java.time.temporal.Temporal.with.

Returns an object of the same type as this object with the specified field altered.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Serialization version.

Annotations
@Serial

Constructor Detail

ChronoLocalDateImplback to summary
pack-priv ChronoLocalDateImpl()

Creates an instance.

Method Detail

daysUntilback to summary
private long daysUntil(ChronoLocalDate end)
ensureValidback to summary
pack-priv static <D extends ChronoLocalDate> D ensureValid(Chronology chrono, Temporal temporal)

Casts the Temporal to ChronoLocalDate ensuring it bas the specified chronology.

Parameters
chrono:Chronology

the chronology to check for, not null

temporal:Temporal

a date-time to cast, not null

Returns:D

the date-time checked and cast to ChronoLocalDate, not null

Exceptions
ClassCastException:
if the date-time cannot be cast to ChronoLocalDate or the chronology is not equal this Chronology
equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Implements java.time.chrono.ChronoLocalDate.equals.

Doc from java.time.chrono.ChronoLocalDate.equals.

Checks if this date is equal to another date, including the chronology.

Compares this date with another ensuring that the date and chronology are the same.

To compare the dates of two TemporalAccessor instances, including dates in two different chronologies, use ChronoField#EPOCH_DAY as a comparator.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Implements java.time.chrono.ChronoLocalDate.hashCode.

Doc from java.time.chrono.ChronoLocalDate.hashCode.

A hash code for this date.

Annotations
@Override
minusback to summary
public D minus(TemporalAmount amount)

Overrides default java.time.chrono.ChronoLocalDate.minus, java.time.temporal.Temporal.minus.

Doc from java.time.chrono.ChronoLocalDate.minus.

Returns an object of the same type as this object with an amount subtracted.

This adjusts this temporal, subtracting according to the rules of the specified amount. The amount is typically a java.time.Period but may be any other type implementing the TemporalAmount interface, such as java.time.Duration.

Some example code indicating how and why this method is used:

 date = date.minus(period);               // subtract a Period instance
 date = date.minus(duration);             // subtract a Duration instance
 date = date.minus(workingDays(6));       // example user-written workingDays method

Note that calling plus followed by minus is not guaranteed to return the same date-time.

Annotations
@Override
@SuppressWarnings:unchecked
minusback to summary
public D minus(long amountToSubtract, TemporalUnit unit)

Overrides default java.time.chrono.ChronoLocalDate.minus, java.time.temporal.Temporal.minus.

Doc from java.time.chrono.ChronoLocalDate.minus.

Returns an object of the same type as this object with the specified period subtracted.

This method returns a new object based on this one with the specified period subtracted. For example, on a LocalDate, this could be used to subtract a number of years, months or days. The returned object will have the same observable type as this object.

In some cases, changing a field is not fully defined. For example, if the target object is a date representing the 31st March, then subtracting one month would be unclear. In cases like this, the field is responsible for resolving the result. Typically it will choose the previous valid date, which would be the last valid day of February in this example.

Annotations
@Override
@SuppressWarnings:unchecked
minusDaysback to summary
pack-priv D minusDays(long daysToSubtract)

Returns a copy of this date with the specified number of days subtracted.

This subtracts the specified period in days to the date.

The default implementation uses plusDays(long).

This instance is immutable and unaffected by this method call.

Parameters
daysToSubtract:long

the days to subtract, may be negative

Returns:D

a date based on this one with the days subtracted, not null

Annotations
@SuppressWarnings:unchecked
Exceptions
DateTimeException:
if the result exceeds the supported date range
minusMonthsback to summary
pack-priv D minusMonths(long monthsToSubtract)

Returns a copy of this date with the specified number of months subtracted.

This subtracts the specified period in months to the date. In some cases, subtracting months can cause the resulting date to become invalid. If this occurs, then other fields, typically the day-of-month, will be adjusted to ensure that the result is valid. Typically this will select the last valid day of the month.

The default implementation uses plusMonths(long).

This instance is immutable and unaffected by this method call.

Parameters
monthsToSubtract:long

the months to subtract, may be negative

Returns:D

a date based on this one with the months subtracted, not null

Annotations
@SuppressWarnings:unchecked
Exceptions
DateTimeException:
if the result exceeds the supported date range
minusWeeksback to summary
pack-priv D minusWeeks(long weeksToSubtract)

Returns a copy of this date with the specified number of weeks subtracted.

This subtracts the specified period in weeks to the date. In some cases, subtracting weeks can cause the resulting date to become invalid. If this occurs, then other fields will be adjusted to ensure that the result is valid.

The default implementation uses plusWeeks(long).

This instance is immutable and unaffected by this method call.

Parameters
weeksToSubtract:long

the weeks to subtract, may be negative

Returns:D

a date based on this one with the weeks subtracted, not null

Annotations
@SuppressWarnings:unchecked
Exceptions
DateTimeException:
if the result exceeds the supported date range
minusYearsback to summary
pack-priv D minusYears(long yearsToSubtract)

Returns a copy of this date with the specified number of years subtracted.

This subtracts the specified period in years to the date. In some cases, subtracting years can cause the resulting date to become invalid. If this occurs, then other fields, typically the day-of-month, will be adjusted to ensure that the result is valid. Typically this will select the last valid day of the month.

The default implementation uses plusYears(long).

This instance is immutable and unaffected by this method call.

Parameters
yearsToSubtract:long

the years to subtract, may be negative

Returns:D

a date based on this one with the years subtracted, not null

Annotations
@SuppressWarnings:unchecked
Exceptions
DateTimeException:
if the result exceeds the supported date range
monthsUntilback to summary
private long monthsUntil(ChronoLocalDate end)
plusback to summary
public D plus(TemporalAmount amount)

Overrides default java.time.chrono.ChronoLocalDate.plus, java.time.temporal.Temporal.plus.

Doc from java.time.chrono.ChronoLocalDate.plus.

Returns an object of the same type as this object with an amount added.

This adjusts this temporal, adding according to the rules of the specified amount. The amount is typically a java.time.Period but may be any other type implementing the TemporalAmount interface, such as java.time.Duration.

Some example code indicating how and why this method is used:

 date = date.plus(period);                // add a Period instance
 date = date.plus(duration);              // add a Duration instance
 date = date.plus(workingDays(6));        // example user-written workingDays method

Note that calling plus followed by minus is not guaranteed to return the same date-time.

Annotations
@Override
@SuppressWarnings:unchecked
plusback to summary
public D plus(long amountToAdd, TemporalUnit unit)

Overrides default java.time.chrono.ChronoLocalDate.plus.

Implements java.time.temporal.Temporal.plus.

Doc from java.time.chrono.ChronoLocalDate.plus.

Returns an object of the same type as this object with the specified period added.

This method returns a new object based on this one with the specified period added. For example, on a LocalDate, this could be used to add a number of years, months or days. The returned object will have the same observable type as this object.

In some cases, changing a field is not fully defined. For example, if the target object is a date representing the 31st January, then adding one month would be unclear. In cases like this, the field is responsible for resolving the result. Typically it will choose the previous valid date, which would be the last valid day of February in this example.

Annotations
@Override
@SuppressWarnings:unchecked
plusDaysback to summary
pack-priv abstract D plusDays(long daysToAdd)

Returns a copy of this date with the specified number of days added.

This adds the specified period in days to the date.

This instance is immutable and unaffected by this method call.

Parameters
daysToAdd:long

the days to add, may be negative

Returns:D

a date based on this one with the days added, not null

Exceptions
DateTimeException:
if the result exceeds the supported date range
plusMonthsback to summary
pack-priv abstract D plusMonths(long monthsToAdd)

Returns a copy of this date with the specified number of months added.

This adds the specified period in months to the date. In some cases, adding months can cause the resulting date to become invalid. If this occurs, then other fields, typically the day-of-month, will be adjusted to ensure that the result is valid. Typically this will select the last valid day of the month.

This instance is immutable and unaffected by this method call.

Parameters
monthsToAdd:long

the months to add, may be negative

Returns:D

a date based on this one with the months added, not null

Exceptions
DateTimeException:
if the result exceeds the supported date range
plusWeeksback to summary
pack-priv D plusWeeks(long weeksToAdd)

Returns a copy of this date with the specified number of weeks added.

This adds the specified period in weeks to the date. In some cases, adding weeks can cause the resulting date to become invalid. If this occurs, then other fields will be adjusted to ensure that the result is valid.

The default implementation uses plusDays(long) using a 7 day week.

This instance is immutable and unaffected by this method call.

Parameters
weeksToAdd:long

the weeks to add, may be negative

Returns:D

a date based on this one with the weeks added, not null

Exceptions
DateTimeException:
if the result exceeds the supported date range
plusYearsback to summary
pack-priv abstract D plusYears(long yearsToAdd)

Returns a copy of this date with the specified number of years added.

This adds the specified period in years to the date. In some cases, adding years can cause the resulting date to become invalid. If this occurs, then other fields, typically the day-of-month, will be adjusted to ensure that the result is valid. Typically this will select the last valid day of the month.

This instance is immutable and unaffected by this method call.

Parameters
yearsToAdd:long

the years to add, may be negative

Returns:D

a date based on this one with the years added, not null

Exceptions
DateTimeException:
if the result exceeds the supported date range
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Implements java.time.chrono.ChronoLocalDate.toString.

Doc from java.time.chrono.ChronoLocalDate.toString.

Outputs this date as a String.

The output will include the full local date.

Annotations
@Override
untilback to summary
public long until(Temporal endExclusive, TemporalUnit unit)

Implements java.time.chrono.ChronoLocalDate.until, java.time.temporal.Temporal.until.

Doc from java.time.chrono.ChronoLocalDate.until.

Calculates the amount of time until another date in terms of the specified unit.

This calculates the amount of time between two ChronoLocalDate objects in terms of a single TemporalUnit. The start and end points are this and the specified date. The result will be negative if the end is before the start. The Temporal passed to this method is converted to a ChronoLocalDate using Chronology#date(TemporalAccessor). The calculation returns a whole number, representing the number of complete units between the two dates. For example, the amount in days between two dates can be calculated using startDate.until(endDate, DAYS).

There are two equivalent ways of using this method. The first is to invoke this method. The second is to use TemporalUnit#between(Temporal, Temporal):

  // these two lines are equivalent
  amount = start.until(end, MONTHS);
  amount = MONTHS.between(start, end);
The choice should be made based on which makes the code more readable.

The calculation is implemented in this method for ChronoUnit. The units DAYS, WEEKS, MONTHS, YEARS, DECADES, CENTURIES, MILLENNIA and ERAS should be supported by all implementations. Other ChronoUnit values will throw an exception.

If the unit is not a ChronoUnit, then the result of this method is obtained by invoking TemporalUnit.between(Temporal, Temporal) passing this as the first argument and the converted input temporal as the second argument.

This instance is immutable and unaffected by this method call.

Annotations
@Override
withback to summary
public D with(TemporalAdjuster adjuster)

Overrides default java.time.chrono.ChronoLocalDate.with, java.time.temporal.Temporal.with.

Doc from java.time.chrono.ChronoLocalDate.with.

Returns an adjusted object of the same type as this object with the adjustment made.

This adjusts this date-time according to the rules of the specified adjuster. A simple adjuster might simply set the one of the fields, such as the year field. A more complex adjuster might set the date to the last day of the month. A selection of common adjustments is provided in TemporalAdjusters. These include finding the "last day of the month" and "next Wednesday". The adjuster is responsible for handling special cases, such as the varying lengths of month and leap years.

Some example code indicating how and why this method is used:

 date = date.with(Month.JULY);        // most key classes implement TemporalAdjuster
 date = date.with(lastDayOfMonth());  // static import from Adjusters
 date = date.with(next(WEDNESDAY));   // static import from Adjusters and DayOfWeek
Annotations
@Override
@SuppressWarnings:unchecked
withback to summary
public D with(TemporalField field, long value)

Overrides default java.time.chrono.ChronoLocalDate.with.

Implements java.time.temporal.Temporal.with.

Doc from java.time.chrono.ChronoLocalDate.with.

Returns an object of the same type as this object with the specified field altered.

This returns a new object based on this one with the value for the specified field changed. For example, on a LocalDate, this could be used to set the year, month or day-of-month. The returned object will have the same observable type as this object.

In some cases, changing a field is not fully defined. For example, if the target object is a date representing the 31st January, then changing the month to February would be unclear. In cases like this, the field is responsible for resolving the result. Typically it will choose the previous valid date, which would be the last valid day of February in this example.

Annotations
@Override
@SuppressWarnings:unchecked