JTAppleCalendar icon indicating copy to clipboard operation
JTAppleCalendar copied to clipboard

Correct numerical errors in roundedFrameSection calculation

Open wtmoose opened this issue 3 years ago • 0 comments

In my project, I have a calendar view that scrolls horizontaly one month at a time:

image

When calling calendar.scrollToDate(), the calendar was scrolling to the wrong month anytime the specified date was a Sunday. Specifically, it was scrolling to the next previous month.

The problem is due to the formula floor(frameSection) in targetPointForItemAt(). Naturally, frameSection may have small numerical errors. For example, a Sunday may yield frameSection == 49.9999999999999. However, floor(49.9999999999999) == 49 when the correct calculation should be 50.

One potential fix, which is the one I'm submitting in this PR, is to reduce the numerical precision of frameSection from double to single before calling floor(). This correctly results in floor(50) == 50.

wtmoose avatar Jun 27 '22 01:06 wtmoose