luz-clock¶
Date and time utilities included with Luz. No installation needed.
Moment¶
now()¶
Returns a dict with all components of the current local time.
| Key | Description |
|---|---|
year |
Four-digit year |
month |
Month (1–12) |
day |
Day of month (1–31) |
hour |
Hour (0–23) |
min |
Minute (0–59) |
sec |
Second (0–59) |
ms |
Milliseconds (0–999) |
weekday |
Day of week (0=Monday … 6=Sunday) |
yearday |
Day of year (1–366) |
today()¶
Returns only the date part: {year, month, day}.
current_time()¶
Returns only the time part: {hour, min, sec, ms}.
stamp()¶
Returns the current Unix timestamp (seconds since 1970-01-01) as a float.
Format¶
fmt(pattern)¶
Formats the current date/time using a pattern string.
| Pattern | Output |
|---|---|
%Y |
Four-digit year |
%m |
Month (01–12) |
%d |
Day (01–31) |
%H |
Hour 24h (00–23) |
%M |
Minute (00–59) |
%S |
Second (00–59) |
%A |
Full weekday name |
%B |
Full month name |
%I |
Hour 12h (01–12) |
%p |
AM/PM |
write(fmt("%Y-%m-%d")) # 2026-03-22
write(fmt("%H:%M:%S")) # 17:05:42
write(fmt("%A, %B %d %Y")) # Sunday, March 22 2026
day_name(n) / day_short(n)¶
Returns the full or abbreviated name of a weekday (0=Monday … 6=Sunday).
month_name(n) / month_short(n)¶
Returns the full or abbreviated name of a month (1–12).
is_leap(yr)¶
Returns true if the given year is a leap year.
Calc¶
since(ts)¶
Returns the seconds elapsed since a Unix timestamp.
diff(ts1, ts2)¶
Returns the absolute difference in seconds between two timestamps.
add_secs(ts, n) / add_mins(ts, n) / add_hours(ts, n) / add_days(ts, n)¶
Returns a new timestamp offset by the given amount.
from_stamp(ts)¶
Converts a Unix timestamp to a time dict (same format as now()).
parse_stamp(date_str, pattern)¶
Parses a date string into a Unix timestamp.
to_secs(h, m, s)¶
Converts hours, minutes, seconds to total seconds.
from_secs(total)¶
Breaks a total seconds value into {hours, mins, secs}.