APITime.Duration

Time.Duration

Exact elapsed time at nanosecond precision. Unlike Time.Period, a duration has no calendar units. Use hours 24 when exactly 24 hours are intended. The representation is floor seconds plus a nonnegative nanosecond fraction, so the range is signed 64-bit seconds. Arithmetic is total: a result beyond that range wraps like Int, which takes inputs near 10^17 hours. Conversions to sub-second units answer Nothing when the integer would overflow.

import Time.Duration as Duration
import Maybe exposing (Maybe(..))

Duration.toSeconds (Duration.milliseconds (-1500)) == -1
Duration.toMilliseconds (Duration.scale 3 (Duration.milliseconds 500)) == Just 1500

Duration

type DurationSource

An exact signed interval, ordered by elapsed length.

Instances:

Eq Duration
Ord Duration
Show Duration

add

add : Duration -> Duration -> DurationSource

Adds two durations.

fromParts

fromParts : Int -> Int -> DurationSource

Normalizes seconds plus a signed nanosecond adjustment.

hours

hours : Int -> DurationSource

An exact number of hours.

microseconds

microseconds : Int -> DurationSource

An exact number of microseconds.

milliseconds

milliseconds : Int -> DurationSource

An exact number of milliseconds.

minutes

minutes : Int -> DurationSource

An exact number of minutes.

nanoseconds

nanoseconds : Int -> DurationSource

An exact number of nanoseconds.

negate

negate : Duration -> DurationSource

Reverses a duration’s sign.

parts

parts : Duration -> (Int, Int)Source

Floor seconds and the fraction in the range 0 through 999999999.

scale

scale : Int -> Duration -> DurationSource

Multiplies by an integer, preserving nanoseconds.

seconds

seconds : Int -> DurationSource

An exact number of seconds.

subtract

subtract : Duration -> Duration -> DurationSource

Subtracts the first duration from the second; suitable for pipelines.

toHours

toHours : Duration -> IntSource

Whole hours, truncating toward zero.

toMicroseconds

toMicroseconds : Duration -> Maybe IntSource

Whole microseconds, truncating toward zero, or Nothing on overflow.

toMilliseconds

toMilliseconds : Duration -> Maybe IntSource

Whole milliseconds, truncating toward zero, or Nothing on overflow.

toMinutes

toMinutes : Duration -> IntSource

Whole minutes, truncating toward zero.

toNanoseconds

toNanoseconds : Duration -> Maybe IntSource

Total nanoseconds, or Nothing beyond roughly 292 years.

toSeconds

toSeconds : Duration -> IntSource

Whole seconds, truncating toward zero.

zero

zero : DurationSource

No elapsed time.