prolificinteractive / material-calendarview

A Material design back port of Android's CalendarView
https://prolificinteractive.github.io/material-calendarview/
MIT License
5.91k stars 1.32k forks source link

isInRange() not working properly #1124

Closed waluaier closed 2 years ago

waluaier commented 2 years ago

I have a list containing start and end dates and I wish to highlight the dates between and including the start and end dates. The first range of dates are highlighted/marked properly, meaning if my start date is set to be March 3 and end date as March 7, then the dates from March 3 to 7 are highlighted . However, when I move on to the remaining list of start and end dates, the dates shift down by a day. For instance, if my start date was April 2 and my end date was April 5, then the dates from April 1 to April 4 are highlighted instead of April 2 to April 5. I have implemented the following code:

override fun shouldDecorate(day: CalendarDay): Boolean {
                for (item in datesList) {
                    val start = item.startDate
                    val end = item. endDate

                    if (day.isInRange(start, end)) {
                        return true
                    }
                }

                return false
            }

I am not sure why it works well for the first date range but not after. Please help!