Reference · reference

time module

2 min read · 2026-09-02 · config-weave 0.1.0

use time reads the wall clock and the monotonic clock, sleeps, and formats timestamps. config-weave registers it from wscript-std. No function in this module fails. Its common use is a resource that converges on an age rather than on a state, such as a package cache refreshed within the last N minutes: compare the modified field of fs::metadata against now.

now_unix and now_millis

rust
time::now_unix() -> float
time::now_millis() -> int

The wall-clock time since the Unix epoch, as seconds with sub-second precision or as whole milliseconds. Prefer now_millis() / 1000 when the other side of a comparison is an integer, so the comparison stays in integers.

instant and elapsed

rust
time::instant() -> float
time::elapsed(start: float) -> float

instant reads the monotonic clock as seconds since a process-wide anchor. elapsed returns the seconds since an earlier instant. Use these for durations rather than a difference of now_unix calls, because the wall clock can step backwards when NTP corrects it or a VM resumes from a snapshot.

sleep

rust
time::sleep(millis: int)

Blocks the script's thread for the given milliseconds. A negative value is treated as zero.

format_iso

rust
time::format_iso(unix_seconds: float) -> string

Formats a Unix timestamp as an ISO 8601 string in UTC.

rust
use fs
use time

// Refresh when the stamp file is missing or older than max_age seconds.
fn stale(stamp: string, max_age: int) -> Result[bool, string] {
    if !fs::is_file(stamp) { return Ok(true) }
    let meta = fs::metadata(stamp)?
    let modified = if let Some(m) = meta.get("modified") {
        if let Some(ts) = m.as_int() { ts } else { 0 }
    } else { 0 }
    Ok(time::now_millis() / 1000 - modified > max_age)
}