2021-03-29 16:14:49 +00:00
|
|
|
package dev.inmo.krontab.utils
|
|
|
|
|
|
|
|
import com.soywiz.klock.*
|
|
|
|
import dev.inmo.krontab.builder.buildSchedule
|
2021-04-09 18:28:08 +00:00
|
|
|
import dev.inmo.krontab.next
|
2023-03-18 06:23:53 +00:00
|
|
|
import kotlinx.coroutines.test.runTest
|
2021-03-29 16:14:49 +00:00
|
|
|
import kotlin.test.Test
|
|
|
|
import kotlin.test.assertEquals
|
|
|
|
|
|
|
|
class TimeZoneTest {
|
|
|
|
@Test
|
|
|
|
fun testDifferentTimeZonesReturnsDifferentTimes() {
|
|
|
|
val scheduler = buildSchedule { seconds { every(1) } }
|
2021-05-30 11:15:32 +00:00
|
|
|
val additionalMilliseconds = 100.milliseconds
|
|
|
|
val baseDate = DateTime.now().startOfWeek.copy(milliseconds = additionalMilliseconds.millisecondsInt)
|
2021-03-29 16:14:49 +00:00
|
|
|
runTest {
|
2021-04-24 12:33:37 +00:00
|
|
|
for (i in 0 until 7) {
|
|
|
|
val now = baseDate + i.days
|
|
|
|
for (j in 0 .. 24) {
|
|
|
|
val nowTz = now.toOffset(j.hours)
|
|
|
|
val next = scheduler.next(nowTz)!!
|
|
|
|
assertEquals(
|
2021-05-30 11:15:32 +00:00
|
|
|
(nowTz + 1.seconds - additionalMilliseconds).utc.unixMillisLong, next.utc.unixMillisLong
|
2021-04-24 12:33:37 +00:00
|
|
|
)
|
|
|
|
}
|
2021-03-29 16:14:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-05-30 11:15:32 +00:00
|
|
|
}
|