Skip to content

Customize formatting for dates in error messages of min/max/greater/less (with ISO default) #1762

@tomyam1

Description

@tomyam1

Describe the problem you are trying to fix (provide as much context as possible)

Error messages for min, max, greater and less of the date type use the default date string formatting which results in unreadable error messages, e.g.:

const Joi = require('joi');
Joi.assert(
    new Date('2000-01-01T00:00:00.000Z'),
    Joi.date().less(new Date('2000-01-01T00:00:00.000Z')
));
[1] "value" must be less than "Sat Jan 01 2000 02:00:00 GMT+0200 (Jerusalem Standard Time)"

They also use the local timezone making it harder to unit tests for the expected message string.

Using ISO formatting would result a) more readable error message b) always in UTC:

[1] "value" must be less than "2000-01-01T00:00:00.000Z"

Which API (or modification of the current API) do you suggest to solve that problem ?

Convert the limit parameter to string using .toISOString() before passing it to createError

Are you ready to work on a pull request if your suggestion is accepted ?

Yes.

Metadata

Metadata

Assignees

Labels

breaking changesChange that can breaking existing codefeatureNew functionality or improvement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions