Skip to Content

Duration

A number directly followed by a time unit is a time value. Five units: us, ms, s, min, hr — case-insensitive, and the number may carry a decimal point (2.0s is legal).

print(500ms, 1.5min, 2hr, 1us); print(30s + 1s); print(1min - 30s); print(30s < 1min, 30s == 30s);
500ms 1.5min 2hr 1us 31s 30s True True

When print shows a time value it picks the most readable unit: two minutes will not come out as 120s.

print(90s + 30s); print(45min + 45min);
2min 1.5hr

Multiplication and division

Time values also support multiplication and division: multiply or divide by a number (30s * 2 gives 1min, 1.5min / 3 gives 30s). Dividing by 0 raises a runtime error on the spot, same as integer division by zero.

The duration keyword

The type name duration is a soft keyword built into the language:

func Halve(d: duration) -> duration { return d / 2; } print(Halve(90s), (0s - 30s).Abs()); print(duration.FromSeconds(2.0)); print(duration.Min(30s, 90s));
45s 30s 2s 30s
  • duration is a soft keyword: a type or local name you declare yourself with the same spelling takes normal precedence, no conflict.
  • The static factory duration.FromSeconds(2.0) builds a duration from a number. Members also include duration.Min/Max(a, b) and d.Abs().
  • Duration literals fold to duration at compile time.

Notes

  • There is no implicit conversion between duration and integers/floats: val n: int = 30s; reports MS3101.
  • Unit parsing uses longest match: 30seconds does not parse the misspelling as 30s, and duration suffixes take precedence over numeric suffixes.
  • Arithmetic and comparison go through the Time module’s operator overloads; mismatched arguments report MS3104.
  • A duration has magnitude but no starting point; to express a point in time there is DateTime instead, covered on the async part’s pages.
Last updated on October 11, 2026