Axle v0.14.1
Package

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 are
std/sys's own.

Free functions

TypeMethod and description
i64
instantNow() : i64 Current wall-clock time as milliseconds since the Unix epoch.
i64
instantPlusMillis(t : i64, ms : i64) : i64 Instant t shifted forward by ms milliseconds.
i64
instantMinusMillis(t : i64, ms : i64) : i64 Instant t shifted back by ms milliseconds.
i64
instantUntil(start : i64, end : i64) : i64 Elapsed milliseconds from start to end (negative if end precedes start).
i64
durationFromSeconds(seconds : i64) : i64 Converts seconds whole seconds to a duration in milliseconds.
i64
durationFromMinutes(minutes : i64) : i64 Converts minutes whole minutes to a duration in milliseconds.
i64
durationFromHours(hours : i64) : i64 Converts hours whole hours to a duration in milliseconds.
i64
durationToSeconds(millis : i64) : i64 Whole seconds in a millis-millisecond duration (truncated).
i64
durationToMinutes(millis : i64) : i64 Whole minutes in a millis-millisecond duration (truncated).
i64
durationToHours(millis : i64) : i64 Whole hours in a millis-millisecond duration (truncated).
i64
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.
i64
__timeMax() : i64 The ceiling a saturating result stops at.
i64
__timeMin() : i64 The floor a saturating result stops at, spelled so no literal overflows.
i64
__saturatingAdd(a : i64, b : i64) : i64 a + b held at the i64 bounds. Each bound is tested before the sum, since
the sum itself wraps.
i64
__saturatingSub(a : i64, b : i64) : i64 a - b held at the i64 bounds, tested before the difference.
i64
__saturatingScale(v : i64, k : i64) : i64 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.

Method detail

#instantNow

instantNow() : i64

Current wall-clock time as milliseconds since the Unix epoch.

#instantPlusMillis

instantPlusMillis(t : i64, ms : i64) : i64

Instant t shifted forward by ms milliseconds.

Parameters
t base instant, milliseconds since the Unix epoch (UTC)
ms offset to add, in milliseconds

#instantMinusMillis

instantMinusMillis(t : i64, ms : i64) : i64

Instant t shifted back by ms milliseconds.

Parameters
t base instant, milliseconds since the Unix epoch (UTC)
ms offset to subtract, in milliseconds

#instantUntil

instantUntil(start : i64, end : i64) : i64

Elapsed milliseconds from start to end (negative if end precedes start).

Parameters
start start instant, milliseconds since the Unix epoch (UTC)
end end instant, milliseconds since the Unix epoch (UTC)

#durationFromSeconds

durationFromSeconds(seconds : i64) : i64

Converts seconds whole seconds to a duration in milliseconds.

Parameters
seconds duration in whole seconds

#durationFromMinutes

durationFromMinutes(minutes : i64) : i64

Converts minutes whole minutes to a duration in milliseconds.

Parameters
minutes duration in whole minutes

#durationFromHours

durationFromHours(hours : i64) : i64

Converts hours whole hours to a duration in milliseconds.

Parameters
hours duration in whole hours

#durationToSeconds

durationToSeconds(millis : i64) : i64

Whole seconds in a millis-millisecond duration (truncated).

Parameters
millis duration in milliseconds

#durationToMinutes

durationToMinutes(millis : i64) : i64

Whole minutes in a millis-millisecond duration (truncated).

Parameters
millis duration in milliseconds

#durationToHours

durationToHours(millis : i64) : i64

Whole hours in a millis-millisecond duration (truncated).

Parameters
millis duration in milliseconds

#monotonicNanos

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

__timeMax() : i64

The ceiling a saturating result stops at.

#__timeMin

__timeMin() : i64

The floor a saturating result stops at, spelled so no literal overflows.

#__saturatingAdd

__saturatingAdd(a : i64, b : i64) : i64

a + b held at the i64 bounds. Each bound is tested before the sum, since
the sum itself wraps.

#__saturatingSub

__saturatingSub(a : i64, b : i64) : i64

a - b held at the i64 bounds, tested before the difference.

#__saturatingScale

__saturatingScale(v : i64, k : i64) : i64

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.