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

Cannot map day of week (5#1) #605

Open alexey-anufriev opened 1 year ago

alexey-anufriev commented 1 year ago

It is not possible to perform the following mapping:

CronDefinition cronDefinition = CronDefinitionBuilder.instanceDefinitionFor(CronType.SPRING);
CronParser cronParser = new CronParser(cronDefinition);
Cron cron = cronParser.parse("0 0 0 ? * 5#1");
CronMapper mapper = CronMapper.fromSpringToQuartz();
Cron quartzCron = mapper.map(cron);

Execution leads to the following exception:

java.lang.IllegalArgumentException: value missing for a#b cron expression

    at com.cronutils.utils.Preconditions.checkArgument(Preconditions.java:110)
    at com.cronutils.model.field.expression.On.<init>(On.java:43)
    at com.cronutils.mapper.CronMapper$1.visit(CronMapper.java:294)
    at com.cronutils.model.field.expression.On.accept(On.java:70)
    at com.cronutils.mapper.CronMapper.lambda$dayOfWeekMapping$5(CronMapper.java:288)
    at com.cronutils.mapper.CronMapper.map(CronMapper.java:88)
jmrozanec commented 1 year ago

@alexey-anufriev may we ask you for a PR with the corresponding test? Thanks!

alexey-anufriev commented 1 year ago

Sure, https://github.com/jmrozanec/cron-utils/pull/606