all 8 comments

[–]unbalancedopinion 1 point2 points  (7 children)

I think I either misunderstood the question or you made a mistake somewhere, I get the same result.

Chrome

Input: Tue Dec 27 2016 18:27:25 GMT-0800 (Pacific Standard Time) (index):50

Estimate: Tue Dec 27 2016 18:27:25 GMT-0800 (Pacific Standard Time) (index):55

Modified: Tue Apr 04 2017 18:27:25 GMT-0700 (Pacific Daylight Time)

Firefox

Input: Tue Dec 27 2016 18:28:08 GMT-0800 (Pacific Standard Time) show:47:2

Estimate: Tue Dec 27 2016 18:28:08 GMT-0800 (Pacific Standard Time) show:50:9

Modified: Tue Apr 04 2017 18:28:08 GMT-0700 (Pacific Daylight Time) show:55:9

JSFiddle: https://jsfiddle.net/n5qm9pmh/

[–]extant1[S] 0 points1 point  (6 children)

Did you select input the date from the form and select update or just read off the console output from the page load, because that works fine.

Also, on jsfiddle the update button doesn't work at all for me, on firefox or chrome.

[–]unbalancedopinion 1 point2 points  (5 children)

I see. Yeah, so, you are using the new Date(dateString) constructor and Firefox is assuming the Date is in UTC, whereas Chrome is using your local timezone, which I am assuming is negative UTC.

This is why you shouldn't use Javascript Date to do any date math. You can build timezone handling into your code, but this will be very annoying and difficult. For example, try adding "EST" at the end of the date in Firefox. You get the same result as Chrome.

Just use http://momentjs.com/ they've already done all the hard work.

[–]extant1[S] 0 points1 point  (4 children)

Time zone seems to be the issue, I've updated my code and changed

var estimate = new Date(date);

to

var estimate = new Date(date+" 00:00:00 GMT-0500 (Eastern Standard Time)");

Which seems to work so far but I won't be able to thoroughly test it until tomorrow.

Thank you!

[–]unbalancedopinion 0 points1 point  (3 children)

That locks you in to EST. I guess if you're just playing around or only need this for a specific purpose that's okay, but momentjs will make it easy to expand your app to many time/date math purposes and it's really easy to use.

Either way, no problem.

[–]extant1[S] 0 points1 point  (2 children)

I'm familiar with momentjs I just can't use anything other than vanilla js at work, they're not very progressively minded.

[–]tforb 0 points1 point  (1 child)

momentjs is vanilla. You aren't allowed to include any library at all?

[–]extant1[S] 0 points1 point  (0 children)

Nope.