Skip to content

Latest commit

 

History

History
171 lines (107 loc) · 2.98 KB

File metadata and controls

171 lines (107 loc) · 2.98 KB

datetime

Date and time. import datetime, effect.

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

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]

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

Convert a Unix timestamp (identity function for documentation clarity).

datetime.from_unix(1705320000)

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

Format a timestamp as ISO 8601 string.

datetime.to_iso(1705320000) // => "2024-01-15T12:00:00Z"

datetime.to_unix(ts: Int) -> Int

Get the Unix timestamp value (identity function).

datetime.to_unix(ts) // => 1705320000

datetime.year(ts: Int) -> Int

Extract the year from a timestamp.

datetime.year(ts) // => 2024

datetime.month(ts: Int) -> Int

Extract the month (1-12) from a timestamp.

datetime.month(ts) // => 1

datetime.day(ts: Int) -> Int

Extract the day of month (1-31) from a timestamp.

datetime.day(ts) // => 15

datetime.hour(ts: Int) -> Int

Extract the hour (0-23) from a timestamp.

datetime.hour(ts) // => 12

datetime.minute(ts: Int) -> Int

Extract the minute (0-59) from a timestamp.

datetime.minute(ts) // => 30

datetime.second(ts: Int) -> Int

Extract the second (0-59) from a timestamp.

datetime.second(ts) // => 45

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

Add n days to a timestamp.

datetime.add_days(ts, 7) // one week later

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

Add n minutes to a timestamp.

datetime.add_minutes(ts, 30)

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

Compute the difference in seconds between two timestamps.

datetime.diff_seconds(later, earlier) // => 3600

datetime.is_before(a: Int, b: Int) -> Bool

Check if timestamp a is before timestamp b.

datetime.is_before(earlier, later) // => true

datetime.is_after(a: Int, b: Int) -> Bool

Check if timestamp a is after timestamp b.

datetime.is_after(later, earlier) // => true