before
The date is earlier than the date in a sibling field.
Signature
ts
function before(field: string, msg?: Message): Action<Date>Parameters
| Parameter | Type | Description |
|---|---|---|
field | string | Name of the sibling field |
msg | Message | Custom error message |
Error codes
| Code | When | Default message |
|---|---|---|
before | The date is not earlier than the sibling | Must be before {field} |
You can change the texts: see Messages & i18n.
Notes
Compared with the raw value of the sibling field — a date or a string. If the sibling is empty or not a date, the rule passes: that field's schema reports the error.
Example
ts
const Trip = object({ departure: pipe(coerce.date(), before('arrival')), arrival: coerce.date() });