Fix counting time for inactive slots

This commit is contained in:
Jonas Lochmann 2020-06-01 02:00:00 +02:00
parent a0a1c20e10
commit a638b35dd2
No known key found for this signature in database
GPG key ID: 8B8C9AEE10FA5B36
2 changed files with 7 additions and 5 deletions

View file

@ -502,10 +502,12 @@ class BackgroundTaskLogic(val appLogic: AppLogic) {
if (categoriesToCount.isNotEmpty()) { if (categoriesToCount.isNotEmpty()) {
categoriesToCount.forEach { categoryId -> categoriesToCount.forEach { categoryId ->
// only handle rules which are related to today // only handle rules which are related at today and the current time
val rules = timeLimitRules.get(categoryId).waitForNonNullValue().filter { val rules = RemainingTime.getRulesRelatedToDay(
(it.dayMask.toInt() and (1 shl nowDate.dayOfWeek)) != 0 dayOfWeek = nowDate.dayOfWeek,
} minuteOfDay = minuteOfWeek % MinuteOfDay.LENGTH,
rules = timeLimitRules.get(categoryId).waitForNonNullValue()
)
usedTimeUpdateHelper.add( usedTimeUpdateHelper.add(
categoryId = categoryId, categoryId = categoryId,

View file

@ -44,7 +44,7 @@ data class RemainingTime(val includingExtraTime: Long, val default: Long) {
) )
} }
private fun getRulesRelatedToDay(dayOfWeek: Int, minuteOfDay: Int, rules: List<TimeLimitRule>): List<TimeLimitRule> { fun getRulesRelatedToDay(dayOfWeek: Int, minuteOfDay: Int, rules: List<TimeLimitRule>): List<TimeLimitRule> {
return rules.filter { return rules.filter {
((it.dayMask.toInt() and (1 shl dayOfWeek)) != 0) && ((it.dayMask.toInt() and (1 shl dayOfWeek)) != 0) &&
minuteOfDay >= it.startMinuteOfDay && minuteOfDay <= it.endMinuteOfDay minuteOfDay >= it.startMinuteOfDay && minuteOfDay <= it.endMinuteOfDay