std/time
std/time — Instant / Duration arithmetic.
Arithmetic over millis represented as i64, exposed as free functions. Every
result that can leave the i64 range saturates at its bound rather than
wrapping, so a far-future instant stays in the future. The two clocks arestd/sys's own.
Free functions
| Type | Method and description |
|---|---|
| instantNow() : i64 Current wall-clock time as milliseconds since the Unix epoch. |
| instantPlusMillis(t : i64, ms : i64) : i64 Instant t shifted forward by ms milliseconds. |
| instantMinusMillis(t : i64, ms : i64) : i64 Instant t shifted back by ms milliseconds. |
| instantUntil(start : i64, end : i64) : i64 Elapsed milliseconds from start to end (negative if end precedes start). |
| durationFromSeconds(seconds : i64) : i64 Converts seconds whole seconds to a duration in milliseconds. |
| durationFromMinutes(minutes : i64) : i64 Converts minutes whole minutes to a duration in milliseconds. |
| durationFromHours(hours : i64) : i64 Converts hours whole hours to a duration in milliseconds. |
| durationToSeconds(millis : i64) : i64 Whole seconds in a millis-millisecond duration (truncated). |
| durationToMinutes(millis : i64) : i64 Whole minutes in a millis-millisecond duration (truncated). |
| durationToHours(millis : i64) : i64 Whole hours in a millis-millisecond duration (truncated). |
| monotonicNanos() : i64 Reading from a monotonic clock, in nanoseconds. Only differences are meaningful (the origin is arbitrary); use for elapsed-time measurement, never as a wall-clock timestamp. |
| __timeMax() : i64 The ceiling a saturating result stops at. |
| __timeMin() : i64 The floor a saturating result stops at, spelled so no literal overflows. |
| __saturatingAdd(a : i64, b : i64) : i64 a + b held at the i64 bounds. Each bound is tested before the sum, sincethe sum itself wraps. |
| __saturatingSub(a : i64, b : i64) : i64 a - b held at the i64 bounds, tested before the difference. |
| __saturatingScale(v : i64, k : i64) : i64 v * k for a positive unit factor k, held at the i64 bounds. The quotientstruncate toward zero, which keeps every admitted product inside the range. |
Method detail
#instantNow
Current wall-clock time as milliseconds since the Unix epoch.
#instantPlusMillis
Instant t shifted forward by ms milliseconds.
t base instant, milliseconds since the Unix epoch (UTC)ms offset to add, in milliseconds#instantMinusMillis
Instant t shifted back by ms milliseconds.
t base instant, milliseconds since the Unix epoch (UTC)ms offset to subtract, in milliseconds#instantUntil
Elapsed milliseconds from start to end (negative if end precedes start).
start start instant, milliseconds since the Unix epoch (UTC)end end instant, milliseconds since the Unix epoch (UTC)#durationFromSeconds
Converts seconds whole seconds to a duration in milliseconds.
seconds duration in whole seconds#durationFromMinutes
Converts minutes whole minutes to a duration in milliseconds.
minutes duration in whole minutes#durationFromHours
Converts hours whole hours to a duration in milliseconds.
hours duration in whole hours#durationToSeconds
Whole seconds in a millis-millisecond duration (truncated).
millis duration in milliseconds#durationToMinutes
Whole minutes in a millis-millisecond duration (truncated).
millis duration in milliseconds#durationToHours
Whole hours in a millis-millisecond duration (truncated).
millis duration in milliseconds#monotonicNanos
Reading from a monotonic clock, in nanoseconds. Only differences are
meaningful (the origin is arbitrary); use for elapsed-time measurement,
never as a wall-clock timestamp.
#__timeMax
The ceiling a saturating result stops at.
#__timeMin
The floor a saturating result stops at, spelled so no literal overflows.
#__saturatingAdd
a + b held at the i64 bounds. Each bound is tested before the sum, since
the sum itself wraps.
#__saturatingSub
a - b held at the i64 bounds, tested before the difference.
#__saturatingScale
v * k for a positive unit factor k, held at the i64 bounds. The quotients
truncate toward zero, which keeps every admitted product inside the range.