time
The time module provides date, time, and duration functionality.
Import
Section titled “Import”import timeimport { now, format, sleep } from timeCurrent Time
Section titled “Current Time”Get current time:
@now = @time#now()Get today’s date:
@today = @time#today()unix_timestamp
Section titled “unix_timestamp”Get Unix timestamp:
@timestamp = @time#unix_timestamp()Duration
Section titled “Duration”seconds
Section titled “seconds”Create a duration of seconds:
@duration = @time#seconds(30)minutes
Section titled “minutes”Create a duration of minutes:
@duration = @time#minutes(5)Create a duration of hours:
@duration = @time#hours(2)Create a duration of days:
@duration = @time#days(7)milliseconds
Section titled “milliseconds”Create a duration of milliseconds:
@duration = @time#milliseconds(500)Pause execution:
@time#sleep(seconds(5))@time#sleep(milliseconds(500))sleep_until
Section titled “sleep_until”Sleep until a specific time:
@target = @time#now() + @time#hours(1)@time#sleep_until(@target)Formatting
Section titled “Formatting”format
Section titled “format”Format a time:
@now = @time#now()@formatted = @time#format(@now, "YYYY-MM-DD HH:mm:ss")@// "2026-08-26 14:30:00"Format Tokens
Section titled “Format Tokens”| Token | Output |
|---|---|
YYYY |
4-digit year |
YY |
2-digit year |
MM |
Month (01-12) |
DD |
Day (01-31) |
HH |
Hour (00-23) |
mm |
Minute (00-59) |
ss |
Second (00-59) |
SSS |
Millisecond (000-999) |
dddd |
Day name |
mmm |
Month name |
Predefined Formats
Section titled “Predefined Formats”@time#format(@now, @time#RFC3339) @// "2026-08-26T14:30:00Z"@time#format(@now, @time#RFC1123) @// "Wed, 26 Aug 2026 14:30:00 GMT"@time#format(@now, @time#ISO8601) @// "2026-08-26T14:30:00+00:00"@time#format(@now, @time#DATE) @// "2026-08-26"@time#format(@now, @time#TIME) @// "14:30:00"Parsing
Section titled “Parsing”Parse time from string:
@time = @time#parse("2026-08-26 14:30:00", "YYYY-MM-DD HH:mm:ss")parse_rfc3339
Section titled “parse_rfc3339”Parse RFC3339 format:
@time = @time#parse_rfc3339("2026-08-26T14:30:00Z")Time Components
Section titled “Time Components”Get year:
@year = @now#year @// 2026Get month:
@month = @now#month @// 8Get day of month:
@day = @now#day @// 26Get hour:
@hour = @now#hour @// 14minute
Section titled “minute”Get minute:
@minute = @now#minute @// 30second
Section titled “second”Get second:
@second = @now#second @// 0weekday
Section titled “weekday”Get day of week:
@weekday = @now#weekday @// "Wednesday"day_of_year
Section titled “day_of_year”Get day of year:
@day = @now#day_of_year @// 238Time Arithmetic
Section titled “Time Arithmetic”Add duration to time:
@future = @now + @time#days(7)@later = @now + @time#hours(3)subtract
Section titled “subtract”Subtract duration from time:
@past = @now - @time#days(30)@earlier = @now - @time#minutes(15)difference
Section titled “difference”Get duration between two times:
@duration = @time#difference(@start, @end)Time Comparison
Section titled “Time Comparison”@a = @time#parse("2026-01-01", "YYYY-MM-DD")@b = @time#parse("2026-12-31", "YYYY-MM-DD")
@a < @b @// true@a > @b @// false@a == @b @// falseElapsed Time
Section titled “Elapsed Time”elapsed
Section titled “elapsed”Get elapsed time since a point:
@start = @time#now()@// ... do work ...@elapsed = @time#elapsed(@start)Create a timer:
@timer = @time#timer()@timer#start()@// ... do work ...@elapsed = @timer#elapsed()@timer#stop()stopwatch
Section titled “stopwatch”Measure execution time:
@sw = @time#stopwatch()@// ... do work ...@ms = @time#elapsed_ms(@sw)Time Zones
Section titled “Time Zones”Get UTC time:
@utc = @time#utc()Get local time:
@local = @time#local()with_zone
Section titled “with_zone”Set time zone:
@time = @time#with_zone("America/New_York")Timers and Intervals
Section titled “Timers and Intervals”set_timeout
Section titled “set_timeout”Execute after delay:
@timer = @time#set_timeout(seconds(5), fn() => write("5 seconds passed")fin action.)set_interval
Section titled “set_interval”Execute repeatedly:
@count = 0@interval = @time#set_interval(seconds(1), fn() => @count = @count + 1 write("Tick " + string(@count))fin action.)clear_timeout
Section titled “clear_timeout”Cancel a timeout:
@time#clear_timeout(@timer)clear_interval
Section titled “clear_interval”Cancel an interval:
@time#clear_interval(@interval)Calendar Functions
Section titled “Calendar Functions”is_leap_year
Section titled “is_leap_year”Check leap year:
@time#is_leap_year(2026) @// false@time#is_leap_year(2024) @// truedays_in_month
Section titled “days_in_month”Get days in month:
@time#days_in_month(2026, 2) @// 28@time#days_in_month(2024, 2) @// 29days_in_year
Section titled “days_in_year”Get days in year:
@time#days_in_year(2024) @// 366Time Humanization
Section titled “Time Humanization”humanize
Section titled “humanize”Convert duration to human-readable string:
@time#humanize(@time#minutes(90)) @// "1 hour 30 minutes"@time#humanize(@time#seconds(3661)) @// "1 hour 1 minute"time_ago
Section titled “time_ago”Relative time string:
@past = @time#now() - @time#hours(2)@time#time_ago(@past) @// "2 hours ago"