Use range-limiting methods in more places.

This commit is contained in:
Isira Seneviratne 2022-08-08 07:10:16 +05:30
parent 647f099b30
commit 2e350c9675
4 changed files with 11 additions and 13 deletions

View file

@ -100,13 +100,11 @@ object ReleaseVersionUtil {
* @return Epoch second of expiry date time
*/
fun coerceUpdateCheckExpiry(expiryString: String?): Long {
val now = ZonedDateTime.now()
return expiryString?.let {
var expiry =
ZonedDateTime.from(DateTimeFormatter.RFC_1123_DATE_TIME.parse(expiryString))
expiry = maxOf(expiry, now.plusHours(6))
expiry = minOf(expiry, now.plusHours(72))
expiry.toEpochSecond()
} ?: now.plusHours(6).toEpochSecond()
val nowPlus6Hours = ZonedDateTime.now().plusHours(6)
val expiry = expiryString?.let {
ZonedDateTime.from(DateTimeFormatter.RFC_1123_DATE_TIME.parse(it))
.coerceIn(nowPlus6Hours, nowPlus6Hours.plusHours(66))
} ?: nowPlus6Hours
return expiry.toEpochSecond()
}
}