Merge pull request #918 from archibishop/fix-multidayevent-issue

Fixes multi-day event issue when event ends at start of next day for monthly and weekly.
This commit is contained in:
Tibor Kaputa 2019-06-27 22:57:49 +02:00 committed by GitHub
commit 683821f8a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions

View file

@ -420,7 +420,10 @@ class WeekFragment : Fragment(), WeeklyCalendar {
return
}
val daysCnt = Days.daysBetween(Formatter.getDateTimeFromTS(minTS).toLocalDate(), Formatter.getDateTimeFromTS(maxTS).toLocalDate()).days
//Check if End time for event is start time for another day
val isStartTimeDay = Formatter.getDateTimeFromTS(maxTS) == Formatter.getDateTimeFromTS(maxTS).withTimeAtStartOfDay()
val numDays = Days.daysBetween(Formatter.getDateTimeFromTS(minTS).toLocalDate(), Formatter.getDateTimeFromTS(maxTS).toLocalDate()).days
val daysCnt = if (numDays == 1 && isStartTimeDay) 0 else numDays
val startDateTimeInWeek = Formatter.getDateTimeFromTS(minTS)
val firstDayIndex = (startDateTimeInWeek.dayOfWeek - if (mConfig.isSundayFirst) 0 else 1) % 7

View file

@ -105,7 +105,8 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
// make sure we properly handle events lasting multiple days and repeating ones
val lastEvent = allEvents.lastOrNull { it.id == event.id }
val daysCnt = getEventLastingDaysCount(event)
if (lastEvent == null || lastEvent.startDayIndex + daysCnt <= day.indexOnMonthView) {
val validDayEvent = isDayValid(event, day.code)
if ((lastEvent == null || lastEvent.startDayIndex + daysCnt <= day.indexOnMonthView) && !validDayEvent) {
val monthViewEvent = MonthViewEvent(event.id!!, event.title, event.startTS, event.color, day.indexOnMonthView,
daysCnt, day.indexOnMonthView, event.getIsAllDay(), event.isPastEvent)
allEvents.add(monthViewEvent)
@ -336,6 +337,14 @@ class MonthView(context: Context, attrs: AttributeSet, defStyle: Int) : View(con
if (diff < 0) {
eventStartDateTime = screenStartDateTime
}
return Days.daysBetween(eventStartDateTime, eventEndDateTime).days + 1
val isMidnight = Formatter.getDateTimeFromTS(endDateTime.seconds()) == Formatter.getDateTimeFromTS(endDateTime.seconds()).withTimeAtStartOfDay()
val numDays = Days.daysBetween(eventStartDateTime, eventEndDateTime).days
val daysCnt = if (numDays == 1 && isMidnight) 0 else numDays
return daysCnt + 1
}
private fun isDayValid(event: Event, code: String): Boolean {
val date = Formatter.getDateTimeFromCode(code)
return Formatter.getDateTimeFromTS(event.endTS) == Formatter.getDateTimeFromTS(date.seconds()).withTimeAtStartOfDay()
}
}