2020-11-21 08:58:19 +00:00
|
|
|
package dev.inmo.krontab
|
2019-10-08 17:04:58 +00:00
|
|
|
|
2023-05-25 14:53:10 +00:00
|
|
|
import korlibs.time.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
|
|
|
|
|
|
|
/**
|
2023-06-20 04:25:15 +00:00
|
|
|
* [KronScheduler.next] will always return [korlibs.time.DateTime.now]
|
2020-06-03 14:41:54 +00:00
|
|
|
*/
|
2019-10-10 10:43:52 +00:00
|
|
|
val AnyTimeScheduler: KronScheduler by lazy {
|
2021-05-30 11:15:32 +00:00
|
|
|
CronDateTimeScheduler(anyCronDateTime)
|
2019-10-08 17:04:58 +00:00
|
|
|
}
|
2020-06-03 14:41:54 +00:00
|
|
|
|
2022-04-29 15:57:10 +00:00
|
|
|
/**
|
2023-06-20 04:25:15 +00:00
|
|
|
* [KronScheduler.next] will always return [korlibs.time.DateTime.now] + one millisecond
|
2022-04-29 15:57:10 +00:00
|
|
|
*/
|
|
|
|
val EveryMillisecondScheduler: KronScheduler by lazy {
|
|
|
|
buildSchedule { milliseconds { 0 every 1 } }
|
|
|
|
}
|
|
|
|
|
2020-06-03 14:41:54 +00:00
|
|
|
/**
|
2023-06-20 04:25:15 +00:00
|
|
|
* [KronScheduler.next] will always return [korlibs.time.DateTime.now] + one second
|
2020-06-03 14:41:54 +00:00
|
|
|
*/
|
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
|
|
|
/**
|
2023-06-20 04:25:15 +00:00
|
|
|
* [KronScheduler.next] will always return [korlibs.time.DateTime.now] + one minute
|
2020-06-03 14:41:54 +00:00
|
|
|
*/
|
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
|
|
|
/**
|
2023-06-20 04:25:15 +00:00
|
|
|
* [KronScheduler.next] will always return [korlibs.time.DateTime.now] + one hour
|
2020-06-03 14:41:54 +00:00
|
|
|
*/
|
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
|
|
|
/**
|
2023-06-20 04:25:15 +00:00
|
|
|
* [KronScheduler.next] will always return [korlibs.time.DateTime.now] + one day
|
2020-06-03 14:41:54 +00:00
|
|
|
*/
|
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
|
|
|
/**
|
2023-06-20 04:25:15 +00:00
|
|
|
* [KronScheduler.next] will always return [korlibs.time.DateTime.now] + one month
|
2020-06-03 14:41:54 +00:00
|
|
|
*/
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-06-20 04:25:15 +00:00
|
|
|
* [KronScheduler.next] will always return [korlibs.time.DateTime.now] + one year
|
2021-01-02 15:35:08 +00:00
|
|
|
*/
|
|
|
|
val EveryYearScheduler: KronScheduler by lazy {
|
|
|
|
buildSchedule { years { 0 every 1 } }
|
2021-05-30 11:15:32 +00:00
|
|
|
}
|
2023-06-20 04:25:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Shortcut for [EveryMillisecondScheduler]
|
|
|
|
*/
|
|
|
|
inline val KronScheduler.Companion.everyMillisecond
|
|
|
|
get() = EveryMillisecondScheduler
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shortcut for [EverySecondScheduler]
|
|
|
|
*/
|
|
|
|
inline val KronScheduler.Companion.everySecond
|
|
|
|
get() = EverySecondScheduler
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shortcut for [EveryMinuteScheduler]
|
|
|
|
*/
|
|
|
|
inline val KronScheduler.Companion.everyMinute
|
|
|
|
get() = EveryMinuteScheduler
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shortcut for [EveryHourScheduler]
|
|
|
|
*/
|
|
|
|
inline val KronScheduler.Companion.hourly
|
|
|
|
get() = EveryHourScheduler
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shortcut for [EveryDayOfMonthScheduler]
|
|
|
|
*/
|
|
|
|
inline val KronScheduler.Companion.daily
|
|
|
|
get() = EveryDayOfMonthScheduler
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shortcut for [EveryMonthScheduler]
|
|
|
|
*/
|
|
|
|
inline val KronScheduler.Companion.monthly
|
|
|
|
get() = EveryMonthScheduler
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shortcut for [EveryYearScheduler]
|
|
|
|
*/
|
|
|
|
inline val KronScheduler.Companion.annually
|
|
|
|
get() = EveryYearScheduler
|