datetime

Date, Time, and DateTime Functions

Functions

FunctionDescription
_dt_time_syscallInternal: get current time via time(2) syscall 201.
dt_is_leapCheck if year is a leap year.
dt_days_in_monthDays in a given month (1-12).
dt_dateConvert year/month/day to days since epoch (1970-01-01 = day 0).
dt_yearExtract year from days since epoch.
_dt_day_of_yearInternal: remaining days after subtracting full years.
dt_monthExtract month from days since epoch.
dt_dayExtract day-of-month from days since epoch.
dt_weekdayDay of week: 0=Thu (epoch was Thursday), 1=Fri, …, 6=Wed. More useful: (dt_…
dt_nowCurrent unix timestamp in seconds.
dt_from_tsConvert unix timestamp to days since epoch.
_dt_write2Internal: write 2-digit number to buffer.
_dt_write4Internal: write 4-digit number to buffer.
dt_formatFormat timestamp as “YYYY-MM-DD HH:MM:SS”. Returns length (always 19).
dt_diffDifference between two timestamps in seconds.
dt_add_daysAdd days to a timestamp.
dt_add_hoursAdd hours to a timestamp.

Details

_dt_time_syscall

fn _dt_time_syscall() -> i64

Internal: get current time via time(2) syscall 201.

dt_is_leap

fn dt_is_leap(year: i64) -> i64

Check if year is a leap year.

dt_days_in_month

fn dt_days_in_month(year: i64, month: i64) -> i64

Days in a given month (1-12).

dt_date

fn dt_date(year: i64, month: i64, day: i64) -> i64

Convert year/month/day to days since epoch (1970-01-01 = day 0).

dt_year

fn dt_year(d: i64) -> i64

Extract year from days since epoch.

_dt_day_of_year

fn _dt_day_of_year(d: i64) -> i64

Internal: remaining days after subtracting full years.

dt_month

fn dt_month(d: i64) -> i64

Extract month from days since epoch.

dt_day

fn dt_day(d: i64) -> i64

Extract day-of-month from days since epoch.

dt_weekday

fn dt_weekday(d: i64) -> i64

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

Current unix timestamp in seconds.

dt_from_ts

fn dt_from_ts(ts: i64) -> i64

Convert 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) -> i64

Format timestamp as “YYYY-MM-DD HH:MM:SS”. Returns length (always 19).

dt_diff

fn dt_diff(a: i64, b: i64) -> i64

Difference between two timestamps in seconds.

dt_add_days

fn dt_add_days(ts: i64, days: i64) -> i64

Add days to a timestamp.

dt_add_hours

fn dt_add_hours(ts: i64, hours: i64) -> i64

Add hours to a timestamp.