Date and time. import datetime, effect.
Get the current time as a Unix timestamp (seconds, UTC).
let ts = datetime.now()
Create a timestamp from year, month, day, hour, minute, second (UTC).
datetime.from_parts(2024, 1, 15, 12, 0, 0)
Parse an ISO 8601 date string into a timestamp.
datetime.parse_iso("2024-01-15T12:00:00Z") // => ok(1705320000)
Convert a Unix timestamp (identity function for documentation clarity).
datetime.from_unix(1705320000)
Format a timestamp using a pattern string.
datetime.format(ts, "%Y-%m-%d") // => "2024-01-15"
Format a timestamp as ISO 8601 string.
datetime.to_iso(1705320000) // => "2024-01-15T12:00:00Z"
Get the Unix timestamp value (identity function).
datetime.to_unix(ts) // => 1705320000
Extract the year from a timestamp.
datetime.year(ts) // => 2024
Extract the month (1-12) from a timestamp.
datetime.month(ts) // => 1
Extract the day of month (1-31) from a timestamp.
datetime.day(ts) // => 15
Extract the hour (0-23) from a timestamp.
datetime.hour(ts) // => 12
Extract the minute (0-59) from a timestamp.
datetime.minute(ts) // => 30
Extract the second (0-59) from a timestamp.
datetime.second(ts) // => 45
Get the day of week as a string (Monday-Sunday).
datetime.weekday(ts) // => "Monday"
Add n days to a timestamp.
datetime.add_days(ts, 7) // one week later
Add n hours to a timestamp.
datetime.add_hours(ts, 3)
Add n minutes to a timestamp.
datetime.add_minutes(ts, 30)
Add n seconds to a timestamp.
datetime.add_seconds(ts, 90)
Compute the difference in seconds between two timestamps.
datetime.diff_seconds(later, earlier) // => 3600
Check if timestamp a is before timestamp b.
datetime.is_before(earlier, later) // => true
Check if timestamp a is after timestamp b.
datetime.is_after(later, earlier) // => true