time
This library exports three datatypes:
Datetime, Timedelta, and
Timezone.
Datetime is meant to be a low friction datatype; this means that it should
be relatively easy to create, modify, and convert to other types! It can be
formatted with strftime and parsed with strptime, both mirroring the C
formatting API.
Timedelta is used to add and subtract anything on the scale of seconds to
weeks from those times.
Timezone represents a timezone with a name, UTC offset, and DST flag.
Formatting
(load "git@github.com:carpentry-org/time@0.2.0")
(defn main []
(println*
&(Datetime.strftime
&(Timedelta.sub &(Datetime.now) &(Timedelta.days 2))
"%Y-%m-%d %I:%M:%S.%n %p %z")))
Parsing
(load "git@github.com:carpentry-org/time@0.2.0")
(defn main []
(match (Datetime.strptime "2024-03-15 14:30:00" "%Y-%m-%d %H:%M:%S")
(Result.Success dt) (println* &(Datetime.isoformat &dt))
(Result.Error e) (println* &e)))