diff --git a/README.md b/README.md index 5edc2bb..ee5a487 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,8 @@ runtime of applications. | [ How to use: Config from string ](#config-from-string) | | [ How to use: Config via builder (DSL preview) ](#config-via-builder) | | [ How to use: KronScheduler as a Flow ](#KronScheduler-as-a-Flow) | -| [ Note about week days ](#Note-about-week-days) | +| [ How to use: Offsets ](#Offsets) | +| [ How to use: Note about week days ](#Note-about-week-days) | ## How to use @@ -157,6 +158,21 @@ flow.takeWhile { } ``` +### Offsets + +Offsets in this library works via passing parameter ending with `o` in any place after `month` config. Currently +there is only one format supported for offsets: minutes of offsets. To use time zones you will need to call `next` +method with `DateTimeTz` argument or `nextTimeZoned` method with any `KronScheduler` instance, but in case if this +scheduler is not instance of `KronSchedulerTz` it will works like you passed just `DateTime`. + +Besides, in case you wish to use time zones explicitly, you will need to get `KronSchedulerTz`. It is possible by: + +* Using `createSimpleScheduler`/`buildSchedule`/`KrontabTemplate#toSchedule`/`KrontabTemplate#toKronScheduler` methods +with passing `defaultOffset` parameter +* Using `SchedulerBuilder#build`/`createSimpleScheduler`/`buildSchedule`/`KrontabTemplate#toSchedule`/`KrontabTemplate#toKronScheduler` +methods with casting to `KronSchedulerTz` in case you are pretty sure that it is timezoned `KronScheduler` +* Creating your own implementation of `KronSchedulerTz` + ### Note about week days Unlike original CRON, here week days: diff --git a/src/commonMain/kotlin/dev/inmo/krontab/KronSchedulerTz.kt b/src/commonMain/kotlin/dev/inmo/krontab/KronSchedulerTz.kt index 65d812f..16867bb 100644 --- a/src/commonMain/kotlin/dev/inmo/krontab/KronSchedulerTz.kt +++ b/src/commonMain/kotlin/dev/inmo/krontab/KronSchedulerTz.kt @@ -29,4 +29,6 @@ suspend fun KronScheduler.next(relatively: DateTimeTz) = if (this is KronSchedul this.next(relatively) } else { this.next(relatively.local) ?.toOffsetUnadjusted(relatively.offset) -} \ No newline at end of file +} + +suspend fun KronScheduler.nextTimeZoned() = next(DateTime.now().local) \ No newline at end of file