Time Bottom
is smaller than any other time, and is equal only
to itself.
Time Bottom
is smaller than any other time, and is equal only
to itself. It may be used as a sentinel value, representing a
time infinitely far in the past.
An extractor for finite TimeLikes; eg.:
An extractor for finite TimeLikes; eg.:
duration match { case Duration.Finite(d) => ... case Duration.Top => ..
An extractor for finite This
, yielding its value in nanoseconds.
An extractor for finite This
, yielding its value in nanoseconds.
duration match { case Duration.Nanoseconds(ns) => ... case Duration.Top => ... }
Time Top
is greater than any other definable time, and is
equal only to itself.
Time Top
is greater than any other definable time, and is
equal only to itself. It may be used as a sentinel value,
representing a time infinitely far into the future.
An undefined value: behaves like Double.NaN
An undefined value: behaves like Double.NaN
The zero value
The zero value
Creates a Time instance of the given Date.
Creates a Time instance at the given datetime
string in the
"yyyy-MM-dd HH:mm:ss Z" format.
The unix epoch.
The unix epoch. Times are measured relative to this.
Make a new This
from the given number of seconds.
Make a new This
from the given number of seconds.
Because this method takes a Double, it can represent values less than a second.
Note however that there is some slop in floating-point conversion that
limits precision. Currently we can assume at least microsecond precision.
Make a new This
from the given number of nanoseconds
Make a new This
from the given number of nanoseconds
Returns the Time parsed from a string in RSS format.
Returns the Time parsed from a string in RSS format. Eg: "Wed, 15 Jun 2005 19:00:00 GMT"
Returns the current Time.
Returns the current Time.
Note that returned values are not monotonic. This means it is not suitable for measuring durations where the clock cannot drift backwards. If monotonicity is desired prefer a monotonic Stopwatch.
The current time can be manipulated via Time.withTimeAt, Time.withCurrentTimeFrozen, Time.withTimeFunction and Time.sleep.
While now
is not a "global" it is however properly propagated through
to other code via the standard usage of Locals throughout util
.
Specifically, code using Futures, FuturePools,
and MockTimers will have their code see the manipulated
values.
Puts the currently executing thread to sleep for the given duration, according to object Time.
Puts the currently executing thread to sleep for the given duration, according to object Time.
This is useful for testing.
val time = Time.fromMilliseconds(123456L) Time.withTimeAt(time) { timeControl => assert(Time.now == time) // you can control time via the `TimeControl` instance. timeControl.advance(2.seconds) FuturePool.unboundedPool { assert(Time.now == time + 2.seconds) } }
Runs the given body at the current time.
Runs the given body at the current time. Makes for simple, fast, predictable unit tests that are dependent on time.
this intended for use in tests.
val time = Time.fromMilliseconds(123456L) Time.withTimeAt(time) { timeControl => assert(Time.now == time) // you can control time via the `TimeControl` instance. timeControl.advance(2.seconds) FuturePool.unboundedPool { assert(Time.now == time + 2.seconds) } }
Runs the given body at a specified time.
Runs the given body at a specified time. Makes for simple, fast, predictable unit tests that are dependent on time.
this intended for use in tests.
val time = Time.fromMilliseconds(123456L) Time.withTimeAt(time) { timeControl => assert(Time.now == time) // you can control time via the `TimeControl` instance. timeControl.advance(2.seconds) FuturePool.unboundedPool { assert(Time.now == time + 2.seconds) } }
Execute body with the time function replaced by timeFunction
WARNING: This is only meant for testing purposes.
Execute body with the time function replaced by timeFunction
WARNING: This is only meant for testing purposes. You can break it
with nested calls if you have an outstanding Future executing in a worker pool.
By using Time.now in your program instead of
System.currentTimeMillis
unit tests are able to adjust the current time to verify timeouts and other time-dependent behavior, without callingsleep
, and providing deterministic tests.The current time can be manipulated via Time.withTimeAt, Time.withCurrentTimeFrozen, Time.withTimeFunction and Time.sleep.
While
now
is not a "global" it is however properly propagated through to other code via the standard usage of Locals throughoututil
. Specifically, code using Futures, FuturePools, and MockTimers will have their code see the manipulated values.TimeFormat for converting to and from
String
representations.Stopwatch for measuring elapsed time.
Duration for intervals between two points in time.