Date is invalid¶
dateIsInvalid is a built‑in scan rule that detects Date instances whose timestamp resolves to NaN.
When the value is a Date and getTime() returns NaN, the rule emits a warn‑level date.is.invalid scan event containing the original value. If the value is not a Date or resolves to a valid timestamp, no events are emitted.
Signature¶
export const dateIsInvalid: ScanRule (raw: unknown, path: FieldPath) => JaneEvent[]
Events¶
| Event code | Description |
|---|---|
| date.is.invalid | Date instance resolves to a NaN timestamp. |
Design rationale¶
- Detects Date objects that cannot be represented as valid timestamps.
- Surfaces parsing failures and malformed date inputs early in the scan stage.
- Uses
Date.getTime()to determine validity (NaNindicates an invalid date). - Emits a warning when the timestamp is invalid.
- Provides metadata (
{ value }) for policy and analysis. - Performs no mutation or transformation of the input.
Invoke¶
dateIsInvalid runs automatically whenever the scan stage is enabled.
Activation methods:
- Enable scan explicitly:
jane.value(input).scan(). - Use a mode that enables scan:
strict()enables scan by default.moderate()andlax()do not enable scan unless.scan()is called.- Enable scan with policy:
jane.value(input).withPolicy({ mode: 'strict' }).
If scan is not enabled or if the value is not a valid Date instance, dateIsInvalid does not run and no invalid‑timestamp detection occurs.
Examples¶
Invalid date detected¶
const result = dateIsInvalid(new Date("not-a-date"), "$");
// → [ JaneEvent{ kind: "warn", code: "date.is.invalid", ... } ]
Valid date¶
const result = dateIsInvalid(new Date("2020-01-01"), "$");
// → []
Non‑Date value¶
const result = dateIsInvalid("2020-01-01", "$");
// → []