DateTime
DateTime module: date/time types and arithmetic.
Types: Date(year, month, day) -- Gregorian calendar, month 1-12, day 1-31 Time(hour, min, sec) -- 24-hour clock, all zero-based except day DateTime(date, time) -- combined date and time
Timestamps are Unix timestamps: integer seconds since 1970-01-01 00:00:00 UTC. now() returns the current time as a Unix timestamp (Int).
Calendar arithmetic assumes the proleptic Gregorian calendar throughout. Day-of-week encoding: 0 = Sunday, 1 = Monday, ..., 6 = Saturday.
Types
Functions
Return the current Unix timestamp as an Int (seconds since 1970-01-01 UTC).
Convert a Unix timestamp (Int seconds) to a DateTime.
DateTime.from_timestamp(0) -- DateTime(Date(1970, 1, 1), Time(0, 0, 0)) DateTime.from_timestamp(86400) -- DateTime(Date(1970, 1, 2), Time(0, 0, 0))
Convert a DateTime to a Unix timestamp (Int seconds since 1970-01-01 UTC).
DateTime.to_timestamp(DateTime(Date(1970, 1, 1), Time(0, 0, 0))) -- 0
Add n days to a DateTime. n may be negative.
Add n hours to a DateTime. n may be negative.
Add n seconds to a DateTime. n may be negative.
Add n milliseconds to a DateTime. n may be negative.
Add a Duration (stored in milliseconds) to a DateTime.
Difference between two DateTimes in seconds. diff_seconds(a, b) = to_timestamp(a) - to_timestamp(b).
Compare two DateTimes. Returns -1 if a < b, 0 if a == b, 1 if a > b.
Return the day of the week for the date component of a DateTime. 0 = Sunday, 1 = Monday, ..., 6 = Saturday. (January 1, 1970 was a Thursday = 4.)
Format a DateTime as a string. Supported specifiers: %Y %m %d %H %M %S %%
Example: DateTime.format(dt, "%Y-%m-%d %H:%M:%S")
Parse a DateTime from a string. Supports: "YYYY-MM-DD" and "YYYY-MM-DD HH:MM:SS". Returns Ok(DateTime) or Err(message).