Fix bug when changing schedule end time and end is before start.

This commit is contained in:
Cody Henthorne
2021-12-10 10:40:11 -05:00
parent 50d2faf381
commit 08a305cb0f
4 changed files with 31 additions and 34 deletions

View File

@@ -59,8 +59,15 @@ data class NotificationProfileSchedule(
return LocalTime.of(end / 100, end % 100)
}
fun endDateTime(now: LocalDateTime): LocalDateTime {
return end.toLocalDateTime(now).plusDays(if (end < start) 1 else 0)
fun endDateTime(localNow: LocalDateTime): LocalDateTime {
val localStart: LocalDateTime = start.toLocalDateTime(localNow)
val localEnd: LocalDateTime = end.toLocalDateTime(localNow)
return if (end < start && (daysEnabled.contains(localStart.dayOfWeek) && localNow.isBetween(localStart, localEnd.plusDays(1)))) {
localEnd.plusDays(1)
} else {
localEnd
}
}
}