class Duration

include Comparable[Duration]

A span of time, kept as a signed 64-bit count of nanoseconds: about 292 years either way. Made by Int#ms, Int#seconds, Float#minutes and the like; sleep and timeouts take one.

d = 1.minute + 30.seconds
d               # => 90s
d.to_f          # => 90.0
d * 2           # => 180s
d > 1.minute    # => true

<prelude>:1156

Methods

def +(other: Duration) -> Duration

The sum; OverflowError when it leaves the range a Duration holds.

1.minute + 30.seconds          # => 90s
100000.days + 100000.days      # raises OverflowError

<prelude>:1166

def -(other: Duration) -> Duration

The difference, negative when other is longer; OverflowError when it leaves the range a Duration holds.

<prelude>:1169

def *(factor: Int) -> Duration

The duration factor times as long; OverflowError when it leaves the range a Duration holds.

<prelude>:1172

def *(factor: Float) -> Duration

The duration factor times as long, truncated to a whole nanosecond; OverflowError when it leaves the range (or for a NaN factor).

<prelude>:1175

def <=>(other: Duration) -> Int

-1, 0 or 1 as self is shorter than, as long as or longer than other.

<prelude>:1178

def to_f -> Float

The length in seconds.

<prelude>:1180

def to_ms -> Int

The length in whole milliseconds, truncated toward zero.

1500.ms.to_ms     # => 1500
1.9.ms.to_ms      # => 1

<prelude>:1187

def to_s -> String

The length in the largest unit that holds it whole, of seconds, milliseconds and nanoseconds, as inspect shows it.

2.seconds.to_s    # => "2s"
1500.ms.to_s      # => "1500ms"
2.5.ms.to_s       # => "2500000ns"

<prelude>:1196