Closed flolege closed 4 years ago
How are you creating your start/end date objects? Are they true Dates, with offsets built in?
JS Dates are a tricky mess, especially when considering timezone offsets. Consider the following:
new Date('2019-08-11')
// Sat Aug 10 2019 19:00:00 GMT-0500 (Central Daylight Time)
new Date('2019-08-11 06:00')
// Sat Aug 11 2019 06:00:00 GMT-0500 (Central Daylight Time)
new Date('2019-08-11 06:00 pm')
// Sat Aug 11 2019 18:00:00 GMT-0500 (Central Daylight Time)
new Date('2019-08-11T06:00:00.000Z')
// Sat Aug 11 2019 01:00:00 GMT-0500 (Central Daylight Time)
As you can see, setting Dates with UTC time is the most accurate format, as the offset is built into the data, being relative to the GMT (Zulu time). Any JS Dates are relative to the machine on which they're created, and are displayed relative to the localizer
used in your implementation of RBC. I live in Nashville, so every JS Date I create today is in CDT. You can see this quite clearly with additional testing.
var dt = moment('2019-08-11 06:00 pm', 'YYYY-MM-DD hh:mm a');
dt.format();
// 2019-08-11T18:00:00-05:00
new Date(dt.format())
// Sun Aug 11 2019 18:00:00 GMT-0500 (Central Daylight Time)
dt.tz('America/New_York').format()
// 2019-08-11T19:00:00-04:00
new Date(dt.tz('America/New_York').format())
// Sun Aug 11 2019 18:00:00 GMT-0500 (Central Daylight Time)
Many thanks for your detailled explanation and examples! I checked and you are right, the created date objects are not correct!
Let me explain: Here is the console output of two events, one taking place on the 25th October and one 28th. It shows the date string from the database and the date object which was created based on the string.
The switch from DST to normal time here in Europe where I live is on the 27th October.
Both events should start on 10:00 in the morning, doesn't matter if we have DST here or not.
It seems I stored the incorrect time in the database, right? If I want the event to always start at 10:00 in the morning, then I have to create the event from the 28th October with UTC time 09:00 instead of 08:00. Can you confirm this is correct?
Not sure, off the top of my head. I just went through an exhaustive exercise in dealing with switching timezones. Take a look at this GitHub and the codesandbox linked in the README. Hope it helps.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
For example, an event occurs every day at 10:00 AM.
Bevor the 27th October 2019 it shows correctly at 10:00 AM in the calendar.
After the 27th October 2019 it shows incorrectly at 09:00 AM in the calendar.
I saw there are some fixes but nothing official yet (I guess).
Could someone explain me how to utilize one of those fixes? Can I overwrite the sources in the node_modules/react-big-calendar folder? If yes, where exactly? Won't the next release (if there is any) overwrite those fixes when I do npm i ?