Date now required¶
dateNowRequired validates that a Date instance represents today's date.
It performs a strict type check ensuring the value is a Date instance, then validates that the date matches today's year, month, and day in UTC. If the value is not a Date or doesn't represent today, the rule emits a single validation event. Otherwise, it produces no validation output.
Signature¶
Through the API:
.dateNowRequired()
And internally:
export const dateNowRequired: ValidationRule
(value: unknown, path: FieldPath) => Promise<ReadonlyArray<JaneEvent>>
Events¶
| Event code | Description |
|---|---|
date.not.date |
Value is not a Date instance |
date.now.undefined |
Date does not represent today's date |
Design rationale¶
- Provides a strict, predictable "today's date" validation.
- First ensures the value is a Date instance.
- Then compares year, month, and day in UTC timezone.
- Useful for enforcing current date requirements.
- 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¶
dateNowRequired 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 not today's date, emits
date.now.undefined. - If the value is a Date representing today → returns an empty result set.
Examples¶
Today's date¶
await dateNowRequired(new Date(), "$");
// → []
Past date¶
await dateNowRequired(new Date("2023-01-01"), "$");
// → [
// JaneEvent{
// kind: "error",
// code: "date.now.undefined",
// path: "$",
// ...
// }
// ]
Non-Date value¶
await dateNowRequired("today", "$");
// → [
// JaneEvent{
// kind: "error",
// code: "date.not.date",
// path: "$",
// ...
// }
// ]