Date is before epoch¶
dateIsBeforeEpoch is a built‑in scan rule that detects Date values whose timestamp occurs before the Unix epoch (1970‑01‑01T00:00:00.000Z).
When the value is a Date instance and its timestamp is less than 0, the rule emits a warn‑level date.is.before-epoch scan event containing the observed timestamp and the epoch boundary. If the value is not a Date or is on or after the epoch, no events are emitted.
Signature¶
export const dateIsBeforeEpoch: ScanRule (raw: unknown, path: FieldPath) => JaneEvent[]
Events¶
| Event code | Description |
|---|---|
date.is.before-epoch |
Date timestamp occurs before the Unix epoch. |
Design rationale¶
- Detects timestamps earlier than the Unix epoch, which often indicate malformed or legacy data.
- Uses
Date.getTime()to compare the timestamp against the epoch boundary (0). - Emits a warning when the timestamp is negative.
- Provides metadata (
{ timestamp, epoch }) for policy and analysis. - Performs no mutation or transformation of the input.
Invoke¶
dateIsBeforeEpoch 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 Date instance, dateIsBeforeEpoch does not run and no epoch‑boundary detection occurs.
Examples¶
Date before epoch¶
const result = dateIsBeforeEpoch(new Date("1960-01-01"), "$");
// → [ JaneEvent{ kind: "warn", code: "date.is.before-epoch", ... } ]
Date on or after epoch¶
const result = dateIsBeforeEpoch(new Date("1975-01-01"), "$");
// → []
Non‑Date value¶
const result = dateIsBeforeEpoch("1970-01-01", "$");
// → []