Use mathematical modulo implementation for calculations (#616)

See documentation (%/rem, mod) for differences.

Example for "issue" that occurred:
mathematical: -4 % 6 = 2 (expected)
kotlin: -4 % 6 = -4 (unexpected)
This commit is contained in:
schroda
2023-07-27 01:28:13 +02:00
committed by GitHub
parent 7ebefa7c42
commit 6ac8f4c45d
2 changed files with 2 additions and 2 deletions

View File

@@ -75,7 +75,7 @@ class Updater : IUpdater {
val updateInterval = serverConfig.globalUpdateInterval.hours.coerceAtLeast(6.hours).inWholeMilliseconds
val lastAutomatedUpdate = preferences.getLong(lastAutomatedUpdateKey, 0)
val timeToNextExecution = updateInterval - (System.currentTimeMillis() - lastAutomatedUpdate) % updateInterval
val timeToNextExecution = (updateInterval - (System.currentTimeMillis() - lastAutomatedUpdate)).mod(updateInterval)
val wasPreviousUpdateTriggered = System.currentTimeMillis() - (if (lastAutomatedUpdate > 0) lastAutomatedUpdate else System.currentTimeMillis()) < updateInterval
if (!wasPreviousUpdateTriggered) {