0

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.

Community
  • 1
  • 1
ksol
  • 11,835
  • 5
  • 37
  • 64

1 Answers1

1

You can replace the Date function entirely if you like (window.Date = ...), or just Date.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 a Date instance. 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.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875