7

Most interesting bug (recently at least)... In JavaScript, you can create a date with new Date(dateString).

...if it starts with the year or is ISO format, it will take the user's local timezone into account. if you did something like new Date('6-Jun-16') it doesn't care about time zones... so depending on how we passed a date via the api, we'd get a different actual date.

Comments
  • 2
    Well that's why I never use the Date constructor with a string. Use RegExp to parse your date string and extract the parts in groups, then call Date.Utc to get the date value, and finally pass that value to the Date cconstructor blah blah blah...or you can just use moment.js.
  • 0
    @benhongh We went down that rabbit hole... Also considered accounting for the timezone offset, wasn't worth it because of how inconsistent the date format is coming in. (legacy application, shit code)
  • 0
    @lreading one you bring in internationalisation and daylight saving things can get real sticky. Been there myself got burnt a few times. I even wrote a DateTimeOffset object to mirror the one in .Net with parsing and formatting with format strings...wonder if there's a JodaTime equivalent in JS.
  • 0
    Best thing to do is store dates in UTC then display them in the users timezone.
Add Comment