Skip to content

dateField

const dateField: <Row>(input) => MemoryFieldSpec<Row>;

Defined in: filters/memory.ts:87

Allow-list a public field as a date filter over a row value read by path (a key, a dot path, or a getter). The row value may be a Date, an ISO-8601 string, epoch milliseconds, or any object with a numeric epochMilliseconds (Temporal.Instant, Temporal.ZonedDateTime). A date preset needs the resolveDate you pass to buildFilterPredicate, and becomes a half-open [start, end) window.

Type Parameter Default type
Row any
Parameter Type
input { path: MemoryAccessor<Row>; }
input.path MemoryAccessor<Row>

MemoryFieldSpec<Row>

import { buildFilterPredicate, dateField } from "@xtandard/lib/filters/memory";
// Your resolver turns the preset into instant bounds (this one is hard-coded).
const resolveDate = () => ({ start: new Date("2026-01-01T00:00:00Z"), end: new Date("2026-02-01T00:00:00Z") });
const { predicate } = buildFilterPredicate({
spec: { createdAt: dateField({ path: "createdAt" }) },
filters: [{ field: "createdAt", filter: { kind: "date", operator: "is", unit: "month", timeZone: "UTC", anchor: "2026-01-15T00:00:00" } }],
resolveDate,
});
predicate({ createdAt: new Date("2026-01-31T23:59:59Z") }); // → true
predicate({ createdAt: "2026-02-01T00:00:00Z" }); // → false (the end is exclusive)
predicate({ createdAt: null }); // → false