2020-11-21 08:58:19 +00:00
|
|
|
package dev.inmo.krontab
|
2019-10-08 17:04:58 +00:00
|
|
|
|
2021-01-02 15:35:08 +00:00
|
|
|
import com.soywiz.klock.DateTime
|
2020-11-21 08:58:19 +00:00
|
|
|
import dev.inmo.krontab.builder.buildSchedule
|
2021-01-02 15:35:08 +00:00
|
|
|
import dev.inmo.krontab.internal.*
|
2019-10-08 17:04:58 +00:00
|
|
|
|
|
|
|
internal val anyCronDateTime by lazy {
|
|
|
|
CronDateTime()
|
|
|
|
}
|
2021-01-02 15:35:08 +00:00
|
|
|
internal fun getAnyNext(relatively: DateTime) = anyCronDateTime.toNearDateTime(relatively)!!
|
2020-06-03 14:41:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* [KronScheduler.next] will always return [com.soywiz.klock.DateTime.now]
|
|
|
|
*/
|
2019-10-10 10:43:52 +00:00
|
|
|
val AnyTimeScheduler: KronScheduler by lazy {
|
2019-10-08 17:04:58 +00:00
|
|
|
CronDateTimeScheduler(listOf(anyCronDateTime))
|
|
|
|
}
|
2020-06-03 14:41:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* [KronScheduler.next] will always return [com.soywiz.klock.DateTime.now] + one second
|
|
|
|
*/
|
2020-06-03 15:39:52 +00:00
|
|
|
val EverySecondScheduler: KronScheduler by lazy {
|
|
|
|
buildSchedule { seconds { 0 every 1 } }
|
|
|
|
}
|
2019-10-08 17:04:58 +00:00
|
|
|
|
2020-06-03 14:41:54 +00:00
|
|
|
/**
|
|
|
|
* [KronScheduler.next] will always return [com.soywiz.klock.DateTime.now] + one minute
|
|
|
|
*/
|
2019-10-10 10:43:52 +00:00
|
|
|
val EveryMinuteScheduler: KronScheduler by lazy {
|
2019-10-08 17:04:58 +00:00
|
|
|
buildSchedule { minutes { 0 every 1 } }
|
|
|
|
}
|
|
|
|
|
2020-06-03 14:41:54 +00:00
|
|
|
/**
|
|
|
|
* [KronScheduler.next] will always return [com.soywiz.klock.DateTime.now] + one hour
|
|
|
|
*/
|
2019-10-10 10:43:52 +00:00
|
|
|
val EveryHourScheduler: KronScheduler by lazy {
|
2019-10-08 17:04:58 +00:00
|
|
|
buildSchedule { hours { 0 every 1 } }
|
|
|
|
}
|
|
|
|
|
2020-06-03 14:41:54 +00:00
|
|
|
/**
|
|
|
|
* [KronScheduler.next] will always return [com.soywiz.klock.DateTime.now] + one day
|
|
|
|
*/
|
2019-10-10 10:43:52 +00:00
|
|
|
val EveryDayOfMonthScheduler: KronScheduler by lazy {
|
2019-10-08 17:04:58 +00:00
|
|
|
buildSchedule { dayOfMonth { 0 every 1 } }
|
|
|
|
}
|
|
|
|
|
2020-06-03 14:41:54 +00:00
|
|
|
/**
|
|
|
|
* [KronScheduler.next] will always return [com.soywiz.klock.DateTime.now] + one month
|
|
|
|
*/
|
2019-10-10 10:43:52 +00:00
|
|
|
val EveryMonthScheduler: KronScheduler by lazy {
|
2019-10-08 17:04:58 +00:00
|
|
|
buildSchedule { months { 0 every 1 } }
|
2021-01-02 15:35:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* [KronScheduler.next] will always return [com.soywiz.klock.DateTime.now] + one year
|
|
|
|
*/
|
|
|
|
val EveryYearScheduler: KronScheduler by lazy {
|
|
|
|
buildSchedule { years { 0 every 1 } }
|
2019-10-08 17:04:58 +00:00
|
|
|
}
|