DateTime
The following functions operate on the type DateTime
representing a Date
together with a Time
.
The definition is
type DateTime {
date : Date,
time : Time
}
Note that a DateTime
does not include a time zone and therefore does not correspond to a unique Instant
on the global timeline.
It is therefore not possible to add a Duration
to a DateTime
because the result is undefined.
For example, the result of adding 24 hours to 2020-10-25 01:00
could be either 2020-10-26 01:00
or 2020-10-26 00:00
depending on whether the time zone is America/New_York
or Europe/Copenhagen
, respectively, because the two regions observe daylight saving time in different periods.
If you need to perform arithmetic on calendar dates together with time of day, use the zoned time and date functions.
DateTime::addPeriod : Period -> DateTime -> DateTime
Add a Period
to the underlying calendar date. The time component is unchanged.
This function is partial and fails if the resulting date would be out of range; see Date::fromComponents.
Examples
val a = DateTime::addPeriod
(Period::from 0 0 1)
(DateTime {
date = Date::from 2020 December 25,
time = Time::from 1 0 0 0
})
// = DateTime {
// date = Date::from 2020 December 26,
// time = Time::from 1 0 0 0
// }