jquery-date-range-picker
jquery-date-range-picker copied to clipboard
Wrong time calculation when start or end of range is in DST change day
Algorithm used in changeTime() and setRange() works incorrectly when start or end date falls on DST change day.
Currently both functions set date/time to beginning of the day then add to it selected hours and minutes, this way:
opt[name] = parseInt(
moment(parseInt(date))
.startOf('day')
.add(moment(opt[name + 'Time']).format('HH'), 'h')
.add(moment(opt[name + 'Time']).format('mm'), 'm')
.valueOf()
);
For example, for year 2020 when selected time range is 00:00 – 23:59:
- on spring DST change day (29.03) 1 hour is added to the calculation and picker selects additionally whole 30.03
- on autumn DST (25.10) 1 hour is subtracted and selection changes to 00:00 – 22:59
Problem can be solved by setting hours and minutes directly instead of adding them to the beginning of the day.
opt[name] = parseInt(
moment(parseInt(date))
.startOf('day')
.hour(moment(opt[name + 'Time']).format('H'))
.minute(moment(opt[name + 'Time']).format('m'))
.valueOf()
);