cron-utils icon indicating copy to clipboard operation
cron-utils copied to clipboard

CronBuilder: support java.time.Duration

Open cdalexndr opened this issue 4 years ago • 9 comments

Construct a cron from java.time.Duration

cdalexndr avatar May 10 '20 16:05 cdalexndr

@cdalexndr may you elaborate a bit more on this?

jmrozanec avatar May 10 '20 19:05 jmrozanec

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 * ?

cdalexndr avatar May 10 '20 20:05 cdalexndr

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 avatar May 10 '20 20:05 cdalexndr

@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! 😄

jmrozanec avatar May 10 '20 21:05 jmrozanec

Hey I would like to take this up as a part of Hacktober fest.

adwsingh avatar Oct 01 '20 21:10 adwsingh

@mehwhatever sure! Thanks!

jmrozanec avatar Oct 02 '20 07:10 jmrozanec

@mehwhatever do we have any updates on this? Thanks!

jmrozanec avatar Oct 11 '20 19:10 jmrozanec

@mehwhatever do we have some update on this? Thanks!

jmrozanec avatar Oct 27 '20 11:10 jmrozanec