-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Description
Observed in 4.8.0
The "now" keyword passed to date.min and date.max creates a new Date when the schema is compiled.
It would make more sense if the date was created when validating the schema.
In this example the validation fails because test_date is created one second after the schema.
var Joi = require('joi');
var schema = Joi.date().max('now');
var test_date;
setTimeout(function() {
test_date = new Date();
}, 1000);
setTimeout(function() {
var result = Joi.validate(test_date, schema);
// result.error -> "validate: value must be less than or equal to ..."
console.log('Validation error:', result.error);
}, 2000);A solution could be to keep "now" in the _tests part of the schema and convert to date when validating:
{
"isJoi": true,
"_type": "date",
"_tests": [
{
"name": "max",
"arg": "now"
}
]
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugBug or defectBug or defect