adopted-ember-addons / ember-moment

MIT License
399 stars 122 forks source link

"Invalid date" in Safari #323

Closed Redsandro closed 4 years ago

Redsandro commented 4 years ago

Using a pickupDate from my model as DS.attr('date'), I can't use moment-format in Safari like so:

{{moment-format model.pickupDate 'Y-MM-DD HH:mm'}}

It will show:

Invalid date

This issue is similar to the previously closed #187. The bug was closed by @ihomp after commenting:

I had in my model: bookingDate: DS.attr('date'), changed to bookingDate: DS.attr('string'),

However, this is a workaround, not a fix for this issue. The documentation states that the date passed to moment-format can be:

Any value(s) interpretable as a date/time by moment (a date String or a Moment or a Date...)

So I am passing a Date. It should work. If I pass this to moment in Safari manualy:

moment(new Date()).format('Y-MM-DD HH:mm')

It works as expected.

Why does the date get invalid in Safari after being passed through moment-format?

jasonmit commented 4 years ago

You're passing in a Date instance and not a String and momentjs warns against this because of browser inconsistencies in how Date's are handled across browsers.

This seems to be related to the browser inconsistency discussed here: https://momentjs.com/docs/#/parsing/string/