Weekday¶
weekday validates that a Date instance falls on a specific weekday (0-6, where 0=Sunday, 6=Saturday).
It performs a strict type check ensuring the value is a valid Date instance, then validates that the UTC weekday matches the required value. If the value is not a Date, is invalid, or falls on a different weekday, the rule emits a single validation event. Otherwise, it produces no validation output.
Signature¶
Through the API:
.weekday(required: number)
And internally:
export const weekday = (required: number): 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.weekday |
Date does not fall on the required weekday |
Design rationale¶
- Provides a strict, predictable weekday validation.
- First ensures the value is a valid Date instance.
- Then compares UTC weekday using
getUTCDay()(0=Sunday, 6=Saturday). - Useful for business logic requiring specific days of the week.
- 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¶
weekday 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 wrong weekday, emits
date.not.weekday. - If the value is a valid Date on the required weekday → returns an empty result set.
Examples¶
Correct weekday (Monday = 1)¶
await weekday(1)(new Date("2023-01-02"), "$"); // Monday
// → []
Wrong weekday¶
await weekday(1)(new Date("2023-01-01"), "$"); // Sunday
// → [
// JaneEvent{
// kind: "error",
// code: "date.not.weekday",
// path: "$",
// ...
// }
// ]
Non-Date value¶
await weekday(1)("2023-01-02", "$");
// → [
// JaneEvent{
// kind: "error",
// code: "date.not.date",
// path: "$",
// ...
// }
// ]