I'm making a business day calculator that takes a date and an offset and returns a date. So if you pass it Monday, Feb 27, 2017 and want to know the date 2 business days prior it returns Thursday, Feb 23, 2017. It also takes into account holidays, so if in the previous example, Feb 23, 2017 was a holiday it would return Feb 22, 2017.
I have a list of holidays in SQL Server in a date field in the format yyyy-mm-dd
. The problem is that when they're converted to javascript Date
objects it appends a timezone offset and in the case of Eastern Standard Time subtracts 5 hours from the date, rolling it back to the previous day.
new Date('2017-02-20');
becomes
Sun Feb 19 2017 19:00:00 GMT-0500 (Eastern Standard Time)
or
Sun Feb 19 2017 20:00:00 GMT-0400 (Eastern Daylight Time)
It seems to flip back and forth between standard time and daylight time randomly.
How do I prevent javascript from messing up my dates regardless of where the user lives? I only care about dates, not times.