Issue with last day of month after end of Norwegian DST
See original GitHub issueI detected an issue today with the SingleDatePicker and the upcoming end of the Norwegian DST. In Norway, DST ends on the last Sunday in October, meaning this year it will be 30th of October.
There’s an issue with react-dates and the last day of October, the 31st, ie after the DST has changed.
Here’s an example using moment and setting the date directly to the 31st:
import moment from 'moment';
moment.locale('nb');
const d = moment('2016-10-31');
console.log(d.toJSON());
// Correct timezone offset: 2016-10-30T23:00:00.000Z
However, when selecting October 31st in the SimpleDatePicker I get this:
// 2016-10-30T22:00:00.000Z
This is the wrong offset for the 31st (compare to moment code above). If I select any date in November I get the correct offset of T23 (as expected). Up to and including the 30th the offset is also correct (T22).
I’ve forked this repo and reduced the Storybook stories down to a single story that demonstrates this problem: https://github.com/alexanbj/react-dates/tree/dst_error
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (1 by maintainers)
Top GitHub Comments
@ljharb after digging a bit further it seems to be related somehow.
I’ve done some further investigation and I think I found the problem. Have a look at the first few lines of getCalendarMonthsWeeks.js:
It explicitly sets the UTC offset of the baseDate equal to the offset of the
month
param. The baseDate is then used as a basis for building arrays of the days in the months.The issue here is that the UTC offset can change mid-month, as is the case here in my original issue. This is even more evident in March 2017, where there are 5 more days left in the month after the switch to DST. All of these get the wrong offset.
The code comment says that setting the UTC offset is for getting the correct future days. I could be missing something, but if I simply skipped setting the offset, everything worked correctly for me, including the days left in months after a DST switch. All the tests are running green as well.
As a bonus, this also seems to fix the problem in #110 (before removing the UTC offset, in the SingleDatePicker, if I selected March 31st 2017, April 1st was highlighted as well).
Sweet! Thank you for checking!