adopted-ember-addons / ember-validators

A collection of EmberJS validators
Other
24 stars 40 forks source link

[Bug] `date value is not finite in DateTimeFormat.format()` when passing locale `de` & specific `format` #137

Open mkszepp opened 1 year ago

mkszepp commented 1 year ago

Description

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.

https://github.com/rwwagner90/ember-validators/blob/1282748147a691f3fcffacb0c478a676cc9e309a/addon/date.js#L141-L146

Fix:

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.

Enviroment

Ember: v3.28.x / v4.x Ember Validators: v4.1.2

mkszepp commented 1 year ago

@RobbieTheWagner is there possible to get a release with this fix?