Duration functions¶
The following functions operate on the built-in type Duration
for durations.
Duration::fromSeconds : Float -> Duration
¶
The function Duration::fromSeconds
creates a new duration from seconds.
You can specify milliseconds using the fractional part of the Float
.
Examples¶
val a = Duration::fromSeconds 62.123
// = #PT1M2.123S#
Duration::fromMinutes : Float -> Duration
¶
The function Duration::fromMinutes
creates a Duration
from a Float
representing minutes.
Examples¶
val a = Duration::fromMinutes 62.5
// = #PT1H2M30S#
Duration::fromHours : Float -> Duration
¶
The function Duration::fromHours
creates a Duration
from a Float
representing hours.
Examples¶
val a = Duration::fromHours 4.25
// = #PT4H15M#
Duration::fromDays : Float -> Duration
¶
The function Duration::fromDays
creates a Duration
from a Float
representing days.
Examples¶
val a = Duration::fromDays 2.5
// = #P2DT12H#
Duration::toSeconds : Duration -> Float
¶
The function Duration::toSeconds
converts a duration to a Float
the value of which is the total seconds of the duration.
Examples¶
val a = Duration::toSeconds #PT1M2.123S#
// = 62.123
Duration::addSeconds : DateTime -> Float -> DateTime
¶
The function Duration::addSeconds
adds the given number of seconds to a duration.
In contrast with DateTime::addSeconds this function takes a Float
which therefore allows one to add milliseconds to a timestamp.
Examples¶
val a = Duration::addSeconds #2018-01-01T00:00:00# 62.123
// = #2018-01-01T00:01:02.123#
Duration::between : DateTime -> DateTime -> Duration
¶
The function Duration::between
returns a Duration
which is the number of days, hours, minutes and seconds between the arguments.
Examples¶
val a = Duration::between #2018-02-01# #2018-03-01T00:00:00.123#
// = #P28DT0.123S#
val b = Duration::between #2018-02-01# #2018-03-01#
// = #P28D#
Duration::diffDateTimes : DateTime -> DateTime -> Duration
¶
The function Duration::diffDateTimes
returns a Duration
which is the number of days, hours, minutes and seconds that passes from the second argument to the first.
Examples¶
val a = Duration::diffDateTimes #2018-03-01T00:00:00.123# #2018-02-01#
// = #P28DT0.123S#
val b = Duration::diffDateTimes #2018-02-01# #2018-03-01#
// = #-P28D#
Duration::addDurations : Duration -> Duration -> Duration
¶
The function Duration::addDurations
adds two durations together.
Examples¶
val a = Duration::addDurations #PT1H2M3S# #PT60S#
// = #PT1H3M3S#
Duration::subDurations : Duration -> Duration -> Duration
¶
The function Duration::subDurations
subtracts the second duration from the
first.
Examples¶
val a = Duration::subDurations #PT1H2M3S# #PT60S#
// = #PT1H1M3S#
Duration::addToDateTime : Duration -> Duration -> DateTime
¶
The function Duration::addToDateTime
adds a Duration
to a DateTime
.
Examples¶
val a = Duration::addToDateTime #2018-01-01# #P1D#
// = #2018-01-02#
Duration::negate : Duration -> Duration -> Duration
¶
The function Duration::negate
negates a Duration
.
Examples¶
val a = Duration::negate #P1DT2S#
// = #-P1DT2S#
Duration::components : Duration -> Duration::Components
¶
The function Duration::components
returns a value of the type Duration::Components
which represents the individual components of time of the argument.
Examples¶
val a = Duration::components #P1DT2H62M3.333S#
// = Duration::Components {
// day = 1,
// hour = 3,
// minute = 2,
// second = 3.333
// }