Durations
A duration represents a non-negative period of time.
Duration units
Durations can be specified in any of the following units:
| Unit | Description |
|---|---|
| ns | Nanoseconds |
| us | Microseconds, alternative: µs |
| ms | Milliseconds |
| s | Seconds |
| m | Minutes |
| h | Hours |
| d | Days |
| w | Weeks |
| y | Years |
Creating and using durations
A duration can be composed of any number of duration units.
A duration that contains multiple instances of the same unit type will parse as well, combining lesser units into greater units when a maximum value is reached.
For example, a duration that includes 12h two times will be evaluated as 1d.
A duration can also be created by casting a string.
A duration can be zero, but cannot be negative.
The maximum possible duration can be accessed via the const duration::max, above which a duration cannot be formed.
Durations can be added to and subtracted from other durations as well as datetimes.
Multiplying and dividing durations
A duration can be multiplied and divided by a number.