Is date¶
isDate validates that a value is a valid JavaScript Date instance.
It performs a strict type check ensuring the value is a Date instance, then validates that the Date is not an "Invalid Date" (NaN timestamp). If the value is not a Date or is invalid, the rule emits a single validation event. Otherwise, it produces no validation output.
Signature¶
Through the API:
.isDate()
And internally:
export const isDate: 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 (NaN timestamp) |
Design rationale¶
- Provides a strict, predictable Date instance validation.
- First ensures the value is a Date object using
instanceof Date. - Then validates the Date is not "Invalid Date" using
isNaN(date.getTime()). - 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¶
isDate 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 instance → returns an empty result set.
Examples¶
Valid Date¶
await isDate(new Date("2023-01-01"), "$");
// → []
Invalid Date instance¶
await isDate(new Date("invalid"), "$");
// → [
// JaneEvent{
// kind: "error",
// code: "date.is.invalid",
// path: "$",
// ...
// }
// ]
Non-Date value¶
await isDate("2023-01-01", "$");
// → [
// JaneEvent{
// kind: "error",
// code: "date.not.date",
// path: "$",
// ...
// }
// ]