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.14k stars 261 forks source link

Schedule to run every 24day? #441

Closed TaridaGeorge closed 4 years ago

TaridaGeorge commented 4 years ago

Is it possible to schedule every 24 day? How can I do that with CronBuilder?

I've tried something like this:

12 15 */24 -> Run every from 24 day to 24 at 12:15 But it doesn't work. I get this exception

Invalid cron expression: 12 15 */24. Both, a day-of-week AND a day-of-month parameter, are not supported.

jmrozanec commented 4 years ago

@TaridaGeorge is possible! 😄 Below we provide a snippet of code, where you can cron for an event to happen every 24 days or on 24th each month:

        CronParser parser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ));
        CronDescriptor descriptor = CronDescriptor.instance(Locale.UK);
        System.out.println(descriptor.describe(parser.parse("0 0 0 24 * ? *"))); // On 24th day
        System.out.println(descriptor.describe(parser.parse("0 0 0 */24 * ? *"))); // Every 24 days

Hope this helps! If any further questions arise, will be glad to answer! 😄