Update Habit.kt

pull/2082/head
llx 9 months ago committed by GitHub
parent fc9cc423d0
commit d6dccb179b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -57,13 +57,33 @@ data class Habit(
fun isCompletedToday(): Boolean { fun isCompletedToday(): Boolean {
val today = DateUtils.getTodayWithOffset() val today = DateUtils.getTodayWithOffset()
val startOfWeek = today.truncate(
DateUtils.TruncateField.WEEK_NUMBER,
DateUtils.getFirstWeekdayNumberAccordingToLocale()
)
var totalCompletedValue = 0
val entriesThisWeek = computedEntries.getByInterval(startOfWeek, today)
for(entry in entriesThisWeek){
totalCompletedValue += entry.value
}
val value = computedEntries.get(today).value val value = computedEntries.get(today).value
return if (isNumerical) { return if (isNumerical && frequency != Frequency.DAILY) {
when (targetType) {
NumericalHabitType.AT_LEAST -> totalCompletedValue / 1000.0 >= targetValue
NumericalHabitType.AT_MOST -> totalCompletedValue != Entry.UNKNOWN
&& value / 1000.0 <= targetValue
}
}
else if(isNumerical && frequency == Frequency.DAILY) {
when (targetType) { when (targetType) {
NumericalHabitType.AT_LEAST -> value / 1000.0 >= targetValue NumericalHabitType.AT_LEAST -> value / 1000.0 >= targetValue
NumericalHabitType.AT_MOST -> value != Entry.UNKNOWN && value / 1000.0 <= targetValue NumericalHabitType.AT_MOST -> value != Entry.UNKNOWN
&& value / 1000.0 <= targetValue
}
} }
} else { else {
value != Entry.NO && value != Entry.UNKNOWN value != Entry.NO && value != Entry.UNKNOWN
} }
} }

Loading…
Cancel
Save