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