This interface models a date-based amount of time in a calendar system.
While most calendar systems use years, months and days, some do not.
Therefore, this interface operates solely in terms of a set of supported
units that are defined by the Chronology
.
The set of supported units is fixed for a given chronology.
The amount of a supported unit may be set to zero.
The period is modeled as a directed amount of time, meaning that individual parts of the period may be negative.
Implementation Specification
This interface 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.
Modifier and Type | Method and Description |
---|---|
public Temporal | Returns: an object of the same type with the adjustment made, not nullthe temporal object to adjust, not null temporal)Redeclares java. Adds this period to the specified temporal object. |
public static ChronoPeriod | Returns: the period between this date and the end date, not nullthe start date, inclusive, specifying the chronology of the calculation, not null startDateInclusive, ChronoLocalDate the end date, exclusive, in any chronology, not null endDateExclusive)Obtains a |
public boolean | |
public long | Returns: the long value of the unitthe unit)TemporalUnit for which to return the valueRedeclares java. Gets the value of the requested unit. |
public Chronology | Returns: the chronology defining the period, not nullGets the chronology that defines the meaning of the supported units. |
public List | Returns: a list containing the supported units, not nullRedeclares java. Gets the set of units supported by this period. |
public int | |
public default boolean | Returns: true if any unit of this period is negativeChecks if any of the supported units of this period are negative. |
public default boolean | Returns: true if this period is zero-lengthChecks if all the supported units of this period are zero. |
public ChronoPeriod | Returns: aChronoPeriod based on this period with the requested period subtracted, not nullthe period to subtract, not null amountToSubtract)Returns a copy of this period with the specified period subtracted. |
public ChronoPeriod | Returns: aChronoPeriod based on this period with the amounts multiplied
by the scalar, not nullthe scalar to multiply by, not null scalar)Returns a new instance with each amount in this period in this period multiplied by the specified scalar. |
public default ChronoPeriod | Returns: aChronoPeriod based on this period with the amounts negated, not nullReturns a new instance with each amount in this period negated. |
public ChronoPeriod | Returns: aChronoPeriod based on this period with the amounts of each
unit normalized, not nullReturns a copy of this period with the amounts of each unit normalized. |
public ChronoPeriod | Returns: aChronoPeriod based on this period with the requested period added, not nullthe period to add, not null amountToAdd)Returns a copy of this period with the specified period added. |
public Temporal | Returns: an object of the same type with the adjustment made, not nullthe temporal object to adjust, not null temporal)Redeclares java. Subtracts this period from the specified temporal object. |
public String |
addTo | back to summary |
---|---|
public Temporal addTo(Temporal temporal) Redeclares java. Adds this period to the specified temporal object. This returns a temporal object of the same observable type as the input with this period added.
In most cases, it is clearer to reverse the calling pattern by using
// these two lines are equivalent, but the second approach is recommended dateTime = thisPeriod.addTo(dateTime); dateTime = dateTime.plus(thisPeriod); The specified temporal must have the same chronology as this period. This returns a temporal with the non-zero supported units added. This instance is immutable and unaffected by this method call.
|
between | back to summary |
---|---|
public static ChronoPeriod between(ChronoLocalDate startDateInclusive, ChronoLocalDate endDateExclusive) Obtains a
The start date is included, but the end date is not.
The period is calculated using The chronology of the first date is used. The chronology of the second date is ignored, with the date being converted to the target chronology system before the calculation starts. The result of this method can be a negative period if the end is before the start. In most cases, the positive/negative sign will be the same in each of the supported fields.
|
equals | back to summary |
---|---|
public boolean equals(Object obj) Checks if this period is equal to another period, including the chronology. Compares this period with another ensuring that the type, each amount and the chronology are the same. Note that this means that a period of "15 Months" is not equal to a period of "1 Year and 3 Months". |
get | back to summary |
---|---|
public long get(TemporalUnit unit) Redeclares java. Gets the value of the requested unit.
The supported units are chronology specific.
They will typically be
|
getChronology | back to summary |
---|---|
public Chronology getChronology() Gets the chronology that defines the meaning of the supported units.
The period is defined by the chronology.
It controls the supported units and restricts addition/subtraction
to
|
getUnits | back to summary |
---|---|
public List Redeclares java. Gets the set of units supported by this period.
The supported units are chronology specific.
They will typically be
This set can be used in conjunction with
|
hashCode | back to summary |
---|---|
public int hashCode() A hash code for this period.
|
isNegative | back to summary |
---|---|
public default boolean isNegative() Checks if any of the supported units of this period are negative.
|
isZero | back to summary |
---|---|
public default boolean isZero() Checks if all the supported units of this period are zero.
|
minus | back to summary |
---|---|
public ChronoPeriod minus(TemporalAmount amountToSubtract) Returns a copy of this period with the specified period subtracted.
If the specified amount is a This instance is immutable and unaffected by this method call.
|
multipliedBy | back to summary |
---|---|
public ChronoPeriod multipliedBy(int scalar) Returns a new instance with each amount in this period in this period multiplied by the specified scalar. This returns a period with each supported unit individually multiplied. For example, a period of "2 years, -3 months and 4 days" multiplied by 3 will return "6 years, -9 months and 12 days". No normalization is performed.
|
negated | back to summary |
---|---|
public default ChronoPeriod negated() Returns a new instance with each amount in this period negated. This returns a period with each supported unit individually negated. For example, a period of "2 years, -3 months and 4 days" will be negated to "-2 years, 3 months and -4 days". No normalization is performed.
|
normalized | back to summary |
---|---|
public ChronoPeriod normalized() Returns a copy of this period with the amounts of each unit normalized. The process of normalization is specific to each calendar system. For example, in the ISO calendar system, the years and months are normalized but the days are not, such that "15 months" would be normalized to "1 year and 3 months". This instance is immutable and unaffected by this method call.
|
plus | back to summary |
---|---|
public ChronoPeriod plus(TemporalAmount amountToAdd) Returns a copy of this period with the specified period added.
If the specified amount is a This instance is immutable and unaffected by this method call.
|
subtractFrom | back to summary |
---|---|
public Temporal subtractFrom(Temporal temporal) Redeclares java. Subtracts this period from the specified temporal object. This returns a temporal object of the same observable type as the input with this period subtracted.
In most cases, it is clearer to reverse the calling pattern by using
// these two lines are equivalent, but the second approach is recommended dateTime = thisPeriod.subtractFrom(dateTime); dateTime = dateTime.minus(thisPeriod); The specified temporal must have the same chronology as this period. This returns a temporal with the non-zero supported units subtracted. This instance is immutable and unaffected by this method call.
|
toString | back to summary |
---|---|
public String toString() Outputs this period as a The output will include the period amounts and chronology. |