Duration
The duration modules provides the Duration
type and associated functions for representing time durations and performing date/time arithmetic.
Duration
An object representing a time duration. Constructing a duration or performing math which would overflow the limits of the Duration
will result in the value being saturated to the maximum or minimum value.
Duration : { days : I64, hours : I8, minutes : I8, seconds : I8, nanoseconds : I32 }
add : Duration, Duration -> Duration
Add two Duration
objects.
format : Duration, Str -> Str
Format a Time
object according to the given format string.
The following placeholders are supported:
{d}
: day (0-Num.max_i64){hh}
: 2-digit hour (00-23){h}
: hour (0-23){mm}
: 2-digit minute (00-59){m}
: minute (0-59){ss}
: 2-digit second (00-59){s}
: second (0-59){f}
or{f:}
: fractional part of the second{f:x}
: fractional part of the second with x digits{n}
: nanosecond (0-999,999,999)
format_unsigned : Duration, Str -> Str
Format a Time
object according to the given format string. Negative numbers will not include a minus sign.
The following placeholders are supported:
{d}
: day (0-Num.max_i64){hh}
: 2-digit hour (00-23){h}
: hour (0-23){mm}
: 2-digit minute (00-59){m}
: minute (0-59){ss}
: 2-digit second (00-59){s}
: second (0-59){f}
or{f:}
: fractional part of the second{f:x}
: fractional part of the second with x digits{n}
: nanosecond (0-999,999,999)
from_days : Int * -> Duration
Create a Duration
object from days.
from_hms :
Int *,
Int *,
Int *
-> Duration
from_hmsn :
Int *,
Int *,
Int *,
Int *
-> Duration
from_hours : Int * -> Duration
Create a Duration
object from hours.
from_minutes : Int * -> Duration
Create a Duration
object from minutes.
from_nanoseconds : Int * -> Duration
Create a Duration
object from nanoseconds.
from_seconds : Int * -> Duration
Create a Duration
object from seconds.
sub : Duration, Duration -> Duration
Subtract two Duration
objects.
to_days : Duration -> I64
Convert a Duration
object to days (truncates hours and lower).
to_hours : Duration -> I64
Convert a Duration
object to hours (truncates minutes and lower).
to_minutes : Duration -> I64
Convert a Duration
object to minutes (truncates seconds and lower).
to_nanoseconds : Duration -> I128
Convert a Duration
object to nanoseconds.
to_seconds : Duration -> I64
Convert a Duration
object to seconds (truncates nanoseconds).