jmrozanec/cron-utils

ExecitionTime not working when using QUARTZ and time is beyond 2100.

Eyre-S opened this issue · 0 comments

Eyre-S commented

Sorry that I later knows that quartz does not allow year above 2099.


When the input time (or output time) is over 2100, the output will be null (Optional.empty exactly).

scala> var cron = CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ)).parse("0 0 0 * * ?")
var cron: com.cronutils.model.Cron = com.cronutils.model.SingleCron@31183ee2

scala> var exec = ExecutionTime.forCron(cron)
var exec: com.cronutils.model.time.ExecutionTime = com.cronutils.model.time.SingleExecutionTime@249a45fd

scala>  exec.nextExecution(ZonedDateTime.parse("2023-11-09T06:13:00.000Z"))
val res0: java.util.Optional[java.time.ZonedDateTime] = Optional[2023-11-10T00:00Z]

scala> exec.nextExecution(ZonedDateTime.parse("2123-11-09T06:13:00.000Z"))
val res1: java.util.Optional[java.time.ZonedDateTime] = Optional.empty

scala> ZonedDateTime.parse("2123-11-09T06:13:00.000Z")
val res2: java.time.ZonedDateTime = 2123-11-09T06:13Z

scala> exec.nextExecution(ZonedDateTime.parse("2099-11-09T06:13:00.000Z"))
val res5: java.util.Optional[java.time.ZonedDateTime] = Optional[2099-11-10T00:00Z]

scala> exec.nextExecution(ZonedDateTime.parse("2100-11-09T06:13:00.000Z"))
val res6: java.util.Optional[java.time.ZonedDateTime] = Optional.empty

scala> exec.nextExecution(ZonedDateTime.parse("2099-12-31T06:13:00.000Z"))
val res7: java.util.Optional[java.time.ZonedDateTime] = Optional.empty

When using CronType.UNIX, it seems works well

scala> var cron = CronParser(CronDefinitionBuilder.instanceDefinitionFor(CronType.UNIX)).parse("0 0 * * *")
var cron: com.cronutils.model.Cron = com.cronutils.model.SingleCron@4e4af370

scala> var exec = ExecutionTime.forCron(cron)
var exec: com.cronutils.model.time.ExecutionTime = com.cronutils.model.time.SingleExecutionTime@cd93621

scala> exec.nextExecution(ZonedDateTime.parse("2099-11-09T06:13:00.000Z"))
val res8: java.util.Optional[java.time.ZonedDateTime] = Optional[2099-11-10T00:00Z]

scala> exec.nextExecution(ZonedDateTime.parse("2199-11-09T06:13:00.000Z"))
val res9: java.util.Optional[java.time.ZonedDateTime] = Optional[2199-11-10T00:00Z]