Skip to content

Commit f534e49

Browse files
committed
More explicit error on date() with convert: false
Fixes #919.
1 parent 47c051d commit f534e49

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

lib/date.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ internals.Date.prototype._base = function (value, state, options) {
4141
if (result.value instanceof Date && !isNaN(result.value.getTime())) {
4242
result.errors = null;
4343
}
44+
else if (!options.convert) {
45+
result.errors = this.createError('date.strict', null, state, options);
46+
}
4447
else {
4548
let type;
4649
if (internals.isIsoDate(this._flags.format)) {

lib/language.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ exports.errors = {
5555
},
5656
date: {
5757
base: 'must be a number of milliseconds or valid date string',
58+
strict: 'must be a valid date',
5859
min: 'must be larger than or equal to "{{limit}}"',
5960
max: 'must be less than or equal to "{{limit}}"',
6061
isoDate: 'must be a valid ISO 8601 date',

test/date.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe('date', () => {
5757
Joi.date().options({ convert: false }).validate('1-1-2013 UTC', (err, value) => {
5858

5959
expect(err).to.exist();
60-
expect(err.message).to.equal('"value" must be a number of milliseconds or valid date string');
60+
expect(err.message).to.equal('"value" must be a valid date');
6161
done();
6262
});
6363
});

0 commit comments

Comments
 (0)