datetime
Date, Time, and DateTime Functions
Functions
| Function | Description |
|---|---|
_dt_time_syscall | Internal: get current time via time(2) syscall 201. |
dt_is_leap | Check if year is a leap year. |
dt_days_in_month | Days in a given month (1-12). |
dt_date | Convert year/month/day to days since epoch (1970-01-01 = day 0). |
dt_year | Extract year from days since epoch. |
_dt_day_of_year | Internal: remaining days after subtracting full years. |
dt_month | Extract month from days since epoch. |
dt_day | Extract day-of-month from days since epoch. |
dt_weekday | Day of week: 0=Thu (epoch was Thursday), 1=Fri, …, 6=Wed. More useful: (dt_… |
dt_now | Current unix timestamp in seconds. |
dt_from_ts | Convert unix timestamp to days since epoch. |
_dt_write2 | Internal: write 2-digit number to buffer. |
_dt_write4 | Internal: write 4-digit number to buffer. |
dt_format | Format timestamp as “YYYY-MM-DD HH:MM:SS”. Returns length (always 19). |
dt_diff | Difference between two timestamps in seconds. |
dt_add_days | Add days to a timestamp. |
dt_add_hours | Add hours to a timestamp. |
Details
_dt_time_syscall
fn _dt_time_syscall() -> i64Internal: get current time via time(2) syscall 201.
dt_is_leap
fn dt_is_leap(year: i64) -> i64Check if year is a leap year.
dt_days_in_month
fn dt_days_in_month(year: i64, month: i64) -> i64Days in a given month (1-12).
dt_date
fn dt_date(year: i64, month: i64, day: i64) -> i64Convert year/month/day to days since epoch (1970-01-01 = day 0).
dt_year
fn dt_year(d: i64) -> i64Extract year from days since epoch.
_dt_day_of_year
fn _dt_day_of_year(d: i64) -> i64Internal: remaining days after subtracting full years.
dt_month
fn dt_month(d: i64) -> i64Extract month from days since epoch.
dt_day
fn dt_day(d: i64) -> i64Extract day-of-month from days since epoch.
dt_weekday
fn dt_weekday(d: i64) -> i64Day of week: 0=Thu (epoch was Thursday), 1=Fri, …, 6=Wed. More useful: (dt_weekday(d) + 3) % 7 gives 0=Mon..6=Sun.
dt_now
fn dt_now() -> i64Current unix timestamp in seconds.
dt_from_ts
fn dt_from_ts(ts: i64) -> i64Convert unix timestamp to days since epoch.
_dt_write2
fn _dt_write2(out: &i8, pos: i64, val: i64)Internal: write 2-digit number to buffer.
_dt_write4
fn _dt_write4(out: &i8, pos: i64, val: i64)Internal: write 4-digit number to buffer.
dt_format
fn dt_format(ts: i64, out: &i8, max: i64) -> i64Format timestamp as “YYYY-MM-DD HH:MM:SS”. Returns length (always 19).
dt_diff
fn dt_diff(a: i64, b: i64) -> i64Difference between two timestamps in seconds.
dt_add_days
fn dt_add_days(ts: i64, days: i64) -> i64Add days to a timestamp.
dt_add_hours
fn dt_add_hours(ts: i64, hours: i64) -> i64Add hours to a timestamp.