Expand description
Date/Time/Timestamp/Interval support for Citadel SQL.
Thin wrapper around jiff so the rest of the codebase doesn’t depend on it
directly. Timestamps are UTC microseconds since 1970-01-01. INTERVAL is
PG-compatible: (months: i32, days: i32, micros: i64).
Constants§
- DATE_
INFINITY_ DAYS - i64 µs / 86_400_000_000 wraps to i32 for max representable date: ~292k years.
- DATE_
NEG_ INFINITY_ DAYS - MICROS_
PER_ DAY - Microseconds per day.
- MICROS_
PER_ HOUR - Microseconds per hour.
- MICROS_
PER_ MIN - Microseconds per minute.
- MICROS_
PER_ SEC - Microseconds per second.
- TS_
INFINITY_ MICROS - TS_
NEG_ INFINITY_ MICROS
Functions§
- add_
days_ to_ date - add_
interval_ to_ date - PG rule: DATE + INTERVAL always yields TIMESTAMP.
- add_
interval_ to_ time - add_
interval_ to_ timestamp - age
- AGE(a, b) — symbolic diff preserving months/years. Uses jiff’s Span rounding to Year unit.
- current_
time_ micros - date_
to_ ts - Convert a date to a timestamp at midnight UTC.
- date_
trunc - days_
to_ ymd - Convert i32 days-since-1970 to civil Gregorian (year, month, day).
- extract
- format_
date - format_
interval - format_
time - format_
timestamp - format_
timestamp_ in_ zone - hmsn_
to_ micros - Convert (hour, minute, second, subsec_micros) to µs since midnight.
- interval_
to_ total_ micros - PG-normalized total µs for comparison purposes (30-day month, 24-hour day).
- is_
infinity_ date - is_
infinity_ ts - justify_
days - justify_
hours - justify_
interval - micros_
to_ hmsn - Convert µs-since-midnight to (hour, minute, second, subsec_micros).
- now_
micros - parse_
date - Parse an ISO 8601 DATE literal (
YYYY-MM-DD, optionalBCsuffix,'infinity'/'-infinity'). - parse_
interval - Parse a SQL INTERVAL literal. Accepts PG verbose form (
'1 year 2 months 3 days 04:05:06.789'), SQL standard qualified form ('5' DAY), and ISO 8601 duration ('P1Y2M3DT4H5M6S'). - parse_
time - Parse an ISO 8601 TIME literal (
HH:MM:SS[.ffffff]). - parse_
timestamp - Parse an ISO 8601 TIMESTAMP literal (naive
YYYY-MM-DD[T ]HH:MM:SS[.ffffff]or with offset/zone). AcceptsZ, fixed offsets (+HH:MM), and IANA zone names (America/New_York).'infinity'/'-infinity'map to sentinel values. - pg_
normalized_ interval_ cmp - Session-agnostic util used by eval.rs for SQL INTERVAL comparison normalization.
- resolve_
timezone - Accepts IANA names,
Z,UTC, and ISO-8601 fixed offsets; rejects POSIXUTC+5shorthand (sign-inverted in POSIX, ambiguous in practice). - strftime
- subtract_
timestamps - PG
timestamp - timestamp: returns(days, remainder_micros)with months = 0. - today_
days - ts_
combine - Combine i32 date-days and i64 µs-of-day into µs-since-1970-UTC.
- ts_
split - Split µs since 1970-UTC into
(date_days, time_micros). - ts_
to_ date_ floor - Floor-divide timestamp µs to date days (correct for pre-1970 negative values).
- txn_
or_ clock_ micros - Read the cached txn-start clock if one is installed, else a fresh
now_micros(). Used byNOW/CURRENT_TIMESTAMP/CURRENT_DATE/LOCALTIMESTAMP. - with_
txn_ clock - Install a txn-start timestamp for the duration of
f. Restores the previous value on return (nested-safe). - ymd_
to_ days - Convert (year, month, day) Gregorian to i32 days-since-1970.