Skip to content

Date range

dateRange validates that a start and end date form a proper chronological range.

If both fields resolve to valid Date objects and the start occurs after the end, the rule emits a boundary‑level error. This rule is ideal for validating temporal windows such as availability periods, enrollment windows, publication ranges, or any domain where chronological ordering matters.

Signature

export function dateRange(startKey: string, endKey: string): BoundaryRule

Parameters

Parameter Data type Description
startKey string The field expected to contain the start date.
endKey string The field expected to contain the end date.

Events

Event code Description
boundary.does.require-date-range The start date occurred after the end date.

Design rationale

  • Activates only when both fields resolve to actual Date instances.
  • Compares the two dates directly (start > end).
  • Emits a single boundary‑level error when the chronological order is invalid.
  • Does not modify field values or decisions — it only adds boundary‑level issues.
  • Keeps contributor expectations clear by enforcing explicit temporal ordering rules.

Invoke

dateRange runs during the boundary decision phase. It is not affected by normalization mode or parsing rules.

The rule activates when:

  • fields[startKey]?.final is a Date.
  • fields[endKey]?.final is a Date.
  • The start date is chronologically after the end date.

Examples

Valid date range

dateRange("startDate", "endDate");

// startDate = 2024‑01‑01
// endDate   = 2024‑01‑31
// → OK (no boundary issues)

Invalid date range

dateRange("startDate", "endDate");

// startDate = 2024‑02‑01
// endDate   = 2024‑01‑31
// → boundary.does.require-date-range at $

Missing or non‑date values — rule does nothing

dateRange("start", "end");

// start = undefined
// end   = new Date()
// → no comparison performed