DurationA signed, fixed length of time, with nanosecond precision.
Built with the unit constructors (Duration.seconds:, Duration.minutes:, …), combined with +: / -: / *:, and read back as unit totals (asSeconds, asMilliseconds, …). Fixed means clock-agnostic: an hour is always 3600 seconds. Calendar-aware arithmetic (days, months, DST) lives on DateTime (plusDays: and friends). Durations are what Timestamp / DateTime / Instant subtraction yields, and what sleep: / timeout: consume.
(Duration.minutes:90).s "* -> 1h 30m ((Duration.minutes:1) + (Duration.seconds:30)).s "* -> 1m 30s (Duration.milliseconds:1500).asSeconds "* -> 1.5
The fixed duration, as an ISO 8601 duration ('PT1H30M'; Span.parse: reads it back — as a time-only Span, asDuration completing the round trip).
A Duration of exactly the given whole number of hours (may be negative).
A Duration of exactly the given whole number of microseconds (may be negative).
A Duration of exactly the given whole number of milliseconds (may be negative).
(Duration.milliseconds:1500).s "* -> 1s 500ms
A Duration of exactly the given whole number of minutes (may be negative).
(Duration.minutes:90).s "* -> 1h 30m
A Duration of exactly the given whole number of nanoseconds (may be negative).
A Duration of exactly the given whole number of seconds (may be negative).
(Duration.seconds:90).s "* -> 1m 30s
The zero-length Duration — the identity for +: and the natural seed for a summing fold.
Duration.zero.s "* -> 0s
The Duration scaled by an Integer factor (the one arithmetic operator whose operand is not a Duration). Overflow throws an ArithmeticError.
((Duration.seconds:10) * 6).s "* -> 1m
The sum of two Durations. Overflow (past roughly ±292 billion years) throws an ArithmeticError rather than wrapping.
((Duration.minutes:1) + (Duration.seconds:30)).s "* -> 1m 30s
The difference of two Durations — negative when the argument is longer (a Duration is signed). Overflow throws an ArithmeticError.
((Duration.hours:2) - (Duration.minutes:30)).s "* -> 1h 30m ((Duration.minutes:90) - (Duration.hours:2)).s "* -> 30m ago
Whether the receiver is shorter than the argument (signed: any negative Duration is less than any positive one). Only <: is native; >: / <=: / >=: derive from it on Object.
Whether the argument is a Duration of the same length. A non-Duration argument is simply unequal — never an error.
(Duration.seconds:60) == (Duration.minutes:1) "* -> true
The magnitude: a negative Duration made positive, a non-negative one unchanged.
The total number of whole microseconds, truncated toward zero (Integer); throws an ArithmeticError if the count does not fit a 64-bit Integer.
The total number of whole milliseconds, truncated toward zero (Integer).
(Duration.seconds:90).asMilliseconds "* -> 90000
The total number of whole nanoseconds (Integer); throws an ArithmeticError if the count does not fit a 64-bit Integer (a span of ~292 years).
The total length in seconds, as a fractional Double (the one fractional unit total; the others are whole Integer counts).
(Duration.milliseconds:1500).asSeconds "* -> 1.5
The canonical ISO 8601 duration string, for serialization.
(Duration.minutes:90).iso8601 "* -> PT1H30M
The same length with the sign flipped.
(Duration.seconds:30).negate.s "* -> 30s ago
A human-readable rendering; negative Durations read as time "ago". For a machine-readable form use iso8601.
(Duration.minutes:90).s "* -> 1h 30m (Duration.seconds:30).negate.s "* -> 30s ago