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

fix: numGroups calculation #1963

Merged
merged 1 commit into from
Jul 28, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/utils/TimeSlots.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function getSlotMetrics({ min: start, max: end, step, timeslots }) {
1 + dates.diff(start, end, 'minutes') + getDstOffset(start, end)
Copy link
Collaborator

@pietrofxq pietrofxq Jun 23, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to handle the +1 here instead of subtracting it later? Won't removing it cause any problems?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although I'm not completely certain, I think the totalMin value is used for positioning items in the calendar as well while the numGroups is only used for figuring out the amount of slot groups. So the impact of changing the numGroups seems less risky to me.
Plus, my PR is inspired by the changes suggested in #1685 and an internal patch a colleague applied for fixing this behavior. And they both have the - 1 expression in the numGroups value and its effect is working for us quite nicely.

const minutesFromMidnight =
dates.diff(daystart, start, 'minutes') + daystartdstoffset
const numGroups = Math.ceil(totalMin / (step * timeslots))
const numGroups = Math.ceil((totalMin - 1) / (step * timeslots))
const numSlots = numGroups * timeslots

const groups = new Array(numGroups)
Expand Down