0

I have a very strange behavior in my web app. On one page, new Date() parsing works fine while on other pages, it seems like I get a totally different behavior from the new Date() parsing and it completely fails. I have verified that the Date object has not been overwritten extended or modified and I even tried using moment.js and I get the same results when it's converted to a Date object. I have also verified the same behavior in both Chrome and Edge. Any suggestions?

Page 1 - Seems to work fine, when I type into console.

new Date()

Mon Mar 25 2019 12:58:45 GMT-0400 (Eastern Daylight Time)

new Date("3/25/2019 12:29:51 PM")

Mon Mar 25 2019 12:29:51 GMT-0400 (Eastern Daylight Time)

Page 2 - For some reason parsing fails and returns a completely wrong Date value

new Date()

Mon Mar 25 2019 12:58:52 GMT-0400 (Eastern Daylight Time)

new Date("3/25/2019 12:29:51 PM")

Wed Dec 31 1969 19:00:00 GMT-0500 (Eastern Standard Time)

I also noticed that on page 1, Date.parse("3/25/2019 12:29:51 PM") works but when I try the same on page 2, it returns null.

everton
  • 7,579
  • 2
  • 29
  • 42
Paully
  • 582
  • 5
  • 12
  • `new Date("03/25/2019 12:29:51 PM")` -> "03" should work... – Rayon Mar 25 '19 at 17:11
  • Still got my console up on Page 2, it didn't work. new Date("03/25/2019 12:29:51 PM") >>>>> Wed Dec 31 1969 19:00:00 GMT-0500 (Eastern Standard Time) – Paully Mar 25 '19 at 17:13
  • Could you provide working fiddle or something ? – Rayon Mar 25 '19 at 17:13
  • Sorry I can't reproduce the whole page in a fiddle, it's an asp.net app with various partials.... it must be something on my page. PS - updated my post to include info about Date.parse() returning null on page 2 – Paully Mar 25 '19 at 17:17
  • Ahh!! i just saw that the problem page includes a script called https://github.com/datejs/Datejs , which probably IS modifying the Date object. I probably don't need it, I'll try removing it and seeing how things go. – Paully Mar 25 '19 at 17:20
  • FYI This doesn't seem to be a duplicate as RobG has marked. That has nothing to do with DateJS and an overwritten Date object. – Paully Apr 01 '19 at 04:34

1 Answers1

0

It seems Page 2 was actually using a script called DateJS (so it was modified) that had some bugs in it too, when I updated the version to the latest, all issues were resolved. Thanks Rayon for your help.

Paully
  • 582
  • 5
  • 12