The natural ordering of durations matches the natural ordering for Double, including non-finite values.
Infinite duration: greater than any other (apart from Undefined) and not equal to any other but itself.
Infinite duration: greater than any other (apart from Undefined) and not equal to any other but itself. This value closely corresponds to Double.PositiveInfinity, matching its semantics in arithmetic operations.
Infinite duration: less than any other and not equal to any other but itself.
Infinite duration: less than any other and not equal to any other but itself. This value closely corresponds to Double.NegativeInfinity, matching its semantics in arithmetic operations.
The Undefined value corresponds closely to Double.
The Undefined value corresponds closely to Double.NaN:
equals()
)compare
returns 0)The particular comparison semantics mirror those of Double.NaN.
Use eq
when checking an input of a method against this value.
Preconstructed value of 0.days
.
Parse String into Duration.
Parse String into Duration. Format is "<length><unit>"
, where
whitespace is allowed before, between and after the parts. Infinities are
designated by "Inf"
, "PlusInf"
, "+Inf"
and "-Inf"
or "MinusInf"
.
if format is not parseable
Construct a finite duration from the given length and time unit, where the latter is looked up in a list of string representation.
Construct a finite duration from the given length and time unit, where the latter is looked up in a list of string representation. Valid choices are:
d, day, h, hour, min, minute, s, sec, second, ms, milli, millisecond, µs, micro, microsecond, ns, nano, nanosecond
and their pluralized forms (for every but the first mentioned form of each unit, i.e. no "ds", but "days").
Construct a finite duration from the given length and time unit.
Construct a finite duration from the given length and time unit. The unit given is retained throughout calculations as long as possible, so that it can be retrieved later.
Construct a Duration from the given length and unit.
Construct a Duration from the given length and unit. Observe that nanosecond precision may be lost if
Infinite inputs (and NaN) are converted into Duration.Inf, Duration.MinusInf and Duration.Undefined, respectively.
if the length was finite but the resulting duration cannot be expressed as a FiniteDuration
Parse String into Duration.
Parse String into Duration. Format is "<length><unit>"
, where
whitespace is allowed before, between and after the parts. Infinities are
designated by "Inf"
, "PlusInf"
, "+Inf"
and "-Inf"
or "MinusInf"
.
if format is not parseable
Construct a finite duration from the given length and time unit, where the latter is looked up in a list of string representation.
Construct a finite duration from the given length and time unit, where the latter is looked up in a list of string representation. Valid choices are:
d, day, h, hour, min, minute, s, sec, second, ms, milli, millisecond, µs, micro, microsecond, ns, nano, nanosecond
and their pluralized forms (for every but the first mentioned form of each unit, i.e. no "ds", but "days").
Construct a Duration from the given length and unit.
Construct a Duration from the given length and unit. Observe that nanosecond precision may be lost if
Infinite inputs (and NaN) are converted into Duration.Inf, Duration.MinusInf and Duration.Undefined, respectively.
if the length was finite but the resulting duration cannot be expressed as a FiniteDuration
Construct a finite duration from the given length and time unit.
Construct a finite duration from the given length and time unit. The unit given is retained throughout calculations as long as possible, so that it can be retrieved later.
Construct a finite duration from the given number of nanoseconds.
Construct a finite duration from the given number of nanoseconds. The result will have the coarsest possible time unit which can exactly express this duration.
for Long.MinValue
since that would lead to inconsistent behavior afterwards (cannot be negated)
Construct a possibly infinite or undefined Duration from the given number of nanoseconds.
Construct a possibly infinite or undefined Duration from the given number of nanoseconds.
Double.PositiveInfinity
is mapped to Duration.InfDouble.NegativeInfinity
is mapped to Duration.MinusInfDouble.NaN
is mapped to Duration.Undefined-0d
is mapped to Duration.Zero (exactly like 0d
)The semantics of the resulting Duration objects matches the semantics of their Double counterparts with respect to arithmetic operations.
if the length was finite but the resulting duration cannot be expressed as a FiniteDuration
Extract length and time unit out of a duration, if it is finite.
Extract length and time unit out of a string, where the format must match the description for apply(String).
Extract length and time unit out of a string, where the format must match the description for apply(String). The extractor will not match for malformed strings or non-finite durations.