Skip to content

DatePresetSchema

const DatePresetSchema: ObjectSchema<{
anchor: GenericSchema<string, string>;
end: OptionalSchema<GenericSchema<string, string>, undefined>;
kind: LiteralSchema<"date", undefined>;
operator: PicklistSchema<readonly ["is", "before", "after", "between"], undefined>;
timeZone: SchemaWithPipe<readonly [StringSchema<undefined>, CheckAction<string, "Invalid IANA timezone">]>;
unit: PicklistSchema<readonly ["millisecond", "second", "minute", "hour", "day", "week", "month", "quarter", "halfYear", "year"], undefined>;
weekStartsOn: OptionalSchema<SchemaWithPipe<readonly [NumberSchema<undefined>, IntegerAction<number, undefined>, MinValueAction<number, 0, undefined>, MaxValueAction<number, 6, undefined>]>, undefined>;
}, undefined>;

Defined in: filters/schemas.ts:204

Validates a date period preset (the model’s DatePreset): operator (is/before/after/between), unit, a real IANA timeZone, a Temporal.PlainDateTime string anchor (and optional end), and an optional weekStartsOn integer 0–6. The anchor is a wall-clock time read in timeZone, not an instant (a Z-suffixed string is rejected); a date-only "2026-02-01" is accepted as midnight and normalized to "2026-02-01T00:00:00".

import * as v from "valibot";
import { DatePresetSchema } from "@xtandard/lib/filters/valibot";
const input = {
kind: "date", operator: "is", unit: "month",
timeZone: "America/Los_Angeles", anchor: "2026-02-01T00:00:00",
};
v.parse(DatePresetSchema, input);
// → `input`, typed as `DatePreset`
v.is(DatePresetSchema, { ...input, timeZone: "Mars/Olympus" });
// → false (not an IANA zone)