2020-12-02 08:32:26 +00:00
|
|
|
package dev.inmo.SauceNaoAPI.utils
|
2019-10-12 06:30:02 +00:00
|
|
|
|
2020-08-29 13:09:54 +00:00
|
|
|
import com.insanusmokrassar.SauceNaoAPI.additional.LONG_TIME_RECALCULATING_MILLIS
|
|
|
|
import com.insanusmokrassar.SauceNaoAPI.additional.SHORT_TIME_RECALCULATING_MILLIS
|
|
|
|
import com.insanusmokrassar.SauceNaoAPI.models.Header
|
2019-12-12 18:47:52 +00:00
|
|
|
import com.soywiz.klock.DateTime
|
2019-10-12 06:30:02 +00:00
|
|
|
|
|
|
|
internal suspend fun calculateSleepTime(
|
|
|
|
header: Header,
|
|
|
|
mostOldestInShortPeriodGetter: suspend () -> DateTime?,
|
|
|
|
mostOldestInLongPeriodGetter: suspend () -> DateTime?
|
|
|
|
): DateTime? {
|
|
|
|
return when {
|
2019-12-13 16:45:10 +00:00
|
|
|
header.longRemaining < 1 -> mostOldestInLongPeriodGetter() ?.plus(LONG_TIME_RECALCULATING_MILLIS)
|
|
|
|
header.shortRemaining < 1 -> mostOldestInShortPeriodGetter() ?.plus(SHORT_TIME_RECALCULATING_MILLIS)
|
2019-10-12 06:30:02 +00:00
|
|
|
else -> null
|
|
|
|
}
|
|
|
|
}
|