question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issue with last day of month after end of Norwegian DST

See original GitHub issue

I 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

react-dates-issue

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
alexanbjcommented, Oct 11, 2016

@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:

export default function getCalendarMonthWeeks(month, enableOutsideDays) {
  // set utc offset to get correct dates in future (when timezone changes)
  const baseDate = month.clone().utcOffset(month.utcOffset());
  ...

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).

0reactions
majapwcommented, Oct 12, 2016

Sweet! Thank you for checking!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issue with last day of month after end of Norwegian DST #111
In Norway, DST ends on the last Sunday in October, meaning this year it will be 30th of October. There's an issue with...
Read more >
Europe Ends DST 2022 - Time and Date
On Sunday, October 30, 2022, clocks will be set back 1 hour in most of Europe as Daylight Saving Time (DST) ends.
Read more >
Time in Norway - Wikipedia
Norway observes Summer Time (sommertid, daylight saving time). The transition dates are the same as for other European countries. Time in Europe: Light...
Read more >
History & info - Daylight Saving Time, early adoption, U.S. law
Daylight Saving Time was observed for seven months in 1918 and 1919. ... created Daylight Saving Time to begin on the last Sunday...
Read more >
Why daylight saving time exists—and is so unpopular
The logic is that by springing forward and falling back, people add an hour of sunlight to the end of the work day....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found