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

Cron4J definition nextExecutionTime does not match cron4j's execution requirements when restricting the day of month and day of week #203

Closed pangyikhei closed 7 years ago

pangyikhei commented 7 years ago

Release found: 6.0.1

The cron4j documentation states:

Once the scheduler is started, a task will be launched when the five parts in its scheduling pattern will be true at the same time.

However this does not seem to be enforced when using the built-in Cron4j definition: Ex. Cron expression: 1 1 1 1 tue Results from calling: ExecutionTime

Mon Jan 01 01:01:00 EST 2018 Tue Jan 02 01:01:00 EST 2018 Tue Jan 09 01:01:00 EST 2018 Tue Jan 16 01:01:00 EST 2018

Cron4J predicts the following:

Tue Jan 01 01:01:00 EST 2019 Tue Jan 01 01:01:00 EST 2030 Tue Jan 01 01:01:00 EST 2036 Tue Jan 01 01:01:00 EST 2041

Test for ExecutionTimeCron4jIntegrationTest:

@Test
public void testDayOfMonthAndDayOfWeek() throws Exception {
    ExecutionTime executionTime = ExecutionTime.forCron(cron4jCronParser.parse("0 0 1 * tue"));
    ZonedDateTime next = ZonedDateTime.now();
    for(int i = 0; i < 10; i++) {
        next = executionTime.nextExecution(next).get();
        assertEquals(DayOfWeek.TUESDAY, next.getDayOfWeek());
        assertEquals(1, next.getDayOfMonth());
    }
}
jmrozanec commented 7 years ago

@pangyikhei Thank you for reporting this. We would greatly appreciate a PR with this test cases. Thanks!

jmrozanec commented 7 years ago

@pangyikhei thank you for contributing a fix!