mirror of
https://github.com/InsanusMokrassar/krontab.git
synced 2024-11-26 12:08:50 +00:00
fixes for Tz
This commit is contained in:
parent
5c81eede9c
commit
3408d58cb7
@ -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
|
||||
*
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user