jmrozanec / cron-utils

Cron utils for parsing, validations and human readable descriptions as well as date/time interoperability.
http://cron-utils.com
Apache License 2.0
1.15k stars 262 forks source link

asString() output for cron containing weekdays #536

Open jmuis opened 2 years ago

jmuis commented 2 years ago

Hi,

First of all thanks very much for this library. Only recently discovered it but it is extremely useful for us while moving away from a certain scheduler and replacing it with another one.

Our expressions typically contain written weekdays such as MON, TUE, etc. Parsing that up works great, but I can not find a way to get the output as such when building a CRON and getting the expression. (Cron#asString) It always seems to output integer values for the weekdays, which unfortunately, we can't deal with in our legacy solution.

Any idea / hints on how to get named weekdays instead of integers?

Thanks very much!

jmrozanec commented 2 years ago

@jmuis, perhaps we can add a visitor or some post-processing step to achieve this? What would be an acceptable timeline for you so we deliver a solution? Thank you for the positive feedback! We are glad cron-utils is useful to you! 😄 🚀

jmuis commented 2 years ago

@jmrozanec thanks for your quick and positive response. There is no immediate pressure as we can deal with it for the foreseeable future, but would love to drop the legacy stuff altogether rather sooner than later :)

Had a quick look at the visitor pattern already, but I did not get the results as expected for some reason and wasn't entirely sure either that building up the expression myself was the right way forward as we would be building a one off solution once more instead of using 'standard' functionality.

More than happy to help out though where possible, although I'm not entirely familiar yet with your lib. Having that said, I won't be available for the next 4 weeks due to traveling.

What I believe could be a solution is to be able to provide a formatting hint on the CronFields. I've seen that you already have a string to int mapping function and perhaps the other way around would already solve it. That could make it fully backwards compatible and easy to use while still keeping the asString calling conventions.

jmrozanec commented 2 years ago

@jmuis, great! We will look into the code and provide a solution. Have a good travel! 😄 And check for a new cron-utils release on your return! 🚀

jmuis commented 2 years ago

@jmrozanec will do! Thanks very much again!