tobiasschuerg / android-week-view

Android library for displaying an overview of events for a week like in a schedule(us) or timetable(uk).
MIT License
52 stars 6 forks source link

Sunday events are being displayed at Monday #17

Closed MuriloCalegari closed 5 years ago

MuriloCalegari commented 5 years ago

If there's no event at monday, all the following events are actually displayed one day before its actual day.

Might have something to do with the fact that the library counts days with monday as day 1 but you're using several times Calendar.SUNDAY which takes SUNDAY as day 1.

EDIT:

I now realize that you count events with Sunday as day 1, so I adjusted my code for that. But now I notice that if I add an event as Sunday, it is actually displayed at Monday column, but your code is detecting it as a Sunday event because the Sunday column is being drawn.

MuriloCalegari commented 5 years ago

I think I might be understanding now. Although Calendar.getInstance().firstDayOfWeek is returning 1 (Calendar.SUNDAY), the library isn't properly displaying Sunday as the first day of the week, so, at mapDayToColumn(),

Calendar.SUNDAY -> return if (sundayEnabled) {
        calendarDay - 1 // su: 0, mo: 1 fr: 5, sa: 6
} else {
        calendarDay - 2 // mo: 0 fr: 4, sa: 5, su: -1
 }

is actually considering that the Sunday column is being displayed at index n° 0, but it is actually at index number 6

MuriloCalegari commented 5 years ago

For instance, I'm changing calendarDay - 1 to (calendarDay + 5) % 7 // su: 0, mo: 1 fr: 5, sa: 6 while someone can find a solution (and actually check if this happens for all firstDayOfTheWeek) for the problem of the order of the days in backgroundView.

I wish I could help, but I don't exactly have the time for debugging this, especially because I don't actually know Kotlin much.

tobiasschuerg commented 5 years ago

I removed Calendar as this was legacy stuff an also reworked the mapping part.

https://github.com/tobiasschuerg/android-week-view/blob/master/library/src/main/java/de/tobiasschuerg/weekview/util/DayOfWeekUtil.kt#L34-L83

Please check if the issue if solved with version 1.4