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

CronParser not support "0 0 8-1/1 * * ?" #532

Closed chenkaifeng123 closed 2 years ago

chenkaifeng123 commented 2 years ago

The issue is when I configure cron expression like "0 0 8-1/1 ?" which means from moning 8:00 am to 1 am

CronParser parser = new CronParser(cronDefinition); Cron cron = parser.parse(cronStr); will throw exception

at com.cronutils.parser.CronParser.parse(CronParser.java:131)

Caused by: java.lang.IllegalArgumentException: Invalid range! [8,1] at com.cronutils.model.field.expression.visitor.ValidationFieldExpressionVisitor.visit(ValidationFieldExpressionVisitor.java:75) at com.cronutils.model.field.expression.visitor.ValidationFieldExpressionVisitor.visit(ValidationFieldExpressionVisitor.java:25) at com.cronutils.model.field.expression.Between.accept(Between.java:36) at com.cronutils.model.field.expression.visitor.ValidationFieldExpressionVisitor.visit(ValidationFieldExpressionVisitor.java:86) at com.cronutils.model.field.expression.visitor.ValidationFieldExpressionVisitor.visit(ValidationFieldExpressionVisitor.java:25) at com.cronutils.model.field.expression.Every.accept(Every.java:50) at com.cronutils.model.SingleCron.validate(SingleCron.java:79) at com.cronutils.parser.CronParser.parse(CronParser.java:129) ... 29 more

jmrozanec commented 2 years ago

@chenkaifeng123, thank you for reporting this. May we ask you for a test case to reproduce the issue? This is not necessarily a bug; it may signal that your cron expression does not conform to the cron definition. If no test case is provided, we may close this issue due to a lack of reproducibility. Thank you! 😄

chenkaifeng123 commented 2 years ago

@chenkaifeng123, thank you for reporting this. May we ask you for a test case to reproduce the issue? This is not necessarily a bug; it may signal that your cron expression does not conform to the cron definition. If no test case is provided, we may close this issue due to a lack of reproducibility. Thank you! 😄

sorry , I found this is because different CronType issue.

chenkaifeng123 commented 2 years ago

For this definition CronType.QUARTZ, it works and for CronType.SPRING it not work CronDefinition cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ);

jmrozanec commented 2 years ago

@chenkaifeng123, please provide a PR with the corresponding test case. Thanks! 😄

chenkaifeng123 commented 2 years ago

se provide a PR with the corresponding test case. Than

Ok, I will try to give this test case a little later.

jmrozanec commented 2 years ago

Closing until a PR is provided.