Weekend¶
weekend validates that a Date instance falls on a weekend (Saturday or Sunday).
It performs a strict type check ensuring the value is a valid Date instance, then validates that the UTC weekday is either 0 (Sunday) or 6 (Saturday). If the value is not a Date, is invalid, or falls on a weekday, the rule emits a single validation event. Otherwise, it produces no validation output.
Signature¶
Through the API:
.weekend()
And internally:
export const weekend: 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.not.weekend |
Date falls on a weekday (Monday-Friday) |
Design rationale¶
- Provides a strict, predictable weekend validation.
- First ensures the value is a valid Date instance.
- Then validates UTC weekday is 0 (Sunday) or 6 (Saturday).
- Useful for business logic requiring weekend-only dates.
- 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¶
weekend 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 falls on weekday, emits
date.not.weekend. - If the value is a valid Date on weekend → returns an empty result set.
Examples¶
Weekend date (Saturday)¶
await weekend(new Date("2023-01-07"), "$"); // Saturday
// → []
Weekend date (Sunday)¶
await weekend(new Date("2023-01-01"), "$"); // Sunday
// → []
Weekday date¶
await weekend(new Date("2023-01-02"), "$"); // Monday
// → [
// JaneEvent{
// kind: "error",
// code: "date.not.weekend",
// path: "$",
// ...
// }
// ]
Non-Date value¶
await weekend("2023-01-07", "$");
// → [
// JaneEvent{
// kind: "error",
// code: "date.not.date",
// path: "$",
// ...
// }
// ]