Not before¶
notBefore validates that a Date instance is not before the specified minimum boundary (inclusive comparison).
It performs a strict type check ensuring the value is a valid Date instance, then validates that the timestamp is greater than or equal to the minimum boundary. If the value is not a Date, is invalid, or is before the minimum, the rule emits a single validation event. Otherwise, it produces no validation output.
Signature¶
Through the API:
.notBefore(min: Date)
And internally:
export const notBefore = (min: Date): ValidationRule
(value: unknown, path: FieldPath) => Promise<ReadonlyArray<JaneEvent>>
Events¶
| Event code | Description |
|---|---|
date.not.date |
Value is not a Date instance |
date.is.invalid |
Date instance represents an invalid date |
date.too.early |
Date is before the minimum boundary |
Design rationale¶
- Provides a strict, predictable minimum date boundary validation.
- First ensures the value is a valid Date instance.
- Then validates the timestamp is ≥ the minimum boundary.
- Inclusive comparison allows exact boundary matches.
- Never coerces or normalizes — validation is explicit and opt-in.
- Emits exactly one event per failure for clarity and composability.
- Async-compatible and returns a readonly array of
JaneEventobjects.
Invoke¶
notBefore runs only when explicitly included in a boundary or pipeline. It does not run automatically.
The rule activates when:
- The value is any JavaScript value.
- If the value is not a Date instance, emits
date.not.date. - If the value is a Date but invalid, emits
date.is.invalid. - If the value is a valid Date but before the minimum, emits
date.too.early. - If the value is a valid Date ≥ minimum boundary → returns an empty result set.
Examples¶
Date at minimum boundary¶
const minDate = new Date("2023-01-01");
await notBefore(minDate)(new Date("2023-01-01"), "$");
// → []
Date before minimum¶
const minDate = new Date("2023-01-01");
await notBefore(minDate)(new Date("2022-12-31"), "$");
// → [
// JaneEvent{
// kind: "error",
// code: "date.too.early",
// path: "$",
// ...
// }
// ]
Non-Date value¶
const minDate = new Date("2023-01-01");
await notBefore(minDate)("2023-01-01", "$");
// → [
// JaneEvent{
// kind: "error",
// code: "date.not.date",
// path: "$",
// ...
// }
// ]