@Immutable public final class CqlDuration extends Object implements TemporalAmount, Serializable
It stores months, days, and seconds separately due to the fact that the number of days in a
month varies, and a day can have 23 or 25 hours if a daylight saving is involved. As such, this
type differs from Duration (which only represents an amount between two points
in time, regardless of the calendar).
| Modifier and Type | Method and Description |
|---|---|
Temporal |
addTo(Temporal temporal) |
boolean |
equals(Object other) |
static CqlDuration |
from(String input)
Converts a
String into a duration. |
long |
get(TemporalUnit unit) |
int |
getDays()
Returns the number of days in this duration.
|
int |
getMonths()
Returns the number of months in this duration.
|
long |
getNanoseconds()
Returns the number of nanoseconds in this duration.
|
List<TemporalUnit> |
getUnits() |
int |
hashCode() |
static CqlDuration |
newInstance(int months,
int days,
long nanoseconds)
Creates a duration with the given number of months, days and nanoseconds.
|
Temporal |
subtractFrom(Temporal temporal) |
String |
toString() |
public static CqlDuration newInstance(int months, int days, long nanoseconds)
A duration can be negative. In this case, all the non zero values must be negative.
months - the number of monthsdays - the number of daysnanoseconds - the number of nanosecondsIllegalArgumentException - if the values are not all negative or all positivepublic static CqlDuration from(@NonNull String input)
String into a duration.
The accepted formats are:
y: years
mo: months
w: weeks
d: days
h: hours
m: minutes
s: seconds
ms: milliseconds
us or µs: microseconds
ns: nanoseconds
input - the String to convertpublic int getMonths()
public int getDays()
public long getNanoseconds()
public Temporal addTo(Temporal temporal)
This implementation converts the months and days components to a Period, and the
nanosecond component to a Duration, and adds those two amounts to the temporal object.
Therefore the chronology of the temporal must be either the ISO chronology or null.
addTo in interface TemporalAmountPeriod.addTo(Temporal),
Duration.addTo(Temporal)public Temporal subtractFrom(Temporal temporal)
This implementation converts the months and days components to a Period, and the
nanosecond component to a Duration, and subtracts those two amounts to the temporal
object. Therefore the chronology of the temporal must be either the ISO chronology or null.
subtractFrom in interface TemporalAmountPeriod.subtractFrom(Temporal),
Duration.subtractFrom(Temporal)public long get(TemporalUnit unit)
get in interface TemporalAmountpublic List<TemporalUnit> getUnits()
getUnits in interface TemporalAmountCopyright © 2017–2023. All rights reserved.