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 262 forks source link

Validation error while generate cron string using cronBuilder #607

Open yhinge opened 1 year ago

yhinge commented 1 year ago

Hi Team,

I am trying to use the cronBuilder like this.

        public static String getCronExpression(DailyRecurrence dailyRecurrence) throws Exception {
        CronBuilder cronBuilder = CronBuilder.cron(CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ));
        TimeDTO time = TimeDTO.getTimeDTO(dailyRecurrence.getTime());
        cronBuilder.withYear(always());
        cronBuilder.withDoM(always());
        cronBuilder.withDoW(always());
        cronBuilder.withHour(on(time.getHour()));
        cronBuilder.withMinute(on(time.getMinute()));
        Cron cron = cronBuilder.instance();
        log.debug("Cron Expression  generated for dailyRecurrence:{} expression:{}",dailyRecurrence,cron.asString());
        return cron.asString();
    }

Now Am I supposed to specify only the hour and minute and nothing else because no matter what I specify I am getting the validation error message. An I using it incorrectly or my expectation is incorrect from CronBuilder Invalid cron expression: 1 13 * * *. Both, a day-of-week AND a day-of-month parameter, are not supported. If its something that I should be fixing from your documentation sorry to raise an issue. But I was not able to find any documentation.

jmrozanec commented 1 year ago

@yhinge, may we ask you for a PR replicating the issue? We will be grateful for it.