Search code examples
scalacronquartz

NextExecution time with quartz definition fails when date if the end of the month


Currently, I have a cron job scheduling for every minute but once the date is the end of the month, the nextExecution method fails to provide the proper date.

test("check execution times") {
// make sure the execution times are correct
val expression = "0 * * ? * * *" // every minute (the top of the minute)
val currentTime = "2019-12-31T00:00:00.000Z" // get current time
val expectedNextExecution = "2019-12-31T00:01:00.000Z" // get current time
val cron = new CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ)).parse(expression)
val executor = ExecutionTime.forCron(cron)
val actualNextExecution = executor.nextExecution(DateTime.parse(currentTime)).toString // call nextExecution which should give us the next top of the minute
// check if nextExecution has correct next execution time
assert(actualNextExecution == expectedNextExecution, "Wrong execution time")
}

Results :

Expected :"20[19-12-31T00:01]:00.000Z" 
Wrong execution time Actual   :"20[20-01-01T00:00]:00.000Z"

Solution

  • The answer to this was updating my cron-utils version.

    Previously on: 4.1.0

    Issue was fixed on: 9.0.2

    Thank you