Expand description
Dates and durations for the query binding (spec/surface §1.3 “Dates and
durations”, 4.8): the Dataview-parity function set, served as omgbase HOST
functions through oqx’s call_function / call_method seam. Port of the
reference’s oqx-js/dates.ts, function for function.
Two value conventions and no new value kinds:
• a DATE is an ISO-8601 string — YYYY-MM-DD (date-only) or
YYYY-MM-DDThh:mm:ss[.fff](Z|±hh:mm) — exactly what the store writes
for updated_at/ts and what OQX already orders chronologically by
code point (spec/oqx SEMANTICS §6);
• a DURATION is a number of seconds.
Arithmetic between them is METHODS (d.plus(s), a.until(b)), never the
+/- operators: + with a string operand concatenates (SEMANTICS §7),
so "2026-01-05" + 86400 is "2026-01-0586400" and must stay so.
Everything is total: a value that is not a date (or a duration) yields
absent (Null), so a where over mixed data filters quietly. Only a wrong
ARITY is an error (filter_invalid, the surface’s eval error). The one
impure input — the named points today, now, sow… — reads the HOST
clock, UTC, as the instant now_ms the caller threads in: the Surface
passes the clock it stamps commits with (OMGBASE_SPEC_CLOCK pins it; the
fixtures run under the corpus clock, so date("today") is 2026-09-27
there). The language itself has no clock.
The pure half (parse / render / shift / until / fields / format / the
duration grammar) is public for the unit tests; the two arms at the bottom
(date_function, date_method) are what context.rs and the constant
fold in query.rs call. Calendar arithmetic is done by hand (proleptic
Gregorian, days-from-civil) — no date crate, no new dependency.
Structs§
- Date
Value - A parsed date: the instant (milliseconds since the Unix epoch), the offset
it was WRITTEN in (minutes east of UTC;
0forZand for a date-only value), whether it is date-only, and whether it carried a fraction of a second as written (kept on render). - Duration
- A parsed duration: the calendar counts
yearsandmonthskept apart from the fixed-lengthseconds, sopluscan be calendar-aware whiledur()applies the 365-day / 30-day conventions. - Fields
- The fields of a value in the offset it was written in (
weekday1 = Monday … 7 = Sunday).
Constants§
- DATE_
FUNCTIONS - The free functions and their arity.
- DATE_
METHODS - The methods and their arity: on a date string, and (
dur_text/dur_iso) on a number. - MONTH_
SECONDS - Days per month / year under the fixed conventions
dur()applies. - NAMED_
POINTS - The named points
date()resolves against the clock. - YEAR_
SECONDS
Functions§
- calendar_
parts - A duration as
plusapplies it: the WHOLE years and months are calendar months; a fractional year or month count is not calendar — its fraction is 365-day / 30-day seconds — and joins the fixed-length seconds. - canonical_
date date(x)on a string that is not a named point: the canonical form, orNone.- date_
function call_functionarm:date(x)/dur(x);Nonefor any other name.- date_
function_ arity - The arity of
date/dur, orNonefor any other name. - date_
method call_methodarm: the date methods on a string receiver and the duration renderers on a number; a receiver of any other kind yields absent (the methods are total).Nonefor any other name.- date_
method_ arity - The arity of a date method, or
Nonefor any other name. - date_of
date(x): a named point against the clock, else the canonical ISO form, elseNone.- dur_iso
n.dur_iso(): the ISO-8601 durationP[nD][T[nH][nM][nS]]—PT1H30M,P2DT3H,PT45S,PT0Sfor zero, a leading-for a negative duration.Nonefor a non-number.- dur_of
dur(x): a number is that many seconds; a string is parsed; elseNone.- dur_
text n.dur_text():"2d 3h","1h 30m","45s"— days, hours, minutes, seconds, zero parts omitted,"0s"for zero, a leading-for a negative duration, a fractional second kept ("1.5s").Nonefor a non-number.- duration_
seconds - A duration’s length in seconds under the conventions: a year is 365 days, a month 30.
- fields_
of - The fields of the value in the offset it was written in.
- format_
date d.format(pattern):yyyyyear,MMmonth,ddday,HHhour,mmminute,sssecond (two digits each),MMMthe English month abbreviation (Jan),EEEthe English weekday abbreviation (Mon); every other character is literal. Fields are read in the written offset; a date-only value has00time fields.- named_
point - Resolve a named point at the instant
now_ms(UTC):nowis the instant with milliseconds (the form the store stamps commits in); the others are date-only —sow/eowthe Monday/Sunday of the current week,som/eomthe first/last day of the month,soy/eoyof the year.Nonefor a name that is not a point. - parse_
date - Parse an ISO-8601 date / datetime string;
Nonefor anything else (a non-string, a malformed string, an out-of-range field such as month 13 or hour 24). The shape:YYYY-MM-DD, optionallyT/t/space +hh:mm[:ss[.fff…]]+ an optional offset (Z,±hh:mm,±hhmm); a time without an offset is UTC; the fraction (1–9 digits,.or,) is truncated to milliseconds. - parse_
duration - Parse a duration string: Dataview’s
<number> <unit>pairs, each pair separated from the next by spaces, a comma, or nothing ("1h30m","2 days, 3 hours"; a trailing separator is malformed), units case-insensitive: y|yr|yrs|year|years, mo|mos|month|months, w|wk|wks|week|weeks, d|day|days, h|hr|hrs|hour|hours, m|min|mins|minute|minutes, s|sec|secs|second|seconds — or an ISO-8601 duration (P1DT2H,PT90M,P2W).Nonewhen it is neither. - plus_
minus d.plus(x)(sign1) /d.minus(x)(sign-1).- render_
date - The canonical string:
YYYY-MM-DDfor a date-only value; otherwiseYYYY-MM-DDThh:mm:ss+.fffwhen the value carries a fraction (as written, or because arithmetic produced one) +Zfor UTC or the written±hh:mm. - shift_
date - Shift a date by a whole number of calendar
months(the month field moves and the day is clamped to the new month’s length) and then byseconds. A date-only value stays date-only when the seconds are a whole number of days; otherwise it becomes a datetime in its offset (UTC for a date-only receiver). - stamp_
ms - A clock stamp (
YYYY-MM-DDThh:mm:ss.fffZ, the form theSurfacestamps commits in; any ISO datetime accepted) as milliseconds, or the wall clock when it does not parse. - until
a.until(b): seconds fromatob(negative whenbis earlier), by instant.- wall_
clock_ ms - The process wall clock in milliseconds since the Unix epoch — what a caller without a pinned clock resolves the named points against.