Skip to content

aivi.time ​

Wall-clock and monotonic clock tasks, plus pure millisecond arithmetic. EpochMs is an Int alias.

ValueTypeDescription
nowMsTask Text IntUnix epoch milliseconds from the system clock
monotonicMsTask Text IntMilliseconds since the first monotonic-clock request in this process

Use nowMs for stored timestamps and monotonicMs for elapsed durations. The monotonic origin is process-local and must not be persisted or compared between processes.

aivi
use aivi.time (
    nowMs
    monotonicMs
)

value savedAt : Task Text Int = nowMs
value stopwatchNow : Task Text Int = monotonicMs

Timestamp pattern formatting and parsing are not offered. Calendar records and formatting live in aivi.date; epoch-to-calendar conversion is not currently provided.

Pure millisecond helpers ​

ValueTypeDescription
EpochMsIntType alias for epoch milliseconds
msPerSecondInt1000
msPerMinuteInt60000
msPerHourInt3600000
msPerDayInt86400000
toSecondsInt -> IntConvert milliseconds to whole seconds
toMinutesInt -> IntConvert milliseconds to whole minutes
toHoursInt -> IntConvert milliseconds to whole hours
toDaysInt -> IntConvert milliseconds to whole days
fromSecondsInt -> IntConvert seconds to milliseconds
fromMinutesInt -> IntConvert minutes to milliseconds
fromHoursInt -> IntConvert hours to milliseconds
fromDaysInt -> IntConvert days to milliseconds
elapsedInt -> Int -> IntSubtract start from finish
aivi
use aivi.time (
    fromSeconds
    fromMinutes
    elapsed
    toSeconds
)

value timeoutMs : Int = fromSeconds 30
value cacheTtlMs : Int = fromMinutes 5
value requestTimeMs : Int = elapsed 1200 1875
value requestTimeSeconds : Int = toSeconds requestTimeMs

Example — wall clock plus steady clock ​

aivi
use aivi.time (
    nowMs
    monotonicMs
    elapsed
)

value createdAt : Task Text Int = nowMs
value timerStart : Int = 1000
value timerNow : Int = 1450
value timerElapsed : Int = elapsed timerStart timerNow
value steadySnapshot : Task Text Int = monotonicMs

(c) 2026 by Andreas Herd