Skip to content
Draft

time

The time module provides date, time, and duration functionality.

import time
import { now, format, sleep } from time

Get current time:

@now = @time#now()

Get today’s date:

@today = @time#today()

Get Unix timestamp:

@timestamp = @time#unix_timestamp()

Create a duration of seconds:

@duration = @time#seconds(30)

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)

Create a duration of milliseconds:

@duration = @time#milliseconds(500)

Pause execution:

@time#sleep(seconds(5))
@time#sleep(milliseconds(500))

Sleep until a specific time:

@target = @time#now() + @time#hours(1)
@time#sleep_until(@target)

Format a time:

@now = @time#now()
@formatted = @time#format(@now, "YYYY-MM-DD HH:mm:ss")
@// "2026-08-26 14:30:00"
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
@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"

Parse time from string:

@time = @time#parse("2026-08-26 14:30:00", "YYYY-MM-DD HH:mm:ss")

Parse RFC3339 format:

@time = @time#parse_rfc3339("2026-08-26T14:30:00Z")

Get year:

@year = @now#year @// 2026

Get month:

@month = @now#month @// 8

Get day of month:

@day = @now#day @// 26

Get hour:

@hour = @now#hour @// 14

Get minute:

@minute = @now#minute @// 30

Get second:

@second = @now#second @// 0

Get day of week:

@weekday = @now#weekday @// "Wednesday"

Get day of year:

@day = @now#day_of_year @// 238

Add duration to time:

@future = @now + @time#days(7)
@later = @now + @time#hours(3)

Subtract duration from time:

@past = @now - @time#days(30)
@earlier = @now - @time#minutes(15)

Get duration between two times:

@duration = @time#difference(@start, @end)
@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 @// false

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()

Measure execution time:

@sw = @time#stopwatch()
@// ... do work ...
@ms = @time#elapsed_ms(@sw)

Get UTC time:

@utc = @time#utc()

Get local time:

@local = @time#local()

Set time zone:

@time = @time#with_zone("America/New_York")

Execute after delay:

@timer = @time#set_timeout(seconds(5), fn() =>
write("5 seconds passed")
fin action.)

Execute repeatedly:

@count = 0
@interval = @time#set_interval(seconds(1), fn() =>
@count = @count + 1
write("Tick " + string(@count))
fin action.)

Cancel a timeout:

@time#clear_timeout(@timer)

Cancel an interval:

@time#clear_interval(@interval)

Check leap year:

@time#is_leap_year(2026) @// false
@time#is_leap_year(2024) @// true

Get days in month:

@time#days_in_month(2026, 2) @// 28
@time#days_in_month(2024, 2) @// 29

Get days in year:

@time#days_in_year(2024) @// 366

Convert duration to human-readable string:

@time#humanize(@time#minutes(90)) @// "1 hour 30 minutes"
@time#humanize(@time#seconds(3661)) @// "1 hour 1 minute"

Relative time string:

@past = @time#now() - @time#hours(2)
@time#time_ago(@past) @// "2 hours ago"