Last active
December 12, 2022 08:22
-
-
Save sorokod/69c082e94c2966e5eb339bac89d424b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.springframework.scheduling.support.CronExpression | |
import java.time.LocalDateTime | |
import java.time.LocalDateTime.now | |
/** | |
* Let Spring generate a sequence of dates according top the provided cron string. | |
* See: https://spring.io/blog/2020/11/10/new-in-spring-5-3-improved-cron-expressions | |
*/ | |
fun genTimes(cronStr: String): Sequence<LocalDateTime> = | |
CronExpression.parse(cronStr).let { exp -> | |
generateSequence(now()) { t -> exp.next(t) } | |
} | |
fun main() { | |
genTimes("0 * * * * *") | |
.take(10) | |
.forEach { println(it) } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment