@@ -48,21 +48,19 @@ class GetAllStreaksWithCashingUseCase(
4848 val computedPeriods = mutableListOf<LocalDateRange >()
4949
5050 val firstDateToLookFor = habit.schedule.startDate
51- var period = getPeriodRange(habit.schedule, firstDateToLookFor)
51+ var period = getPeriodRange(habit.schedule, firstDateToLookFor)!!
5252
53- val habitEndDate = habit.schedule.endDate
54-
55- while (! (habitEndDate != null && period.start > habitEndDate) && ! (period.contains(today))) {
53+ while (! period.contains(today)) {
5654 val cashedStreaksContainsPeriod = cashedPeriods.any { cashedPeriod ->
5755 period.isSubsetOf(cashedPeriod)
5856 }
5957 if (cashedStreaksContainsPeriod) {
60- period = getPeriodRange(habit.schedule, period.endInclusive.plusDays(1 ))
58+ period = getPeriodRange(habit.schedule, period.endInclusive.plusDays(1 )) ? : break
6159 continue
6260 }
6361 computedStreaks.addAll(getStreaksInPeriod(habit, period, today))
6462 computedPeriods.add(period)
65- period = getPeriodRange(habit.schedule, period.endInclusive.plusDays(1 ))
63+ period = getPeriodRange(habit.schedule, period.endInclusive.plusDays(1 )) ? : break
6664 }
6765 val distinctComputedStreaks = computedStreaks.distinct()
6866 val actuallyNeedToInsertComputedStreaks = computedPeriods.isNotEmpty()
@@ -110,8 +108,8 @@ class GetAllStreaksWithCashingUseCase(
110108 private fun getPeriodRange (
111109 schedule : Schedule ,
112110 currentDate : LocalDate ,
113- ): LocalDateRange = when (schedule) {
114- is Schedule .PeriodicSchedule -> schedule.getPeriodRange(currentDate)!!
111+ ): LocalDateRange ? = when (schedule) {
112+ is Schedule .PeriodicSchedule -> schedule.getPeriodRange(currentDate)
115113 is Schedule .EveryDaySchedule -> currentDate.withDayOfMonth(1 ).. currentDate.atEndOfMonth
116114 is Schedule .CustomDateSchedule -> throw IllegalArgumentException ()
117115 }
0 commit comments