fixes for Tz

This commit is contained in:
InsanusMokrassar 2021-04-10 15:29:55 +06:00
parent 5c81eede9c
commit 3408d58cb7
4 changed files with 10 additions and 8 deletions

View File

@ -1,7 +1,6 @@
package dev.inmo.krontab
import com.soywiz.klock.DateTime
import com.soywiz.klock.DateTimeTz
import dev.inmo.krontab.internal.toNearDateTime
/**
@ -13,6 +12,7 @@ import dev.inmo.krontab.internal.toNearDateTime
* @see dev.inmo.krontab.internal.CronDateTimeScheduler
*/
interface KronScheduler {
/**
* @return Next [DateTime] when some action must be triggered according to settings of this instance
*

View File

@ -1,7 +1,6 @@
package dev.inmo.krontab
import com.soywiz.klock.DateTime
import com.soywiz.klock.DateTimeTz
import dev.inmo.krontab.builder.buildSchedule
import dev.inmo.krontab.internal.*
import dev.inmo.krontab.internal.CronDateTime

View File

@ -14,10 +14,10 @@ internal data class CronDateTimeSchedulerTz internal constructor(
internal val offset: TimezoneOffset
) : KronSchedulerTz {
override suspend fun next(relatively: DateTimeTz): DateTimeTz? {
val dateTimeWithActualOffset = relatively.utc.toOffset(offset).local
val dateTimeWithActualOffset = relatively.toOffset(offset).local
return cronDateTimes.mapNotNull {
it.toNearDateTime(dateTimeWithActualOffset)
}.minOrNull() ?.toOffset(relatively.offset)
}.minOrNull() ?.toOffsetUnadjusted(offset) ?.toOffset(relatively.offset)
}
}

View File

@ -1,9 +1,8 @@
package dev.inmo.krontab.utils
import com.soywiz.klock.DateTimeTz
import com.soywiz.klock.*
import dev.inmo.krontab.KronSchedulerTz
import dev.inmo.krontab.buildSchedule
import dev.inmo.krontab.internal.offsetRange
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.takeWhile
@ -84,9 +83,13 @@ class StringParseTest {
val now = DateTimeTz.nowLocal()
runTest {
for (i in offsetRange) {
val kronScheduler = buildSchedule("* * 10 * * ${i}o") as KronSchedulerTz
for (i in 0 .. 1339) {
val expectedInCurrentOffset = now.toOffset(TimezoneOffset(i.minutes)) + 1.hours
val kronScheduler = buildSchedule(
"${expectedInCurrentOffset.seconds} ${expectedInCurrentOffset.minutes} ${expectedInCurrentOffset.hours} * * ${i}o"
) as KronSchedulerTz
val next = kronScheduler.next(now)
assertEquals(expectedInCurrentOffset.toOffset(now.offset), next)
}
}
}