Skip to content
FutureBlitz

    Install

    Import std.time.duration

    Duration

    std.time.duration

    struct

    Public Struct Duration Implements Comparable, Hashable, Printable, Defaultable

    A length of time, in nanoseconds, below 0 for one that goes back.

    Examples

    Local trip = 90.Minutes
    Expect(trip.TotalHours == 1.5)
    Expect("{trip}" == "1h30m0s")
    Expect(Duration.Parse("1h30m") == trip)
    Expect(2.5.Seconds == 2500.Milliseconds)
    Expect((trip - 2.Hours).IsNegative)

    std/time/duration.fb, line 34

    • Public Static Method Zero(): Duration static method #

      No time at all.

    • Public Static Method DefaultValue(): Duration static method #

      No time at all, 0s.

    • Public Static Method MaxValue(): Duration static method #

      The longest Duration, about 292 years ahead.

    • Public Static Method MinValue(): Duration static method #

      The shortest Duration, about 292 years back.

    • Public Static Method FromNanoseconds(count: Int64): Duration static method #

      The Duration of that many nanoseconds.

    • Public Property Nanoseconds: Int64 property #

      Its nanoseconds, all of them.

    • Public Property TotalMicroseconds: Double property #

      It in microseconds, with a fraction for what's left: 1500 nanoseconds is 1.5.

    • Public Property TotalMilliseconds: Double property #

      It in milliseconds, with a fraction for what's left.

    • Public Property TotalSeconds: Double property #

      It in seconds, with a fraction for what's left.

    • Public Property TotalMinutes: Double property #

      It in minutes, with a fraction for what's left.

    • Public Property TotalHours: Double property #

      It in hours, with a fraction for what's left.

    • Public Property TotalDays: Double property #

      It in days, of 24 hours, with a fraction for what's left.

    • Public Property IsZero: Bool property #

      Whether it's no time at all.

    • Public Property IsNegative: Bool property #

      Whether it goes back.

    • @PanicsAtCaller Public Method Abs(): Duration method #

      It without its sign. MinValue's has none that fits, so it panics.

    • Public Method Truncate(unit: Duration): Duration method #

      It rounded toward 0 to a multiple of unit, as 1h15m truncated to an hour is 1h. A unit that isn't above 0 leaves it as it is.

    • Public Method Round(unit: Duration): Duration method #

      It rounded to the nearest multiple of unit, a half away from 0, as 1h30m rounded to an hour is 2h; past the longest Duration, it's the longest. A unit that isn't above 0 leaves it as it is.

    • Public Method ToString(): String method #

      As Go writes it: hours, minutes, and seconds with a fraction, like "1h2m3.5s" and "2m0s", or below a second, one unit with a fraction, like "1.5ms", "250µs", and "80ns"; and "0s".

    • Public Static Method Parse(text: String): Duration? static method #

      The Duration the text is, as Go's ParseDuration reads it: a sign or none, then one or more numbers, each with a fraction or not and a unit, "ns", "us" (or "µs" or "μs"), "ms", "s", "m", or "h", as in "1h30m" and "-1.5s"; or "0". Other text, or a Duration longer than one holds, is Null.

    • Operator <(a: Duration, b: Duration): Bool operator #

      Whether a is shorter than b.

    • @PanicsAtCaller Operator +(a: Duration, b: Duration): Duration operator #

      a plus b, which panics past the longest Durations, as an Int64's overflow does.

    • @PanicsAtCaller Operator -(a: Duration, b: Duration): Duration operator #

      a minus b, which panics past the longest Durations, as an Int64's overflow does.

    • @PanicsAtCaller Operator -(a: Duration): Duration operator #

      a negated, which panics past the longest Durations, as an Int64's overflow does.

    • @PanicsAtCaller Operator *(a: Duration, b: Int8): Duration operator #

      a times b, exactly. One longer than a Duration holds panics, as an Int64's overflow does.

    • @PanicsAtCaller Operator *(a: Duration, b: Int16): Duration operator #

      a times b, exactly. One longer than a Duration holds panics, as an Int64's overflow does.

    • @PanicsAtCaller Operator *(a: Duration, b: Int32): Duration operator #

      a times b, exactly. One longer than a Duration holds panics, as an Int64's overflow does.

    • @PanicsAtCaller Operator *(a: Duration, b: Int64): Duration operator #

      a times b, exactly. One longer than a Duration holds panics, as an Int64's overflow does.

    • @PanicsAtCaller Operator *(a: Duration, b: UInt8): Duration operator #

      a times b, exactly. One longer than a Duration holds panics, as an Int64's overflow does.

    • @PanicsAtCaller Operator *(a: Duration, b: UInt16): Duration operator #

      a times b, exactly. One longer than a Duration holds panics, as an Int64's overflow does.

    • @PanicsAtCaller Operator *(a: Duration, b: UInt32): Duration operator #

      a times b, exactly. One longer than a Duration holds panics, as an Int64's overflow does.

    • @PanicsAtCaller Operator *(a: Int8, b: Duration): Duration operator #

      a times b, exactly. One longer than a Duration holds panics, as an Int64's overflow does.

    • @PanicsAtCaller Operator *(a: Int16, b: Duration): Duration operator #

      a times b, exactly. One longer than a Duration holds panics, as an Int64's overflow does.

    • @PanicsAtCaller Operator *(a: Int32, b: Duration): Duration operator #

      a times b, exactly. One longer than a Duration holds panics, as an Int64's overflow does.

    • @PanicsAtCaller Operator *(a: Int64, b: Duration): Duration operator #

      a times b, exactly. One longer than a Duration holds panics, as an Int64's overflow does.

    • @PanicsAtCaller Operator *(a: UInt8, b: Duration): Duration operator #

      a times b, exactly. One longer than a Duration holds panics, as an Int64's overflow does.

    • @PanicsAtCaller Operator *(a: UInt16, b: Duration): Duration operator #

      a times b, exactly. One longer than a Duration holds panics, as an Int64's overflow does.

    • @PanicsAtCaller Operator *(a: UInt32, b: Duration): Duration operator #

      a times b, exactly. One longer than a Duration holds panics, as an Int64's overflow does.

    • @PanicsAtCaller Operator *(a: Duration, b: Double): Duration operator #

      a times b, to the nearest nanosecond, ties to even. One longer than a Duration holds panics, and so does a b that isn't a number.

    • @PanicsAtCaller Operator *(a: Double, b: Duration): Duration operator #

      a times b, to the nearest nanosecond, ties to even. One longer than a Duration holds panics, and so does an a that isn't a number.

    • @PanicsAtCaller Operator /(a: Duration, b: Int8): Duration operator #

      a divided by b, rounded toward 0. Dividing by 0 panics, as an Int's / does.

    • @PanicsAtCaller Operator /(a: Duration, b: Int16): Duration operator #

      a divided by b, rounded toward 0. Dividing by 0 panics, as an Int's / does.

    • @PanicsAtCaller Operator /(a: Duration, b: Int32): Duration operator #

      a divided by b, rounded toward 0. Dividing by 0 panics, as an Int's / does.

    • @PanicsAtCaller Operator /(a: Duration, b: Int64): Duration operator #

      a divided by b, rounded toward 0. Dividing by 0 panics, as an Int's / does.

    • @PanicsAtCaller Operator /(a: Duration, b: UInt8): Duration operator #

      a divided by b, rounded toward 0. Dividing by 0 panics, as an Int's / does.

    • @PanicsAtCaller Operator /(a: Duration, b: UInt16): Duration operator #

      a divided by b, rounded toward 0. Dividing by 0 panics, as an Int's / does.

    • @PanicsAtCaller Operator /(a: Duration, b: UInt32): Duration operator #

      a divided by b, rounded toward 0. Dividing by 0 panics, as an Int's / does.

    • @PanicsAtCaller Operator /(a: Duration, b: Double): Duration operator #

      a divided by b, to the nearest nanosecond, ties to even. Dividing by 0 panics, and so does a b that isn't a number.

    • @PanicsAtCaller Operator /(a: Duration, b: Duration): Double operator #

      How many of b fit in a, with a fraction. Dividing by a b of 0 panics.

    • @PanicsAtCaller Operator %(a: Duration, b: Duration): Duration operator #

      What's left of a over b, with a's sign, as an Int's % has, which panics for a b of 0.

    Report an issue with this page or with FutureBlitz on GitHub.