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 TrueWhen 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.5hrMultiplication 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
30sdurationis 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 includeduration.Min/Max(a, b)andd.Abs(). - Duration literals fold to
durationat compile time.
Notes
- There is no implicit conversion between
durationand integers/floats:val n: int = 30s;reports MS3101. - Unit parsing uses longest match:
30secondsdoes not parse the misspelling as30s, and duration suffixes take precedence over numeric suffixes. - Arithmetic and comparison go through the
Timemodule’s operator overloads; mismatched arguments report MS3104. - A duration has magnitude but no starting point; to express a point in time there is
DateTimeinstead, covered on the async part’s pages.
Last updated on October 11, 2026
