One of my projects doesn’t display some informations on safari while it does on chrome. After a few hours of searching, I found that the problem is related to how Safari implements new Date() & Date.parse.
I have some ideas one how to fix this (thanks to Invalid date in safari & Safari JS cannot parse YYYY-MM-DD date format?), but I was wondering if there is not a way to overload the Date object to fix this behaviour, while not breaking compatibility.
I’m a beginner in Js, so I don’t know if there is a way to make the browser use the built-in functions if they work, or one I supply if not. For what it’s worth, the projects is a rails 3.1 app with JQuery & Backbone.js
Thanks for your time!
— EDIT
For what it’s worth, I used Moment.js to fix this.
You can replace the
Datefunction entirely if you like (window.Date = ...), or justDate.parse(Date.parse = ...), but I wouldn’t recommend it. Instead, use a function of your own that understands the format you’re giving it, and have that function return aDateinstance. If you are going to be running your code on implementations that don’t yet support the ECMAScript 5 date format (and there are still a lot of users using browsers that don’t), you’ll have to parse the date yourself.