longbill / jquery-date-range-picker

A jQuery plugin that allows user to select a date range
MIT License
1.12k stars 579 forks source link

Number of days is wrong when it spans daylight savings time #481

Open kmccurley opened 4 years ago

kmccurley commented 4 years ago

We discovered today that when trying to select a 5 day period spanning Nov. 3rd, it shows an error of "Date range should not be more than 5 days". The data at the time of calculation on line 1755 is: opt.end = 1572809294319 opt.start = 1572460094319

The calculation on line 1755 then gives: (opt.end - opt.start) /86400000 = 4.041666666666667

This is then rounded up, 1 is added to it, resulting in 6 days rather than 5. The problem is due to the fact that Nov 4 is the day after daylight savings time change, so we get 0.041666666666667 extra days (or one hour).

This error can be recreated on the demo page with the config that allows a selection between 3 and 7 days and the range spans a day when we advance clocks by one hour. image