Skip to content

Commit ab556f0

Browse files
committed
Fixes #18 end time overflow.
1 parent 2700f7e commit ab556f0

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

library/src/main/java/de/tobiasschuerg/weekview/view/WeekBackgroundView.kt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,14 +200,27 @@ internal class WeekBackgroundView constructor(context: Context) : View(context)
200200
}
201201

202202
fun updateTimes(startTime: LocalTime, endTime: LocalTime) {
203-
if (startTime.isAfter(endTime)) throw IllegalArgumentException()
203+
if (startTime.isAfter(endTime)) {
204+
throw IllegalArgumentException("Start time $startTime must be before end time $endTime")
205+
}
206+
var timesHaveChanged = false
204207
if (startTime.isBefore(this.startTime)) {
205208
this.startTime = startTime.truncatedTo(ChronoUnit.HOURS)
209+
timesHaveChanged = true
206210
}
207211
if (endTime.isAfter(this.endTime)) {
208-
this.endTime = endTime.truncatedTo(ChronoUnit.HOURS).plusHours(1)
212+
if (endTime.isBefore(LocalTime.of(23, 0))) {
213+
this.endTime = endTime.truncatedTo(ChronoUnit.HOURS).plusHours(1)
214+
} else {
215+
this.endTime = LocalTime.MAX
216+
}
217+
timesHaveChanged = true
218+
}
219+
if (this.startTime.isAfter(this.endTime)) throw IllegalArgumentException()
220+
221+
if (timesHaveChanged) {
222+
requestLayout()
209223
}
210-
requestLayout()
211224
}
212225

213226
private fun getDurationMinutes(): Long {

0 commit comments

Comments
 (0)