Is past¶
isPast validates that a Date instance represents a moment strictly before the current system time.
It performs a strict type check ensuring the value is a valid Date instance, then validates that the timestamp is less than the current time. If the value is not a Date, is invalid, or represents a future/present time, the rule emits a single validation event. Otherwise, it produces no validation output.
Signature¶
Through the API:
.isPast()
And internally:
export const isPast: 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.in.future |
Date represents present time or future time |
Design rationale¶
- Provides a strict, predictable past date validation.
- First ensures the value is a valid Date instance.
- Then validates the timestamp is strictly less than current time.
- Useful for ensuring dates represent completed events or historical data.
- 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¶
isPast 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 represents present/future time, emits
date.in.future. - If the value is a valid past Date → returns an empty result set.
Examples¶
Past date¶
await isPast(new Date("2023-01-01"), "$");
// → []
Future date¶
await isPast(new Date(Date.now() + 86400000), "$");
// → [
// JaneEvent{
// kind: "error",
// code: "date.in.future",
// path: "$",
// ...
// }
// ]
Non-Date value¶
await isPast("2023-01-01", "$");
// → [
// JaneEvent{
// kind: "error",
// code: "date.not.date",
// path: "$",
// ...
// }
// ]