Is future¶
isFuture validates that a Date instance represents a moment strictly after the current system time.
It performs a strict type check ensuring the value is a valid Date instance, then validates that the timestamp is greater than the current time. If the value is not a Date, is invalid, or represents a past/present time, the rule emits a single validation event. Otherwise, it produces no validation output.
Signature¶
Through the API:
.isFuture()
And internally:
export const isFuture: 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.in.past |
Date represents present time or past time |
Design rationale¶
- Provides a strict, predictable future date validation.
- First ensures the value is a valid Date instance.
- Then validates the timestamp is strictly greater than current time.
- Useful for ensuring dates represent upcoming events or future deadlines.
- 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¶
isFuture 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 represents present/past time, emits
date.in.past. - If the value is a valid future Date → returns an empty result set.
Examples¶
Future date¶
await isFuture(new Date(Date.now() + 86400000), "$");
// → []
Past date¶
await isFuture(new Date("2023-01-01"), "$");
// → [
// JaneEvent{
// kind: "error",
// code: "date.in.past",
// path: "$",
// ...
// }
// ]
Non-Date value¶
await isFuture("tomorrow", "$");
// → [
// JaneEvent{
// kind: "error",
// code: "date.not.date",
// path: "$",
// ...
// }
// ]