Duration and temporal

Duration is a first-class type. Write 5s, 200ms, 2m30s anywhere a value is expected. No import required.

Duration literals

Append a time suffix immediately after a number (no whitespace). Supported suffixes: ns, us, ms, s, m, h, d. Compound forms like 2m30s or 1h15m work too.

scratch.xs

Internally, every duration is a 64-bit integer count of nanoseconds. The repr picks the largest readable unit and trims trailing zeros:1500ns prints as 1.5us, 90s prints as 1m30s.

Arithmetic and accessors

Duration arithmetic is exact (integer nanoseconds, no float drift). Dividing two durations gives a float ratio.

scratch.xs

Component accessors: .ns returns an int; .us, .ms, .s, .m, .h, .d return floats.

Temporal decorators

To schedule a function to run on an interval or after a delay, use the decorator forms. These work on any named function declaration.

@every runs the decorated function repeatedly at a fixed interval:

@every(1s)
fn tick() {
  println("tick")
}

@after runs the function once after the given delay:

@after(500ms)
fn delayed() {
  println("delayed hello")
}

@cron accepts a standard cron expression string:

@cron("0 9 * * 1-5")
fn weekday_morning() {
  println("good morning")
}