Skip to content

dateField

const dateField: (input) => PostgrestFieldSpec;

Defined in: filters/postgrest.ts:49

Allow-list a public field as a date filter over a PostgREST column (timestamptz/date). A date preset needs the resolveDate you pass to buildParams, and becomes a half-open gte/lt window with ISO-8601 instants.

Parameter Type
input { column: string; }
input.column string

PostgrestFieldSpec

import { buildParams, dateField } from "@xtandard/lib/filters/postgrest";
// 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 { params } = buildParams({
spec: { createdAt: dateField({ column: "created_at" }) },
filters: [{ field: "createdAt", filter: { kind: "date", operator: "is", unit: "month", timeZone: "UTC", anchor: "2026-01-15T00:00:00" } }],
resolveDate,
});
// params → [["created_at", "gte.2026-01-01T00:00:00.000Z"], ["created_at", "lt.2026-02-01T00:00:00.000Z"]]