Skip to content

Commit

Permalink
Fix bug with infinite while loop in GetAllStreaksWithCashingUseCase
Browse files Browse the repository at this point in the history
The while loop in GetAllStreaksWithCashingUseCase ran infinitely when the habit start date was in the future.
  • Loading branch information
DanielRendox committed Feb 7, 2024
1 parent de094f3 commit 773c1d5
Showing 1 changed file with 2 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class GetAllStreaksWithCashingUseCase(
val firstDateToLookFor = habit.schedule.startDate
var period = getPeriodRange(habit.schedule, firstDateToLookFor)!!

if (period.start > today) return@withContext emptyList<Streak>()

while (!period.contains(today)) {
val cashedStreaksContainsPeriod = cashedPeriods.any { cashedPeriod ->
period.isSubsetOf(cashedPeriod)
Expand Down

0 comments on commit 773c1d5

Please sign in to comment.