Skip to content

Too late

tooLate validates that a Date instance is not later than the specified maximum boundary (inclusive comparison).

It performs a strict type check ensuring the value is a valid Date instance, then validates that the timestamp is less than or equal to the maximum boundary. If the value is not a Date, is invalid, or is after the maximum, the rule emits a single validation event. Otherwise, it produces no validation output.

Signature

Through the API:

.tooLate(max: Date)

And internally:

export const tooLate = (max: Date): 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.too.late Date is after the maximum boundary

Design rationale

  • Provides a strict, predictable maximum date boundary validation.
  • First ensures the value is a valid Date instance.
  • Then validates the timestamp is ≤ the maximum boundary.
  • Inclusive comparison allows exact boundary matches.
  • Alias for notAfter with different naming convention.
  • 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 JaneEvent objects.

Invoke

tooLate 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 after the maximum, emits date.too.late.
  • If the value is a valid Date ≤ maximum boundary → returns an empty result set.

Examples

Date at maximum boundary

const maxDate = new Date("2023-12-31");
await tooLate(maxDate)(new Date("2023-12-31"), "$");
// → []

Date after maximum

const maxDate = new Date("2023-12-31");
await tooLate(maxDate)(new Date("2024-01-01"), "$");
// → [
//     JaneEvent{
//       kind: "error",
//       code: "date.too.late",
//       path: "$",
//       ...
//     }
//   ]

Non-Date value

const maxDate = new Date("2023-12-31");
await tooLate(maxDate)("2023-12-31", "$");
// → [
//     JaneEvent{
//       kind: "error",
//       code: "date.not.date",
//       path: "$",
//       ...
//     }
//   ]