std.localdatetime
A date and a time of day together, with no zone: 2024-02-29T15:04:05
on a calendar and a clock on the wall, which is still no instant, as
it comes at a different one in each place — an offset from UTC
(std.offset) makes it one, a std.offsetdatetime. NodaTime’s
LocalDateTime is the model: a std.localdate and a std.localtime,
ordered by the date, then the time. std.period’s addToDateTime
moves one by years, months and hours alike. Import it by a name,
import std.localdatetime as LocalDateTime, as its names are short.
import std.localdatetime as LocalDateTimeimport std.localtime as LocalTime
-- | the start of the day of the date-time-- | >>> maybe "" (\t -> show (startOfDay t)) (LocalDateTime.parse "2024-02-29T15:04:05")-- | "2024-02-29T00:00:00"startOfDay : LocalDateTime.LocalDateTime -> LocalDateTime.LocalDateTimestartOfDay t = LocalDateTime.make (LocalDateTime.date t) LocalTime.midnightLocalDateTime
data LocalDateTimeA date-time: its date and its time of day.
make
make : LocalDate.LocalDate -> LocalTime.LocalTime -> LocalDateTimeThe date at the time of day.
date
date : LocalDateTime -> LocalDate.LocalDateIts date.
time
time : LocalDateTime -> LocalTime.LocalTimeIts time of day.
instanceEqualityLocalDateTime
instance instanceEqualityLocalDateTime : Equality LocalDateTimeThe same date and the same time.
instanceOrderLocalDateTime
instance instanceOrderLocalDateTime : Order LocalDateTimeThe earlier first: by the date, then the time.
instanceDebugLocalDateTime
instance instanceDebugLocalDateTime : Debug LocalDateTimeAs show writes it, 2024-02-29T15:04:05, as NodaTime’s and
Rust’s chrono’s debug form is.
instanceShowLocalDateTime
instance instanceShowLocalDateTime : Show LocalDateTimeAs ISO 8601 writes it: the date as std.localdate writes it, a T,
the time as std.localtime writes it (2024-02-29T15:04:05,
-0001-12-31T23:59:59.5).
>>> make (LocalDate.fromEpochDays (-719529)) (fromMaybe LocalTime.noon (LocalTime.fromNanosecondOfDay 86399500000000))MkLocalDateTime (MkLocalDate (-1) 12 31) (MkLocalTime 86399500000000)>>> show (make (LocalDate.fromEpochDays (-719529)) (fromMaybe LocalTime.noon (LocalTime.fromNanosecondOfDay 86399500000000)))"-0001-12-31T23:59:59.5"parse
parse : String -> Maybe LocalDateTimeThe date-time ISO 8601 writes as s, extended: a date as
std.localdate’s parse reads it, a T (or a t), and a time as
std.localtime’s reads it (2024-02-29T15:04:05,
2024-02-29T15:04:05.25). Nothing if it writes none, or a field is
out of its range; an offset or a Z after it is not read here, but
by std.offsetdatetime.
>>> List.map (\s -> maybe "" show (parse s)) ["2024-02-29T15:04:05", "2024-02-29t15:04:05.250", "0000-01-01T00:00:00.000000001"]["2024-02-29T15:04:05", "2024-02-29T15:04:05.25", "0000-01-01T00:00:00.000000001"]>>> (List.map (\s -> maybe True (\_ -> False) (parse s)) ["2024-02-29 15:04:05", "2024-02-30T15:04:05", "2024-02-29T24:00:00", "2024-02-29T15:04:05Z", "2024-02-29T15:04", "2024-02-29", "2024-02-29T"] : List Bool)[True, True, True, True, True, True, True]>>> List.map (\p -> compare (fst p) (snd p)) [(parse "2024-02-29T23:00:00", parse "2024-03-01T01:00:00"), (parse "2024-02-29T15:04:05.5", parse "2024-02-29T15:04:05")][LT, GT]