Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: scrollToTime 00h:00m doesn't work #1474

Closed
amok opened this issue Oct 1, 2019 · 5 comments · Fixed by #1501
Closed

BUG: scrollToTime 00h:00m doesn't work #1474

amok opened this issue Oct 1, 2019 · 5 comments · Fixed by #1501

Comments

@amok
Copy link
Contributor

amok commented Oct 1, 2019

Do you want to request a feature or report a bug?

Report a bug

What's the current behavior?

scrollToTime prop does not work if the value's date has 00h 00m

demo: https://codesandbox.io/embed/react-big-calendar-issue-scrolltotime-dp9zy
video: https://monosnap.com/file/dP5aEOh73L2K7Z7IfU2XJQtNnxdtJS

It mostly likely happens because of this check https://github.com/intljusticemission/react-big-calendar/blob/master/src/TimeGrid.js#L261 - scrollToTime is not being applied because this._scrollRatio is zero (false) (calculated at line https://github.com/intljusticemission/react-big-calendar/blob/master/src/TimeGrid.js#L275)

What's the expected behavior?

view scrolls to top when scrollToTime has been set to 00h:00m

@Dragomir-Ivanov
Copy link
Contributor

Used your codesandbox as a template, and tried your issue. It seems to work fine with:

const stt00 = new Date(new Date().setHours(0, 0));
const stt10 = new Date(new Date().setHours(10, 0));

Not that in your code stt00 was new Date(new Date().setHours(0, 0, 0, 0));

@amok
Copy link
Contributor Author

amok commented Oct 15, 2019

@Dragomir-Ivanov that's true
as I understand it happens because "shouldUpdate" is being calculated basing on milliseconds https://github.com/intljusticemission/react-big-calendar/blob/master/src/TimeGrid.js#L261

this._scrollRatio = diffMillis / totalMillis

when you setHours(hours, minutes) milliseconds value is not zero (with a high enough level of probability :) )
but when you setHours(hours, minutes, seconds, milliseconds) the value of milliseconds is always 0 so the bug exist.

@Dragomir-Ivanov
Copy link
Contributor

@amok I didn't looked at the code, however your advice seems reasonable. In any case, explicit check for 0 will be needed. Perhaps you can make a PR?

@amok
Copy link
Contributor Author

amok commented Oct 18, 2019

@Dragomir-Ivanov done. pls take a look at #1501

@Dragomir-Ivanov
Copy link
Contributor

@amok Good work, mate!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants