trait ChronoPeriod extends TemporalAmount
A date-based amount of time, such as '3 years, 4 months and 5 days' in an arbitrary chronology, intended for advanced globalization use cases.
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.
Specification for implementors
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.
- Alphabetic
- By Inheritance
- ChronoPeriod
- TemporalAmount
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Abstract Value Members
- abstract def addTo(temporal: Temporal): Temporal
Adds this period to the specified temporal object.
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
Temporal#plus(TemporalAmount)
.// 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.
- temporal
the temporal object to adjust, not null
- returns
an object of the same type with the adjustment made, not null
- Definition Classes
- ChronoPeriod → TemporalAmount
- Exceptions thrown
ArithmeticException
if numeric overflow occursDateTimeException
if unable to add
- abstract def get(unit: TemporalUnit): Long
Gets the value of the requested unit.
Gets the value of the requested unit.
The supported units are chronology specific. They will typically be
YEARS
,MONTHS
andDAYS
. Requesting an unsupported unit will throw an exception.- unit
the { @code TemporalUnit} for which to return the value
- returns
the long value of the unit
- Definition Classes
- ChronoPeriod → TemporalAmount
- Exceptions thrown
DateTimeException
if the unit is not supportedUnsupportedTemporalTypeException
if the unit is not supported
- abstract def getChronology: Chronology
Gets the chronology that defines the meaning of the supported units.
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
ChronoLocalDate
instances of the same chronology.- returns
the chronology defining the period, not null
- abstract def getUnits: List[TemporalUnit]
Gets the set of units supported by this period.
Gets the set of units supported by this period.
The supported units are chronology specific. They will typically be
YEARS
,MONTHS
andDAYS
. They are returned in order from largest to smallest.This set can be used in conjunction with
#get(TemporalUnit)
to access the entire state of the period.- returns
a list containing the supported units, not null
- Definition Classes
- ChronoPeriod → TemporalAmount
- abstract def minus(amountToSubtract: TemporalAmount): ChronoPeriod
Returns a copy of this period with the specified period subtracted.
Returns a copy of this period with the specified period subtracted.
If the specified amount is a
ChronoPeriod
then it must have the same chronology as this period. Implementations may choose to accept or reject otherTemporalAmount
implementations.This instance is immutable and unaffected by this method call.
- amountToSubtract
the period to subtract, not null
- returns
a { @code ChronoPeriod} based on this period with the requested period subtracted, not null
- Exceptions thrown
ArithmeticException
if numeric overflow occurs
- abstract def multipliedBy(scalar: Int): ChronoPeriod
Returns a new instance with each amount in this period in this period multiplied by the specified 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.
- scalar
the scalar to multiply by, not null
- returns
a { @code ChronoPeriod} based on this period with the amounts multiplied by the scalar, not null
- Exceptions thrown
ArithmeticException
if numeric overflow occurs
- abstract def normalized: ChronoPeriod
Returns a copy of this period with the amounts of each unit 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.
- returns
a { @code ChronoPeriod} based on this period with the amounts of each unit normalized, not null
- Exceptions thrown
ArithmeticException
if numeric overflow occurs
- abstract def plus(amountToAdd: TemporalAmount): ChronoPeriod
Returns a copy of this period with the specified period added.
Returns a copy of this period with the specified period added.
If the specified amount is a
ChronoPeriod
then it must have the same chronology as this period. Implementations may choose to accept or reject otherTemporalAmount
implementations.This instance is immutable and unaffected by this method call.
- amountToAdd
the period to add, not null
- returns
a { @code ChronoPeriod} based on this period with the requested period added, not null
- Exceptions thrown
ArithmeticException
if numeric overflow occurs
- abstract def subtractFrom(temporal: Temporal): Temporal
Subtracts this period from the specified temporal object.
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
Temporal#minus(TemporalAmount)
.// 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.
- temporal
the temporal object to adjust, not null
- returns
an object of the same type with the adjustment made, not null
- Definition Classes
- ChronoPeriod → TemporalAmount
- Exceptions thrown
ArithmeticException
if numeric overflow occursDateTimeException
if unable to subtract
Concrete Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##(): Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def isNegative: Boolean
Checks if any of the supported units of this period are negative.
Checks if any of the supported units of this period are negative.
- returns
true if any unit of this period is negative
- def isZero: Boolean
Checks if all the supported units of this period are zero.
Checks if all the supported units of this period are zero.
- returns
true if this period is zero-length
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def negated: ChronoPeriod
Returns a new instance with each amount in this period 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.
- returns
a { @code ChronoPeriod} based on this period with the amounts negated, not null
- Exceptions thrown
ArithmeticException
if numeric overflow occurs, which only happens if one of the units has the value { @code Long.MIN_VALUE}
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()