ward.time
local time = require("ward.time")
Wall clock
time.now() -> TimePointtime.now_table() -> table- returns a table with timestamp components
Parsing
time.parse_rfc3339(s) -> TimePoint|niltime.parse_rfc2822(s) -> TimePoint|niltime.parse(s) -> TimePoint|nil- best-effort parser
Construction
time.from_timestamp(seconds, nanos?) -> TimePointtime.utc(y, m, d, hh?, mm?, ss?, nanos?) -> TimePoint
Durations
time.duration(x) -> Duration
Accepts:
- number: whole seconds
- string: human readable duration (e.g.
500ms,1.5s,2h) - Duration userdata
Examples:
local d1 = time.duration(2)
local d2 = time.duration("250ms")
local d3 = time.duration("2h")
Monotonic time
time.instant_now() -> InstantPoint
Timers (return awaitables)
These return userdata you must call () or :wait().
time.sleep(duration) -> SleepAwaitabletime.after(duration, callback?) -> AfterAwaitabletime.interval(duration) -> IntervalTimertime.timeout(awaitable, duration) -> TimeoutAwaitable
Examples:
-- sleep
time.sleep("200ms"):wait()
-- after
local v = time.after("1s", function() return "done" end):wait()
print(v)
-- interval
local it = time.interval("1s")
for _ = 1, 3 do
print("tick", it())
end
-- timeout
local a = time.sleep("5s")
local ok, err = pcall(function()
time.timeout(a, "200ms"):wait()
end)
print(ok, err)
Blocking sleep
time.sleep_blocking(duration) -> true