Import this module with import @time.
| Function |
Signature |
Description |
now |
() -> i64 |
Current Unix timestamp (seconds) |
now_ms |
() -> i64 |
Current Unix timestamp (milliseconds) |
now_ns |
() -> i64 |
Current Unix timestamp (nanoseconds) |
| Function |
Signature |
Description |
year |
(timestamp i64) -> i64 |
Get year |
month |
(timestamp i64) -> i64 |
Get month (1-12) |
day |
(timestamp i64) -> i64 |
Get day of month |
hour |
(timestamp i64) -> i64 |
Get hour |
minute |
(timestamp i64) -> i64 |
Get minute |
second |
(timestamp i64) -> i64 |
Get second |
weekday |
(timestamp i64) -> i64 |
Get day of week (0=Sunday) |
weekday_name |
(timestamp i64) -> string |
English weekday name ("Sunday".."Saturday"), matching weekday() numbering |
month_name |
(timestamp i64) -> string |
English month name ("January".."December") |
day_of_year |
(timestamp i64) -> i64 |
Day of the year, 1–366 |
days_in_month |
(year i64, month i64) -> i64 |
Days in month (1–12) of year, leap-year aware; panics (P0128) if month is outside 1–12 |
is_leap_year |
(year i64) -> bool |
Check if year is a leap year |
| Function |
Signature |
Description |
format |
(format string, timestamp i64) -> string |
Format time |
to_iso |
(timestamp i64) -> string |
ISO 8601 string |
date |
(timestamp i64) -> string |
Date (YYYY-MM-DD) |
to_clock |
(timestamp i64) -> string |
Time (HH:MM:SS) |
humanize |
(seconds i64) -> string |
Relative phrase for a signed delta: positive is past ("2 days ago"), negative is future ("in 1 hour"), 0 is "just now"; largest whole unit only |
format_duration |
(seconds i64) -> string |
"1h 30m 15s"; capped at hours (no days), zero components omitted unless the whole value is zero ("0s"), negative gets a leading - |
| Function |
Signature |
Description |
parse |
(s string, layout string) -> (i64, Error) |
Parse a time string into a Unix timestamp using strftime-style layout directives |
parse_duration |
(s string) -> (i64, Error) |
Parse "1h30m", "90s", "2d", "1h30m15s" (units s m h d) into total seconds; bad input yields a non-nil error and 0 |
Behavior:
parse and parse_duration are fallible functions. Single-variable assignment (mut ts i64 = time.parse(...)) is a compile-time error (E3089); the result must be destructured.
mut ts, err = time.parse(...) — inspect err (non-nil on invalid input).
mut ts, _ = time.parse(...) — discard the error; on invalid input ts is 0.
| Function |
Signature |
Description |
diff |
(t1 i64, t2 i64) -> i64 |
Difference in seconds (t2 - t1); negative if t1 is after t2 |
since |
(t i64) -> i64 |
Seconds elapsed from t to now; equivalent to diff(t, now()) |
add_days |
(timestamp i64, n i64) -> i64 |
timestamp shifted by n days (n may be negative); pure Unix arithmetic, no calendar/DST logic |
add_hours |
(timestamp i64, n i64) -> i64 |
timestamp shifted by n hours |
add_seconds |
(timestamp i64, n i64) -> i64 |
timestamp shifted by n seconds |
start_of_day |
(timestamp i64) -> i64 |
Unix timestamp of 00:00:00 UTC on the same day |
end_of_day |
(timestamp i64) -> i64 |
Unix timestamp of 23:59:59 UTC on the same day (start_of_day + 86399) |
| Function |
Signature |
Description |
tick |
() -> i64 |
High-resolution timestamp in nanoseconds |
elapsed_ms |
(start_tick i64) -> i64 |
Milliseconds elapsed since a tick |