Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,25 @@ data class Habit(

fun isCompletedToday(): Boolean {
val today = DateUtils.getTodayWithOffset()
val value = computedEntries.get(today).value
return if (isNumerical) {
when (targetType) {
NumericalHabitType.AT_LEAST -> value / 1000.0 >= targetValue
NumericalHabitType.AT_LEAST -> today.getScoreForPeriod() / 1000.0 >= targetValue
NumericalHabitType.AT_MOST -> false
}
} else {
val value = computedEntries.get(today).value
value != Entry.NO && value != Entry.UNKNOWN
}
}

private fun Timestamp.getScoreForPeriod(): Int {
val periodFirstDay = this.minus(frequency.denominator - 1)

return computedEntries.getByInterval(periodFirstDay, this)
.filter { entry -> entry.value != Entry.UNKNOWN }
.sumOf { entry -> entry.value }
}

fun isEnteredToday(): Boolean {
val today = DateUtils.getTodayWithOffset()
val value = computedEntries.get(today).value
Expand Down