Compensate for Daylight Savings Time (DST)
Here’s a function I wrote at ParkMe to do what the title suggests. We were running into an issue where the Bootstrap Datepicker, using the DatePair library, was showing the wrong date if it fell into DST territory.
Here’s the juice:
// Takes the start or end date, // gets the remainder of the two offsets // and returns a new date with the factored offset. this.compensateForDST = function (date) { var internalDate = new Date(date), newDate = new Date(), newDateOffset = newDate.getTimezoneOffset(), internalDateOffset = internalDate.getTimezoneOffset(), offset = (internalDateOffset - newDateOffset) * 60000, internalDateEpoch = internalDate.getTime(), combinedTime = internalDateEpoch + offset, combinedDate = new Date(combinedTime);
return combinedDate; };
Then for the start and end date, use it like this:
// Only compensate for DST if the offsets don't match. if (startDate.getTimezoneOffset() !== date.getTimezoneOffset()) { return this.compensateForDST(date); } else { return date; }









