ianmackenzie/elm-units/1.0.0

NOTE: the latest version is 2.10.0

Duration

A Duration refers to an elapsed time in seconds, milliseconds, hours etc., as opposed to a specific instant in time (which would generally be represented by a Posix value). It is stored as a number of seconds.

type alias Duration =
type Seconds
from : Posix -> Posix -> Duration

Find the elapsed time from a start time to an end time. For example, assuming that nineAM and fivePM are two Time.Posix values on the same day:

Duration.from nineAM fivePM
--> Duration.hours 8
seconds : Float -> Duration

Construct a Duration from a given number of seconds.

inSeconds : Duration -> Float

Convert a Duration to a value in seconds.

Duration.milliseconds 10 |> Duration.inSeconds
--> 0.01
milliseconds : Float -> Duration

Construct a Duration from a given number of milliseconds.

Duration.milliseconds 5000
--> Duration.seconds 5
inMilliseconds : Duration -> Float

Convert a Duration to a value in milliseconds.

Duration.seconds 0.5 |> Duration.inMilliseconds
--> 500
minutes : Float -> Duration

Construct a Duration from a given number of minutes.

Duration.minutes 3
--> Duration.seconds 180
inMinutes : Duration -> Float

Convert a Duration to a value in minutes.

Duration.seconds 90 |> Duration.inMinutes
--> 1.5
hours : Float -> Duration

Construct a Duration from a given number of hours.

Duration.hours 1
--> Duration.seconds 3600
inHours : Duration -> Float

Convert a Duration to a value in hours.

Duration.minutes 120 |> Duration.inHours
--> 2
days : Float -> Duration

Construct a Duration from a given number of days. A day is defined as exactly 24 hours or 86400 seconds. Therefore, it is only equal to the length of a given calendar day if that calendar day does not include either a leap second or any added/removed daylight savings hours.

Duration.days 1
--> Duration.hours 24
inDays : Duration -> Float

Convert a Duration to a value in days.

Duration.hours 72 |> Duration.inDays
--> 3
weeks : Float -> Duration

Construct a Duration from a given number of weeks.

Duration.weeks 1
--> Duration.days 7
inWeeks : Duration -> Float

Convert a Duration to a value in weeks.

Duration.days 28 |> Duration.inWeeks
--> 4
julianYears : Float -> Duration

Construct a Duration from a given number of Julian years. A Julian year is defined as exactly 365.25 days, the average length of a year in the historical Julian calendar. This is 10 minutes and 48 seconds longer than a Gregorian year (365.2425 days), which is the average length of a year in the modern Gregorian calendar, but the Julian year is a bit easier to remember and reason about and has the virtue of being the 'year' value used in the definition of a light year.

Duration.julianYears 1
--> Duration.days 365.25
inJulianYears : Duration -> Float

Convert a Duration to a value in Julian years.

Duration.hours 10000 |> Duration.inJulianYears
--> 1.1407711613050422