DateTime
The DateTime module provides the DateTime
type as well as functions for working with combined date and time values.
These functions include functions for creating DateTime
objects from various numeric values, converting DateTime
s to and from ISO 8601 strings, and performing arithmetic operations on DateTime
s.
DateTime
DateTime : { date : Date, time: Time }
add : DateTime, Duration -> DateTime
Same as add_duration
add_days : DateTime, Int * -> DateTime
Add days to a DateTime
object.
add_duration : DateTime, Duration -> DateTime
Add a Duration
object to a DateTime
object. (May be deprecated in favor of add
in the future.)
add_minutes : DateTime, Int * -> DateTime
Add minutes to a DateTime
object.
add_months : DateTime, Int * -> DateTime
Add months to a DateTime
object.
add_hours : DateTime, Int * -> DateTime
Add hours to a DateTime
object.
add_nanoseconds : DateTime, Int * -> DateTime
Add nanoseconds to a DateTime
object.
add_seconds : DateTime, Int * -> DateTime
Add seconds to a DateTime
object.
add_years : DateTime, Int * -> DateTime
Add years to a DateTime
object.
after : DateTime, DateTime -> Bool
Determine if the first DateTime
occurs after the second DateTime
.
before : DateTime, DateTime -> Bool
Determine if the first DateTime
occurs before the second DateTime
.
compare :
DateTime,
DateTime
->
[
LT,
EQ,
GT
]
Compare two DateTime
objects.
If the first occurs before the second, it returns LT.
If the first and the second are equal, it returns EQ.
If the first occurs after the second, it returns GT.
equal : DateTime, DateTime -> Bool
Determine if the first DateTime
equals the second DateTime
.
format : DateTime, Str -> Str
Format a DateTime
object according to the given format string.
The following placeholders are supported:
{YYYY}
: 4-digit year{YY}
: 2-digit year{MM}
: 2-digit month (01-12){M}
: month (1-12){DD}
: 2-digit day of the month (01-31){D}
: day of the month (1-31){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 (in nanoseconds){f:x}
: fractional part of the second with x digits{n}
: nanosecond (0-999,999,999)
from_iso_str : Str -> Result DateTime [InvalidDateTimeFormat]
Convert an ISO 8601 string to a DateTime
object.
from_iso_u8 : List U8 -> Result DateTime [InvalidDateTimeFormat]
Convert an ISO 8601 list of UTF-8 bytes to a DateTime
object.
from_nanos_since_epoch : Int * -> DateTime
Convert the number of nanoseconds since the Unix epoch to a DateTime
object.
from_yd : Int *, Int * -> DateTime
Create a DateTime
object from the year and day of the year.
from_ymd :
Int *,
Int *,
Int *
-> DateTime
Create a DateTime
object from the year, month, and day.
from_yw : Int *, Int * -> DateTime
Create a DateTime
object from the year and week.
from_ywd :
Int *,
Int *,
Int *
-> DateTime
Create a DateTime
object from the year, week, and day of the week.
from_ymdhms :
Int *,
Int *,
Int *,
Int *,
Int *,
Int *
-> DateTime
Create a DateTime
object from the year, month, day, hour, minute, and second.
from_ymdhmsn :
Int *,
Int *,
Int *,
Int *,
Int *,
Int *,
Int *
-> DateTime
Create a DateTime
object from the year, month, day, hour, minute, second, and nanosecond.
sub : DateTime, DateTime -> Duration
Subtract two DateTime
objects to get the Duration
between them.
to_iso_str : DateTime -> Str
Convert a DateTime
object to an ISO 8601 string.
to_iso_u8 : DateTime -> List U8
Convert a DateTime
object to an ISO 8601 list of UTF-8 bytes.
to_nanos_since_epoch : DateTime -> I128
Convert a DateTime
object to the number of nanoseconds since the Unix epoch.
unix_epoch : DateTime
DateTime
object representing the Unix epoch (1970-01-01T00:00:00).