sealed class Duration extends TimeLike[Duration] with Serializable
A Duration
represents the span between two points in time. It represents
this with a signed long, and thus the largest representable duration is:
106751.days+23.hours+47.minutes+16.seconds +854.milliseconds+775.microseconds+807.nanoseconds
Durations may be constructed via its companion object,
Duration.fromNanoseconds
, Duration.fromSeconds
, etc. or by
using the time conversions:
import com.twitter.conversions.DurationOps._ 3.days+4.nanoseconds
In addition to the timespans in the range of Long.MinValue
to
Long.MaxValue
nanoseconds, durations have two distinguished
values: Duration.Top
and Duration.Bottom
. These have special
semantics: Top
is greater than every other duration, save for
itself; Bottom
is smaller than any duration except for
itself — they act like positive and negative infinity, and
their arithmetic follows. This is useful for representing durations
that are truly infinite; for example the absence of a timeout.
- Alphabetic
- By Inheritance
- Duration
- Serializable
- TimeLike
- Ordered
- Comparable
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
def
%(x: Duration): Duration
Scales this
Duration
by modding byx
. -
def
*(x: Double): Duration
Scales this
Duration
by multiplying byx
. -
def
*(x: Long): Duration
Scales this
Duration
by multiplying byx
. -
def
+(delta: Duration): Duration
Adds
delta
to thisTimeLike
.Adds
delta
to thisTimeLike
. AddingDuration.Top
results in theTimeLike
'sTop
, addingDuration.Bottom
results in theTimeLike
'sBottom
.- Definition Classes
- TimeLike
-
def
-(delta: Duration): Duration
- Definition Classes
- TimeLike
-
def
/(x: Double): Duration
Scales this
Duration
by dividing byx
. -
def
/(x: Long): Duration
Scales this
Duration
by dividing byx
. -
def
<(that: Duration): Boolean
- Definition Classes
- Ordered
-
def
<=(that: Duration): Boolean
- Definition Classes
- Ordered
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
>(that: Duration): Boolean
- Definition Classes
- Ordered
-
def
>=(that: Duration): Boolean
- Definition Classes
- Ordered
-
def
abs: Duration
Converts negative durations to positive durations.
- def afterEpoch: Time
- def ago: Time
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
ceil(increment: Duration): Duration
Rounds up to the nearest multiple of the given duration.
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
def
compare(that: Duration): Int
- Definition Classes
- TimeLike → Ordered
-
def
compareTo(that: Duration): Int
- Definition Classes
- Ordered → Comparable
-
def
diff(that: Duration): Duration
The difference between the two
TimeLike
s -
def
div(x: Double): Duration
- See also
operator /
-
def
div(x: Long): Duration
- See also
operator /
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(other: Any): Boolean
- Definition Classes
- Duration → AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
def
floor(increment: Duration): Duration
Rounds down to the nearest multiple of the given duration.
- def fromNow: Time
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- Duration → AnyRef → Any
-
def
inDays: Int
- Definition Classes
- TimeLike
-
def
inHours: Int
- Definition Classes
- TimeLike
-
def
inLongSeconds: Long
- Definition Classes
- TimeLike
-
def
inMicroseconds: Long
- Definition Classes
- TimeLike
-
def
inMillis: Long
- Definition Classes
- TimeLike
-
def
inMilliseconds: Long
- Definition Classes
- TimeLike
-
def
inMinutes: Int
- Definition Classes
- TimeLike
-
def
inNanoseconds: Long
The
TimeLike
's value in nanoseconds. -
def
inSeconds: Int
- Definition Classes
- TimeLike
-
def
inTimeUnit: (Long, TimeUnit)
Returns a value/
TimeUnit
pair; attempting to return coarser grained values if possible (specifically:TimeUnit.MINUTES
,TimeUnit.SECONDS
orTimeUnit.MILLISECONDS
) before resorting to the defaultTimeUnit.NANOSECONDS
.Returns a value/
TimeUnit
pair; attempting to return coarser grained values if possible (specifically:TimeUnit.MINUTES
,TimeUnit.SECONDS
orTimeUnit.MILLISECONDS
) before resorting to the defaultTimeUnit.NANOSECONDS
.- Definition Classes
- TimeLike
-
def
inUnit(unit: TimeUnit): Long
Returns the length of the duration in the given TimeUnit.
Returns the length of the duration in the given TimeUnit.
In general, a simpler approach is to use the named methods (eg. inSeconds) However, this is useful for more programmatic call sites.
-
def
isFinite: Boolean
Is this a finite TimeLike value?
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
isZero: Boolean
Is this a finite TimeLike value and equals 0
Is this a finite TimeLike value and equals 0
- Definition Classes
- TimeLike
-
def
max(that: Duration): Duration
- Definition Classes
- TimeLike
-
def
min(that: Duration): Duration
- Definition Classes
- TimeLike
-
def
minus(delta: Duration): Duration
- See also
operator -
-
def
moreOrLessEquals(other: Duration, maxDelta: Duration): Boolean
Equality within
maxDelta
Equality within
maxDelta
- Definition Classes
- TimeLike
-
def
mul(x: Double): Duration
- See also
operator *
-
def
mul(x: Long): Duration
- See also
operator *
-
val
nanos: Long
- Attributes
- protected
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
neg: Duration
Negates this
Duration
. -
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- val ops: Duration.type
-
def
plus(delta: Duration): Duration
- See also
operator +
-
def
rem(x: Duration): Duration
- See also
operator %
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
toString produces a representation that
toString produces a representation that
- loses no information - is easy to read - can be read back in if com.twitter.conversions.time._ is imported
An example:
com.twitter.util.Duration(9999999, java.util.concurrent.TimeUnit.MICROSECONDS) res0: com.twitter.util.Duration = 9.seconds+999.milliseconds+999.microseconds
- Definition Classes
- Duration → AnyRef → Any
- def unary_-: Duration
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )