object Duration extends java.io.Serializable
- Source
- Duration.scala
- Alphabetic
- By Inheritance
- Duration
- Serializable
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Value Members
- val Inf: Infinite
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.
- val MinusInf: Infinite
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.
- val Undefined: Infinite
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.
- val Zero: FiniteDuration
Preconstructed value of
0.days
. - def apply(s: String): Duration
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"
,"Duration.Inf"
and"-Inf"
,"MinusInf"
or"Duration.MinusInf"
. Undefined is designated by"Duration.Undefined"
.- Exceptions thrown
NumberFormatException
if format is not parsable
- def apply(length: Long, unit: String): FiniteDuration
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, 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"). - def apply(length: Long, unit: TimeUnit): 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.
- def apply(length: Double, unit: TimeUnit): Duration
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
- 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.
- Exceptions thrown
IllegalArgumentException
if the length was finite but the resulting duration cannot be expressed as a FiniteDuration
- def create(s: String): Duration
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"
.- Exceptions thrown
NumberFormatException
if format is not parsable
- def create(length: Long, unit: String): FiniteDuration
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"). - def create(length: Double, unit: TimeUnit): Duration
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
- 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.
- Exceptions thrown
IllegalArgumentException
if the length was finite but the resulting duration cannot be expressed as a FiniteDuration
- def create(length: Long, unit: TimeUnit): 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.
- def fromNanos(nanos: Long): FiniteDuration
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.
- Exceptions thrown
IllegalArgumentException
forLong.MinValue
since that would lead to inconsistent behavior afterwards (cannot be negated)
- def fromNanos(nanos: Double): Duration
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 like0d
)
The semantics of the resulting Duration objects matches the semantics of their Double counterparts with respect to arithmetic operations.
- Exceptions thrown
IllegalArgumentException
if the length was finite but the resulting duration cannot be expressed as a FiniteDuration
- def unapply(d: Duration): Option[(Long, TimeUnit)]
Extract length and time unit out of a duration, if it is finite.
- def unapply(s: String): Option[(Long, TimeUnit)]
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.
- implicit object DurationIsOrdered extends Ordering[Duration]
The natural ordering of durations matches the natural ordering for Double, including non-finite values.
This is the documentation for the Scala standard library.
Package structure
The scala package contains core types like
Int
,Float
,Array
orOption
which are accessible in all Scala compilation units without explicit qualification or imports.Notable packages include:
scala.collection
and its sub-packages contain Scala's collections frameworkscala.collection.immutable
- Immutable, sequential data-structures such asVector
,List
,Range
,HashMap
orHashSet
scala.collection.mutable
- Mutable, sequential data-structures such asArrayBuffer
,StringBuilder
,HashMap
orHashSet
scala.collection.concurrent
- Mutable, concurrent data-structures such asTrieMap
scala.concurrent
- Primitives for concurrent programming such asFutures
andPromises
scala.io
- Input and output operationsscala.math
- Basic math functions and additional numeric types likeBigInt
andBigDecimal
scala.sys
- Interaction with other processes and the operating systemscala.util.matching
- Regular expressionsOther packages exist. See the complete list on the right.
Additional parts of the standard library are shipped as separate libraries. These include:
scala.reflect
- Scala's reflection API (scala-reflect.jar)scala.xml
- XML parsing, manipulation, and serialization (scala-xml.jar)scala.collection.parallel
- Parallel collections (scala-parallel-collections.jar)scala.util.parsing
- Parser combinators (scala-parser-combinators.jar)scala.swing
- A convenient wrapper around Java's GUI framework called Swing (scala-swing.jar)Automatic imports
Identifiers in the scala package and the
scala.Predef
object are always in scope by default.Some of these identifiers are type aliases provided as shortcuts to commonly used classes. For example,
List
is an alias forscala.collection.immutable.List
.Other aliases refer to classes provided by the underlying platform. For example, on the JVM,
String
is an alias forjava.lang.String
.