C - the chronology of this date-timepublic abstract class DefaultInterfaceChronoLocalDate<C extends Chrono<C>> extends DefaultInterfaceTemporal implements ChronoLocalDate<C>
DATE_COMPARATOR| Constructor and Description |
|---|
DefaultInterfaceChronoLocalDate() |
| Modifier and Type | Method and Description |
|---|---|
Temporal |
adjustInto(Temporal temporal)
Adjusts the specified temporal object.
|
ChronoLocalDateTime<C> |
atTime(LocalTime localTime)
Returns a date-time formed from this date at the specified time.
|
int |
compareTo(ChronoLocalDate<?> other)
Compares this date to another date, including the chronology.
|
boolean |
equals(Object obj)
Checks if this date is equal to another date, including the chronology.
|
Era<C> |
getEra()
Gets the era, as defined by the chronology.
|
int |
hashCode()
A hash code for this date.
|
boolean |
isAfter(ChronoLocalDate<?> other)
Checks if this date is after the specified date ignoring the chronology.
|
boolean |
isBefore(ChronoLocalDate<?> other)
Checks if this date is before the specified date ignoring the chronology.
|
boolean |
isEqual(ChronoLocalDate<?> other)
Checks if this date is equal to the specified date ignoring the chronology.
|
boolean |
isLeapYear()
Checks if the year is a leap year, as defined by the calendar system.
|
boolean |
isSupported(TemporalField field)
Checks if the specified field is supported.
|
int |
lengthOfYear()
Returns the length of the year represented by this date, as defined by the calendar system.
|
ChronoLocalDate<C> |
minus(long amountToSubtract,
TemporalUnit unit)
Returns an object of the same type as this object with the specified period subtracted.
|
ChronoLocalDate<C> |
minus(TemporalSubtractor adjuster)
Returns an object of the same type as this object with an amount subtracted.
|
ChronoLocalDate<C> |
plus(TemporalAdder adjuster)
Returns an object of the same type as this object with an amount added.
|
<R> R |
query(TemporalQuery<R> query)
Queries this date-time.
|
long |
toEpochDay()
Converts this date to the Epoch Day.
|
String |
toString()
Outputs this date as a
String. |
String |
toString(DateTimeFormatter formatter)
Outputs this date-time as a
String using the formatter. |
ChronoLocalDate<C> |
with(TemporalAdjuster adjuster)
Returns an adjusted object of the same type as this object with the adjustment made.
|
get, rangeclone, finalize, getClass, notify, notifyAll, wait, wait, waitgetChrono, lengthOfMonth, plus, withperiodUntilget, getLong, rangepublic DefaultInterfaceChronoLocalDate()
public Era<C> getEra()
ChronoLocalDate
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 Chrono.
All correctly implemented Era classes are singletons, thus it
is valid code to write date.getEra() == SomeChrono.ERA_NAME).
getEra in interface ChronoLocalDate<C extends Chrono<C>>public boolean isLeapYear()
ChronoLocalDateA leap-year is a year of a longer length than normal. The exact meaning is determined by the chronology with the constraint that a leap-year must imply a year-length longer than a non leap-year.
The default implementation uses Chrono.isLeapYear(long).
isLeapYear in interface ChronoLocalDate<C extends Chrono<C>>public int lengthOfYear()
ChronoLocalDateThis returns the length of the year in days.
The default implementation uses ChronoLocalDate.isLeapYear() and returns 365 or 366.
lengthOfYear in interface ChronoLocalDate<C extends Chrono<C>>public boolean isSupported(TemporalField field)
TemporalAccessor
This checks if the date-time can be queried for the specified field.
If false, then calling the range and get
methods will throw an exception.
ChronoField.
If the field is supported, then true is returned, otherwise false
If the field is not a ChronoField, then the result of this method
is obtained by invoking TemporalField.doIsSupported(TemporalAccessor)
passing this as the argument.
Implementations must not alter either this object.
isSupported in interface TemporalAccessorfield - the field to check, null returns falsepublic ChronoLocalDate<C> with(TemporalAdjuster adjuster)
Temporal
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 TemporalAdjusters date = date.with(next(WEDNESDAY)); // static import from TemporalAdjusters and DayOfWeek
with in interface ChronoLocalDate<C extends Chrono<C>>with in interface Temporalwith in class DefaultInterfaceTemporaladjuster - the adjuster to use, not nullpublic ChronoLocalDate<C> plus(TemporalAdder adjuster)
Temporal
This adjusts this temporal, adding according to the rules of the specified adder.
The adder is typically a Period but may be any other type implementing
the TemporalAdder interface, such as 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(MONTHS.between(start, end)); // static import of MONTHS field 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.
plus in interface ChronoLocalDate<C extends Chrono<C>>plus in interface Temporalplus in class DefaultInterfaceTemporaladjuster - the adder to use, not nullpublic ChronoLocalDate<C> minus(TemporalSubtractor adjuster)
Temporal
This adjusts this temporal, subtracting according to the rules of the specified subtractor.
The subtractor is typically a Period but may be any other type implementing
the TemporalSubtractor interface, such as 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(MONTHS.between(start, end)); // static import of MONTHS field 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.
minus in interface ChronoLocalDate<C extends Chrono<C>>minus in interface Temporalminus in class DefaultInterfaceTemporaladjuster - the subtractor to use, not nullpublic ChronoLocalDate<C> minus(long amountToSubtract, TemporalUnit unit)
Temporal
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.
If the implementation represents a date-time that has boundaries, such as LocalTime,
then the permitted units must include the boundary unit, but no multiples of the boundary unit.
For example, LocalTime must accept DAYS but not WEEKS or MONTHS.
Implementations must not alter either this object or the specified temporal object. Instead, an adjusted copy of the original must be returned. This provides equivalent, safe behavior for immutable and mutable implementations.
minus in interface ChronoLocalDate<C extends Chrono<C>>minus in interface Temporalminus in class DefaultInterfaceTemporalamountToSubtract - the amount of the specified unit to subtract, may be negativeunit - the unit of the period to subtract, not nullpublic Temporal adjustInto(Temporal temporal)
TemporalAdjusterThis adjusts the specified temporal object using the logic encapsulated in the implementing class. Examples might be an adjuster that sets the date avoiding weekends, or one that sets the date to the last day of the month.
There are two equivalent ways of using this method.
The first is to invoke this method directly.
The second is to use Temporal.with(TemporalAdjuster):
// these two lines are equivalent, but the second approach is recommended temporal = thisAdjuster.adjustInto(temporal); temporal = temporal.with(thisAdjuster);It is recommended to use the second approach,
with(TemporalAdjuster),
as it is a lot clearer to read in code.
Temporal to
query the temporal object and perform the adjustment.
The returned object must have the same observable type as the input object
The input object must not be altered. Instead, an adjusted copy of the original must be returned. This provides equivalent, safe behavior for immutable and mutable temporal objects.
The input temporal object may be in a calendar system other than ISO.
Implementations may choose to document compatibility with other calendar systems,
or reject non-ISO temporal objects by querying the chronology.
This method may be called from multiple threads in parallel. It must be thread-safe when invoked.
adjustInto in interface TemporalAdjustertemporal - the temporal object to adjust, not nullpublic ChronoLocalDateTime<C> atTime(LocalTime localTime)
ChronoLocalDate
This merges the two objects - this and the specified time -
to form an instance of ChronoLocalDateTime.
This instance is immutable and unaffected by this method call.
atTime in interface ChronoLocalDate<C extends Chrono<C>>localTime - the local time to use, not nullpublic <R> R query(TemporalQuery<R> query)
TemporalAccessorThis queries this date-time using the specified query strategy object.
Queries are a key tool for extracting information from date-times. They exists to externalize the process of querying, permitting different approaches, as per the strategy design pattern. Examples might be a query that checks if the date is the day before February 29th in a leap year, or calculates the number of days to your next birthday.
The most common query implementations are method references, such as
LocalDate::from and ZoneId::from.
Further implementations are on TemporalQueries.
Queries may also be defined by applications.
public <R> R query(TemporalQuery<R> type) {
// only include an if statement if the implementation can return it
if (query == TemporalQueries.zoneId()) return // the ZoneId
if (query == TemporalQueries.chrono()) return // the Chrono
if (query == TemporalQueries.precision()) return // the precision
// call default method
return super.query(query);
}
query in interface TemporalAccessorquery in class DefaultInterfaceTemporalAccessorR - the type of the resultquery - the query to invoke, not nullpublic long toEpochDay()
ChronoLocalDate
The Epoch Day count is a simple
incrementing count of days where day 0 is 1970-01-01 (ISO).
This definition is the same for all chronologies, enabling conversion.
toEpochDay in interface ChronoLocalDate<C extends Chrono<C>>public int compareTo(ChronoLocalDate<?> other)
ChronoLocalDate
The comparison is based first on the underlying time-line date, then
on the chronology.
It is "consistent with equals", as defined by Comparable.
For example, the following is the comparator order:
2012-12-03 (ISO)2012-12-04 (ISO)2555-12-04 (ThaiBuddhist)2012-12-05 (ISO)
If all the date objects being compared are in the same chronology, then the
additional chronology stage is not required and only the local date is used.
To compare the dates of two DateTimeAccessor instances, including dates
in two different chronologies, use ChronoField.EPOCH_DAY as a comparator.
compareTo in interface Comparable<ChronoLocalDate<?>>compareTo in interface ChronoLocalDate<C extends Chrono<C>>other - the other date to compare to, not nullpublic boolean isAfter(ChronoLocalDate<?> other)
ChronoLocalDate
This method differs from the comparison in ChronoLocalDate.compareTo(org.threeten.bp.temporal.ChronoLocalDate<?>) in that it
only compares the underlying date and not the chronology.
This allows dates in different calendar systems to be compared based
on the time-line position.
This is equivalent to using date1.toEpochDay() > date2.toEpochDay().
isAfter in interface ChronoLocalDate<C extends Chrono<C>>other - the other date to compare to, not nullpublic boolean isBefore(ChronoLocalDate<?> other)
ChronoLocalDate
This method differs from the comparison in ChronoLocalDate.compareTo(org.threeten.bp.temporal.ChronoLocalDate<?>) in that it
only compares the underlying date and not the chronology.
This allows dates in different calendar systems to be compared based
on the time-line position.
This is equivalent to using date1.toEpochDay() < date2.toEpochDay().
isBefore in interface ChronoLocalDate<C extends Chrono<C>>other - the other date to compare to, not nullpublic boolean isEqual(ChronoLocalDate<?> other)
ChronoLocalDate
This method differs from the comparison in ChronoLocalDate.compareTo(org.threeten.bp.temporal.ChronoLocalDate<?>) in that it
only compares the underlying date and not the chronology.
This allows dates in different calendar systems to be compared based
on the time-line position.
This is equivalent to using date1.toEpochDay() == date2.toEpochDay().
isEqual in interface ChronoLocalDate<C extends Chrono<C>>other - the other date to compare to, not nullpublic boolean equals(Object obj)
ChronoLocalDateCompares this date with another ensuring that the date and chronology are the same.
To compare the dates of two DateTimeAccessor instances, including dates
in two different chronologies, use ChronoField.EPOCH_DAY as a comparator.
public int hashCode()
ChronoLocalDatepublic String toString()
ChronoLocalDateString.
The output will include the full local date and the chronology ID.
public String toString(DateTimeFormatter formatter)
ChronoLocalDateString using the formatter.toString in interface ChronoLocalDate<C extends Chrono<C>>formatter - the formatter to use, not nullCopyright © 2007-2013 ThreeTen.org. All Rights Reserved.