The datetime module provides date/time creation, formatting, and arithmetic. Requires import datetime. DateTime is represented as Int (Unix timestamp in seconds, UTC).
Function Signature Description now() -> IntCurrent time as Unix timestamp (effect) from_parts(Int, Int, Int, Int, Int, Int) -> IntCreate from year, month, day, hour, minute, second parse_iso(String) -> Result[Int, String]Parse ISO 8601 string from_unix(Int) -> IntIdentity (documentation clarity)
Function Signature Description format(Int, String) -> StringFormat with pattern string to_iso(Int) -> StringFormat as ISO 8601 to_unix(Int) -> IntGet Unix timestamp (identity)
Function Signature Description year(Int) -> IntExtract year month(Int) -> IntExtract month (1-12) day(Int) -> IntExtract day (1-31) hour(Int) -> IntExtract hour (0-23) minute(Int) -> IntExtract minute (0-59) second(Int) -> IntExtract second (0-59) weekday(Int) -> StringDay of week (Monday-Sunday)
Function Signature Description add_days(Int, Int) -> IntAdd n days add_hours(Int, Int) -> IntAdd n hours add_minutes(Int, Int) -> IntAdd n minutes add_seconds(Int, Int) -> IntAdd n seconds diff_seconds(Int, Int) -> IntDifference in seconds
Function Signature Description is_before(Int, Int) -> BoolCheck if a is before b is_after(Int, Int) -> BoolCheck if a is after b
let ts = datetime . from_parts ( 2024 , 1 , 15 , 12 , 0 , 0 )
datetime . format ( ts , " %Y-%m-%d " ) // => "2024-01-15"
datetime . to_iso ( ts ) // => "2024-01-15T12:00:00Z"
datetime . year ( ts ) // => 2024
datetime . weekday ( ts ) // => "Monday"
datetime . add_days ( ts , 7 ) // one week later
datetime . diff_seconds ( later , earlier ) // => 3600