updates and fixes

This commit is contained in:
InsanusMokrassar 2021-04-24 18:33:37 +06:00
parent 7e58ec0873
commit 301afb1ee0
3 changed files with 14 additions and 13 deletions

View File

@ -10,6 +10,7 @@
* New type `KronSchedulerTz`
* `SchedulerFlow` has been deprecated
* New extension `asTzFlow` and small changes in `asFlow` logic
* `merge` extensions now return `CollectionKronScheduler` instead of just `KronScheduler`
## 0.5.1

View File

@ -84,13 +84,10 @@ fun createSimpleScheduler(
offsetParsed = offsetParsed ?: offsetFromString
dayOfWeekParsed = dayOfWeekParsed ?: dayOfWeekFromString
when {
dayOfWeekFromString != null -> return@forEach
offsetFromString == null && yearParsed == null -> {
dayOfWeekFromString != null || offsetFromString != null -> return@forEach
yearParsed == null -> {
yearParsed = parseYears(it)
}
offsetFromString != null && offsetParsed == null -> {
offsetParsed = offsetFromString
}
}
}
}
@ -150,4 +147,4 @@ fun KrontabTemplate.toKronScheduler(): KronScheduler = buildSchedule(this)
/**
* Shortcut for [buildSchedule]
*/
fun KrontabTemplate.toKronScheduler(defaultOffset: Minutes): KronSchedulerTz = buildSchedule(this, defaultOffset)
fun KrontabTemplate.toKronScheduler(defaultOffset: Minutes): KronSchedulerTz = buildSchedule(this, defaultOffset)

View File

@ -10,14 +10,17 @@ class TimeZoneTest {
@Test
fun testDifferentTimeZonesReturnsDifferentTimes() {
val scheduler = buildSchedule { seconds { every(1) } }
val now = DateTime.now()
val baseDate = DateTime.now().startOfWeek
runTest {
for (i in 0 .. 24) {
val nowTz = now.toOffset(i.hours)
val next = scheduler.next(nowTz)!!
assertEquals(
(nowTz + 1.seconds).utc.unixMillisLong, next.utc.unixMillisLong
)
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(
(nowTz + 1.seconds).utc.unixMillisLong, next.utc.unixMillisLong
)
}
}
}
}