Skip to content

Incorrect Day Of Week processing for Quartz when Month or Year isn't '*'. #66

@Joao-Neves

Description

@Joao-Neves

It seems day of week is being incorrectly computed occasionally for Quartz cron expressions.
This works fine:

final CronType cronType = CronType.QUARTZ;
final CronParser quartzParser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(cronType));
ExecutionTime executionTime = ExecutionTime.forCron(quartzParser.parse("0 * * ? * 1 *"));
DateTime nextTime = executionTime.nextExecution(DateTime.now());
assertNotNull(nextTime);
assertEquals(DateTimeConstants.SUNDAY, nextTime.getDayOfWeek());

But with value for Month:

final CronType cronType = CronType.QUARTZ;
final CronParser quartzParser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(cronType));
ExecutionTime executionTime = ExecutionTime.forCron(quartzParser.parse("0 * * ? 5 1 *"));
DateTime nextTime = executionTime.nextExecution(DateTime.now());
assertNotNull(nextTime);
assertEquals(DateTimeConstants.SUNDAY, nextTime.getDayOfWeek());

Yields:

java.lang.AssertionError: 
Expected :7
Actual   :2

And with a value for Year:

final CronType cronType = CronType.QUARTZ;
final CronParser quartzParser = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(cronType));
ExecutionTime executionTime = ExecutionTime.forCron(quartzParser.parse("0 * * ? * 1 2099"));
DateTime nextTime = executionTime.nextExecution(DateTime.now());
assertNotNull(nextTime);
assertEquals(DateTimeConstants.SUNDAY, nextTime.getDayOfWeek());

Yields:

java.lang.AssertionError: 
Expected :7
Actual   :6

For the last assertion.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions