Value under this field must be a Date object or a string (that can be parsed using Date.parse() function). This rule accept Date object as argument, and compare that argument with value. If dateFromValue.getTime() >= dateFromArg.getTime() return an invalid object.
const [ passes, errors ] = await validate({
value1: new Date('2020-01-02'), // date object are accepted
value2: '2020-01-02', // parseable string also accepted
}, {
value1: dateBefore(new Date('2020-01-03')), // 2020-01-02 < 2020-01-03
value2: dateBefore(new Date('2020-01-03')),
});
Invalid examples:
const [ passes, errors ] = await validate({
value1: new Date('2020-01-02'),
value2: '20200101', // this string is not parseable by Date.parse()
value3: 1596255022145 // number is not accepted even this is valid unix epoch time
}, {
value1: dateBefore(new Date('2020-01-01')), // 2020-01-02 > 2020-01-01
value2: dateBefore(new Date('2020-01-01')), // failed because string is not parseable
value3: dateBefore(new Date('2020-01-01')), // failed because number is not accepted
});
Value under this field must be a
Date
object or astring
(that can be parsed usingDate.parse()
function). This rule acceptDate
object as argument, and compare that argument with value. IfdateFromValue.getTime() >= dateFromArg.getTime()
return an invalid object.Usage example:
Valid examples:
Invalid examples: