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.
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 8Construct a Duration from a given number of seconds.
Convert a Duration to a value in seconds.
Duration.milliseconds 10 |> Duration.inSeconds
--> 0.01Construct a Duration from a given number of milliseconds.
Duration.milliseconds 5000
--> Duration.seconds 5Convert a Duration to a value in milliseconds.
Duration.seconds 0.5 |> Duration.inMilliseconds
--> 500Construct a Duration from a given number of minutes.
Duration.minutes 3
--> Duration.seconds 180Convert a Duration to a value in minutes.
Duration.seconds 90 |> Duration.inMinutes
--> 1.5Construct a Duration from a given number of hours.
Duration.hours 1
--> Duration.seconds 3600Convert a Duration to a value in hours.
Duration.minutes 120 |> Duration.inHours
--> 2Construct 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 24Convert a Duration to a value in days.
Duration.hours 72 |> Duration.inDays
--> 3Construct a Duration from a given number of weeks.
Duration.weeks 1
--> Duration.days 7Convert a Duration to a value in weeks.
Duration.days 28 |> Duration.inWeeks
--> 4Construct 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.25Convert a Duration to a value in Julian years.
Duration.hours 10000 |> Duration.inJulianYears
--> 1.1407711613050422