Std.Duration
Duration
Section titled “Duration”opaque type DurationMade with constructors like Duration.seconds(5).
milliseconds
Section titled “milliseconds”fn milliseconds(n: Int64) -> Durationn milliseconds.
seconds
Section titled “seconds”fn seconds(n: Int64) -> Durationn seconds.
minutes
Section titled “minutes”fn minutes(n: Int64) -> Durationn minutes.
fn hours(n: Int64) -> Durationn hours.
to_milliseconds
Section titled “to_milliseconds”fn to_milliseconds(d: Duration) -> Int64The number of milliseconds.
to_seconds
Section titled “to_seconds”fn to_seconds(d: Duration) -> Int64Truncates toward zero.
fn add(d: Duration, other: Duration) -> DurationThe sum.
subtract
Section titled “subtract”fn subtract(d: Duration, other: Duration) -> DurationMay be negative.
to_string
Section titled “to_string”fn to_string(d: Duration) -> StringMilliseconds with an ms suffix (1500ms, -1500ms). parse reads it back. The format is in
spec [api.std.duration].
to_iso8601
Section titled “to_iso8601”fn to_iso8601(d: Duration) -> StringThe time part of an ISO 8601 duration (PT1H30M, PT1.5S, -PT0.5S, PT0S): a sign for a
negative length, then the hours, the minutes and the seconds, each left out when it is 0. The
hours are not carried into days (PT48H). parse reads it back. The format is in spec
[api.std.duration].
fn parse(s: String) -> Duration fails ParseErrorThe length of time written in s: numbers with units (1h30m, 1.5s, 2h 30min,
30 seconds, and 1500ms as to_string writes it), or the time part of an ISO 8601 duration
(PT1H30M, -PT1.5S, as to_iso8601 writes it). Days and longer units are not read. The digits
below the millisecond are dropped, which truncates toward 0. Fails with ParseError(input: s)
otherwise, and for a length outside the range of Duration. The grammar is in spec
[api.std.duration].