I have this function that returns a new Date
instance with a number of days added or subtracted from a passed Date
object.
function daysFrom(date, numDays) {
var retDate = new Date();
retDate.setDate(date.getDate() + numDays);
return retDate;
}
But right now (in Pacific time zone), if I pass a date from September 19, 2018, my two dates are inconsistent in Standard vs Daylight Saving Time.
var endDate = new Date(Date.parse('19 September 2018 00:12:00 GMT'));
var startDate = daysFrom(endDate, -5);
console.log(startDate, endDate);
// Tue Sep 18 2018 17:12:00 GMT-0700 (Pacific Daylight Time) Tue Nov 13 2018 20:05:02 GMT-0800 (Pacific Standard Time)
I guess they would be different because my returned date was instantiated today, since we're not in DST, but what's the simplest way to ensure the returned date is the correct mode for the time of year? In 2019, DST will start on March 10, so if I subtract x
number of days from that, I would expect the time mode (whatever it's called) to be Standard, not DST.
And what's the mode called (DST vs Standard)?
Using current release of Chrome browser.