Skip to content

before ​

The date is earlier than the date in a sibling field.

Signature ​

ts
function before(field: string, msg?: Message): Action<Date>

Parameters ​

ParameterTypeDescription
fieldstringName of the sibling field
msgMessageCustom error message

Error codes ​

CodeWhenDefault message
beforeThe date is not earlier than the siblingMust 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() });

See also ​