diff --git a/CHANGELOG.md b/CHANGELOG.md index 49d604a..f446586 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## 0.5.0 +## 0.5.0 Years **BREAKING CHANGES** @@ -8,6 +8,15 @@ * Old methods `merge` and `plus` related to `CronDateTimeScheduler` has been marked as `deprecated` and changed their parameters types - it is `KronScheduler` now * New methods `merge` has been added +* **`KronScheduler#next` method now is nullable. Use `nextOrRelative`/`nextOrNow` to get next time certainly** +* **Years was added as optional part of krontab template and opportunity in `SchedulerBuilder`** + * New builder `YearsBuilder` + * `SchedulerFlow#collectSafely` will be normally (without exceptions) finish when `next` of scheduler will return + null +* `KronScheduler#doOnce` will run code immediately in case when `next` is returning null value +* `KrontabTemplateWrapper` has been added +* New extension `KrontabTemplate#toKronScheduler` (works as `toSchedule`) +* **Fixed issue related to the fact that `toNearDateTime` of `CronDateTime` incorrectly handled months ## 0.4.2 diff --git a/src/commonMain/kotlin/dev/inmo/krontab/KronScheduler.kt b/src/commonMain/kotlin/dev/inmo/krontab/KronScheduler.kt index b511b3f..b7e214a 100644 --- a/src/commonMain/kotlin/dev/inmo/krontab/KronScheduler.kt +++ b/src/commonMain/kotlin/dev/inmo/krontab/KronScheduler.kt @@ -21,4 +21,7 @@ interface KronScheduler { suspend fun next(relatively: DateTime = DateTime.now()): DateTime? } -suspend fun KronScheduler.forceNext(relatively: DateTime = DateTime.now()): DateTime = next(relatively) ?: getAnyNext(relatively) +suspend fun KronScheduler.nextOrRelative(relatively: DateTime = DateTime.now()): DateTime = next(relatively) ?: getAnyNext(relatively) +suspend fun KronScheduler.nextOrNow(): DateTime = DateTime.now().let { + next(it) ?: getAnyNext(it) +} diff --git a/src/commonMain/kotlin/dev/inmo/krontab/KrontabTemplateWrapper.kt b/src/commonMain/kotlin/dev/inmo/krontab/KrontabTemplateWrapper.kt index 480211f..0cd06f6 100644 --- a/src/commonMain/kotlin/dev/inmo/krontab/KrontabTemplateWrapper.kt +++ b/src/commonMain/kotlin/dev/inmo/krontab/KrontabTemplateWrapper.kt @@ -1,5 +1,18 @@ package dev.inmo.krontab +/** + * This class contains [template] and can be simply serialized/deserialized. In fact that class will work as + * [dev.inmo.krontab.internal.CronDateTimeScheduler] due to the fact that [toKronScheduler] will return it under the + * hood + */ data class KrontabTemplateWrapper( val template: KrontabTemplate ) : KronScheduler by template.toKronScheduler() + +/** + * Will create [KrontabTemplateWrapper] from [this] [KrontabTemplate] + * + * @see [toKronScheduler] + * @see [KrontabTemplateWrapper] + */ +fun KrontabTemplate.wrapAsKronScheduler() = KrontabTemplateWrapper(this)