pull/2107/merge
Jakub Kalinowski 2 weeks ago committed by GitHub
commit 1aac4e02a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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

Loading…
Cancel
Save