jquense / react-big-calendar

gcal/outlook like calendar component
http://jquense.github.io/react-big-calendar/examples/index.html
MIT License
7.9k stars 2.24k forks source link

Event segments one day too short when timezone is set #2659

Open evanbrooks-codaio opened 1 month ago

evanbrooks-codaio commented 1 month ago

Check that this is really a bug

Reproduction link

https://codesandbox.io/p/sandbox/react-big-calendar-example-forked-wc6sts

Bug description

I believe this may be the same issue as #2425 , however it appears to happen consistently in any timezone, and consistently with either the moment or luxon localizers. feel free consolidate if this is a duplicate.

Expected Behavior

image

Actual Behavior

image

react-big-calendar version

1.14.1

React version

18.2.0

Platform/Target and Browser Versions

macOS 14.4, Chrome 129

Validations

Would you like to open a PR for this bug?

evanbrooks-codaio commented 1 month ago

The issue appears to be with the getBrowserTzOffset in the localizers, ie here for luxon. This configures the segmentOffset here and is used to explictly subtract the width of the segment here:

https://github.com/jquense/react-big-calendar/blob/856dddf8938a0e0e543b4ef026e0ca3cdcce1071/src/utils/eventLevels.js#L26-L28

It seems like this is subtracting "1" in situations where the segments are already correct. I've found that simply removing the segmentOffset appears to resolve the issue in my test case. I'm not sure exactly when it is necessary to subtract 1 (if ever?), but it seems to happening more often than it should.