Passing a locale like de, it... with a specific format into before / onOrBefore/ after / onOrAfter validator is causing this error:
date value is not finite in DateTimeFormat.format().
This occures, because the parseAsDate is passing the locale to parseDate function, which returns in for locale en the date format 1.1.2015.
new Date('1.1.2015') returns a Invalid Date and this produces this error.
There is not necessary to pass locale to parseAsDate, because parseAsDate returns always a new Date object.
We can always pass en-us in parseDate function.
Description
Passing a
locale
likede
,it
... with a specificformat
intobefore
/onOrBefore
/after
/onOrAfter
validator is causing this error:date value is not finite in DateTimeFormat.format()
.This occures, because the
parseAsDate
is passing thelocale
toparseDate
function, which returns in for locale en the date format1.1.2015
.new Date('1.1.2015')
returns aInvalid Date
and this produces this error.https://github.com/rwwagner90/ember-validators/blob/1282748147a691f3fcffacb0c478a676cc9e309a/addon/date.js#L141-L146
Fix:
There is not necessary to pass
locale
toparseAsDate
, becauseparseAsDate
returns always anew Date
object. We can always passen-us
inparseDate
function.Enviroment
Ember:
v3.28.x
/v4.x
Ember Validators:v4.1.2