Before epoch¶
beforeEpoch validates that a Date instance represents a moment before the Unix epoch (January 1, 1970, 00:00:00 UTC).
It performs a strict type check ensuring the value is a Date instance, then validates that the timestamp is less than 0 (Unix epoch). If the value is not a Date or represents the epoch or later, the rule emits a single validation event. Otherwise, it produces no validation output.
Signature¶
Through the API:
.beforeEpoch()
And internally:
export const beforeEpoch: ValidationRule
(value: unknown, path: FieldPath) => Promise<ReadonlyArray<JaneEvent>>
Events¶
| Event code | Description |
|---|---|
date.not.date |
Value is not a Date instance |
date.is.before-epoch |
Date represents Unix epoch or later |
Design rationale¶
- Provides a strict, predictable pre-Unix epoch validation.
- First ensures the value is a Date instance.
- Then validates the timestamp is strictly less than 0.
- Useful for historical data or legacy system compatibility.
- 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¶
beforeEpoch 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 represents epoch or later, emits
date.is.before-epoch. - If the value is a Date before the Unix epoch → returns an empty result set.
Examples¶
Pre-epoch date¶
await beforeEpoch(new Date("1969-12-31"), "$");
// → []
Post-epoch date¶
await beforeEpoch(new Date("1970-01-01"), "$");
// → [
// JaneEvent{
// kind: "error",
// code: "date.is.before-epoch",
// path: "$",
// ...
// }
// ]
Non-Date value¶
await beforeEpoch("1969-12-31", "$");
// → [
// JaneEvent{
// kind: "error",
// code: "date.not.date",
// path: "$",
// ...
// }
// ]