cron-utils
cron-utils copied to clipboard
CronBuilder: support java.time.Duration
Construct a cron from java.time.Duration
@cdalexndr may you elaborate a bit more on this?
My use case is that I want to use a single constant value that is used as a Duration for cache expiry and also as a cron job for regular cache repopulation. So I need some method to convert from a constant Duration to cron (the inverse is not be possible for any cron).
CronBuilder
is using manual definition of each cron field.
My suggestion is for it to support parsing a Duration
and auto-complete it's fields.
Example mappings:
Duration.ofSeconds(10)
= 0/10 0 0 ? * *
Duration.ofHours(3)
= 0 0 */3 ? * *
Duration.ofDays(2)
= 0 0 0 */2 * ?
It seems that some values cannot be mapped correctly, so only simple durations should be accepted.
Duration.ofDays(2).plusHours(3)
= ?
As there is not an universal conversion, this feature doesn't sound as good now so it's remains at your discretion.
@cdalexndr thank you for the details. We will have a more detailed look at the use case and decide if we can provide a good solution for it. Best! 😄
Hey I would like to take this up as a part of Hacktober fest.
@mehwhatever sure! Thanks!
@mehwhatever do we have any updates on this? Thanks!
@mehwhatever do we have some update on this? Thanks!