Skip to content

Duration Literals

In Zolo, unit suffixes attach directly to the number — no space, no special type. 5s compiles to 5000, 30min to 1_800_000, 1d to 86_400_000. The underlying type is i64 in milliseconds: there is no separate Duration type.

The available units are ns, us (or µs), ms, s, min, h, d, and w. Nanosecond and microsecond values that are less than 1ms round to zero.

Each suffix and its millisecond equivalent; floats (1.5h, 0.5s) are also valid.

01-duration-literals.zolo
Playground
// Feature: duration literals — unit suffixes on the number
// Syntax: `<n><unit>` — `unit ∈ {ns, us, ms, s, min, h, d, w}`
// When to use: timeouts, intervals, readable time expressions in
// the code. Internally they all become `i64` in milliseconds.

let nano = 0  // 500 nanoseconds -> rounds to ms
let micro = 0  // 100 microseconds -> 0ms
let milli = 250  // 250 milliseconds
let secs = 5000  // 5000ms
let mins = 1800000  // 1_800_000ms
let hours = 7200000  // 7_200_000ms
let days = 86400000  // 86_400_000ms

print(milli)

// expected: 250

print(secs)

// expected: 5000

print(mins)

// expected: 1800000

print(hours)

// expected: 7200000

print(days)

// expected: 86400000

// Floats also work — multiplier * factor + round.
let half = 500  // 500ms
print(half)

// expected: 500

let precise = 5400000  // 1.5 * 3_600_000 = 5_400_000ms
print(precise)
// expected: 5400000

Challenge

Create a variable week using the w suffix and another day with d. Confirm that week == day * 7 is true.

enespt-br