mirror of
https://github.com/InsanusMokrassar/krontab.git
synced 2024-11-22 16:23:55 +00:00
parent
58f30aef15
commit
8ac6cd3e62
@ -101,7 +101,7 @@ internal fun NearDateTimeCalculatorDays(
|
|||||||
times: Array<Byte>
|
times: Array<Byte>
|
||||||
) = CommonNearDateTimeCalculator(
|
) = CommonNearDateTimeCalculator(
|
||||||
times,
|
times,
|
||||||
{ it.dayOfMonth.toByte() },
|
{ (it.dayOfMonth - 1).toByte() },
|
||||||
{ dateTime, newOne ->
|
{ dateTime, newOne ->
|
||||||
val dateTime = (if (newOne < dateTime.dayOfMonth) {
|
val dateTime = (if (newOne < dateTime.dayOfMonth) {
|
||||||
dateTime.plus(1.months)
|
dateTime.plus(1.months)
|
||||||
@ -109,7 +109,7 @@ internal fun NearDateTimeCalculatorDays(
|
|||||||
dateTime
|
dateTime
|
||||||
})
|
})
|
||||||
dateTime.copy(
|
dateTime.copy(
|
||||||
dayOfMonth = min(dateTime.month.days(dateTime.year) - 1, newOne.toInt()), // index1
|
dayOfMonth = min(dateTime.month.days(dateTime.year), newOne.toInt() + 1), // index1
|
||||||
hour = 0,
|
hour = 0,
|
||||||
minute = 0,
|
minute = 0,
|
||||||
second = 0,
|
second = 0,
|
||||||
@ -122,7 +122,7 @@ internal fun NearDateTimeCalculatorMonths(
|
|||||||
times: Array<Byte>
|
times: Array<Byte>
|
||||||
) = CommonNearDateTimeCalculator(
|
) = CommonNearDateTimeCalculator(
|
||||||
times,
|
times,
|
||||||
{ it.dayOfMonth.toByte() },
|
{ it.month0.toByte() },
|
||||||
{ dateTime, newOne ->
|
{ dateTime, newOne ->
|
||||||
(if (newOne < dateTime.month0) {
|
(if (newOne < dateTime.month0) {
|
||||||
dateTime.plus(1.years)
|
dateTime.plus(1.years)
|
||||||
|
@ -1,14 +1,22 @@
|
|||||||
package dev.inmo.krontab.utils
|
package dev.inmo.krontab.utils
|
||||||
|
|
||||||
|
import com.soywiz.klock.DateTime
|
||||||
|
import com.soywiz.klock.days
|
||||||
import dev.inmo.krontab.buildSchedule
|
import dev.inmo.krontab.buildSchedule
|
||||||
import kotlin.test.Test
|
import kotlin.test.*
|
||||||
import kotlin.test.assertNotNull
|
|
||||||
|
|
||||||
class InfinityLoopCheckTest {
|
class InfinityLoopCheckTest {
|
||||||
@Test
|
@Test
|
||||||
fun absenceOfInfinityLoopCheckTest() {
|
fun absenceOfInfinityLoopCheckTest() {
|
||||||
|
val now = DateTime.now().startOfYear.startOfDay
|
||||||
|
for (i in 0 until now.year.days) {
|
||||||
|
val scheduleDateTime = (now + i.days)
|
||||||
runTest {
|
runTest {
|
||||||
assertNotNull(buildSchedule("0 0 0 1 *").next())
|
assertEquals(
|
||||||
|
scheduleDateTime,
|
||||||
|
buildSchedule("0 0 0 ${scheduleDateTime.dayOfMonth - 1} ${scheduleDateTime.month0}").next(now)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user