Duration

scala.concurrent.duration.Duration
See theDuration companion class
object Duration

Attributes

Companion
class
Source
Duration.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Duration.type

Members list

Type members

Classlikes

The natural ordering of durations matches the natural ordering for Double, including non-finite values.

The natural ordering of durations matches the natural ordering for Double, including non-finite values.

Attributes

Source
Duration.scala
Supertypes
trait Equiv[Duration]
trait Serializable
class Object
trait Matchable
class Any
Show all
Self type
sealed abstract class Infinite extends Duration

Attributes

Source
Duration.scala
Supertypes
class Duration
trait Ordered[Duration]
trait Serializable
class Object
trait Matchable
class Any
Show all

Value members

Concrete methods

def apply(length: Double, unit: TimeUnit): Duration

Constructs a Duration from the given length and unit. Observe that nanosecond precision may be lost if

Constructs a Duration from the given length and unit. Observe that nanosecond precision may be lost if

  • the unit is NANOSECONDS
  • and the length has an absolute value greater than 2^53

Infinite inputs (and NaN) are converted into Duration.Inf, Duration.MinusInf and Duration.Undefined, respectively.

Value parameters

length

the duration length as a floating-point number

unit

the time unit in which length is measured

Attributes

Returns

a duration representing the given length in the given unit, possibly infinite or undefined

Throws
IllegalArgumentException

if the length was finite but the resulting duration cannot be expressed as a FiniteDuration

Source
Duration.scala
def apply(length: Long, unit: TimeUnit): FiniteDuration

Constructs 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.

Constructs 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.

Value parameters

length

the duration length as a whole number

unit

the time unit in which length is measured

Attributes

Source
Duration.scala
def apply(length: Long, unit: String): FiniteDuration

Constructs 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:

Constructs 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, hr, hour, m, 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").

Value parameters

length

the duration length as a whole number

unit

the string representation of the time unit (e.g. "ms", "second", "days")

Attributes

Returns

a finite duration of the given length with the resolved time unit

Source
Duration.scala
def apply(s: String): Duration

Parses String into Duration. Format is "", where whitespace is allowed before, between and after the parts. Infinities are designated by "Inf", "PlusInf", "+Inf", "Duration.Inf" and "-Inf", "MinusInf" or "Duration.MinusInf". Undefined is designated by "Duration.Undefined".

Parses String into Duration. Format is "", where whitespace is allowed before, between and after the parts. Infinities are designated by "Inf", "PlusInf", "+Inf", "Duration.Inf" and "-Inf", "MinusInf" or "Duration.MinusInf". Undefined is designated by "Duration.Undefined".

Value parameters

s

the string to parse into a duration

Attributes

Throws
NumberFormatException

if format is not parsable

Source
Duration.scala
def create(length: Long, unit: TimeUnit): FiniteDuration

Constructs 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.

Constructs 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.

Value parameters

length

the duration length as a whole number

unit

the time unit in which length is measured

Attributes

Source
Duration.scala
def create(length: Double, unit: TimeUnit): Duration

Constructs a Duration from the given length and unit. Observe that nanosecond precision may be lost if

Constructs a Duration from the given length and unit. Observe that nanosecond precision may be lost if

  • the unit is NANOSECONDS
  • and the length has an absolute value greater than 2^53

Infinite inputs (and NaN) are converted into Duration.Inf, Duration.MinusInf and Duration.Undefined, respectively.

Value parameters

length

the duration length as a floating-point number

unit

the time unit in which length is measured

Attributes

Returns

a duration representing the given length in the given unit, possibly infinite or undefined

Throws
IllegalArgumentException

if the length was finite but the resulting duration cannot be expressed as a FiniteDuration

Source
Duration.scala
def create(length: Long, unit: String): FiniteDuration

Constructs 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:

Constructs 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").

Value parameters

length

the duration length as a whole number

unit

the string representation of the time unit (e.g. "ms", "second", "days")

Attributes

Returns

a finite duration of the given length with the resolved time unit

Source
Duration.scala

Parses String into Duration. Format is "", where whitespace is allowed before, between and after the parts. Infinities are designated by "Inf", "PlusInf", "+Inf" and "-Inf" or "MinusInf".

Parses String into Duration. Format is "", where whitespace is allowed before, between and after the parts. Infinities are designated by "Inf", "PlusInf", "+Inf" and "-Inf" or "MinusInf".

Value parameters

s

the string to parse into a duration

Attributes

Throws
NumberFormatException

if format is not parsable

Source
Duration.scala
def fromNanos(nanos: Double): Duration

Constructs a possibly infinite or undefined Duration from the given number of nanoseconds.

Constructs a possibly infinite or undefined Duration from the given number of nanoseconds.

The semantics of the resulting Duration objects matches the semantics of their Double counterparts with respect to arithmetic operations.

Value parameters

nanos

the number of nanoseconds as a floating-point value, may be infinite or NaN

Attributes

Returns

a duration corresponding to the given number of nanoseconds, possibly infinite or undefined

Throws
IllegalArgumentException

if the length was finite but the resulting duration cannot be expressed as a FiniteDuration

Source
Duration.scala

Constructs a finite duration from the given number of nanoseconds. The result will have the coarsest possible time unit which can exactly express this duration.

Constructs a finite duration from the given number of nanoseconds. The result will have the coarsest possible time unit which can exactly express this duration.

Value parameters

nanos

the number of nanoseconds

Attributes

Throws
IllegalArgumentException

for Long.MinValue since that would lead to inconsistent behavior afterwards (cannot be negated)

Source
Duration.scala

Extracts 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.

Extracts 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.

Value parameters

s

the string to parse and extract a length and time unit from

Attributes

Source
Duration.scala

Extracts length and time unit out of a duration, if it is finite.

Extracts length and time unit out of a duration, if it is finite.

Value parameters

d

the duration to decompose into length and time unit

Attributes

Source
Duration.scala

Concrete fields

val Inf: Infinite

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: 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.

Attributes

Source
Duration.scala

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.

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.

Attributes

Source
Duration.scala

The Undefined value corresponds closely to Double.NaN:

The Undefined value corresponds closely to Double.NaN:

  • it is the result of otherwise invalid operations
  • it does not equal itself (according to equals())
  • it compares greater than any other Duration apart from itself (for which compare returns 0)

The particular comparison semantics mirror those of Double.NaN.

Use eq when checking an input of a method against this value.

Attributes

Source
Duration.scala

Preconstructed value of 0.days.

Preconstructed value of 0.days.

Attributes

Source
Duration.scala