CronExpressionGenerator icon indicating copy to clipboard operation
CronExpressionGenerator copied to clipboard

getNextRunDate false on Daily frequency type (every x days)

Open Creeall opened this issue 2 years ago • 0 comments

Hi, I was trying to have a script finding the next run date from this setup :

$xdays = 3; $period = $generator->dailyAt( $dateTime->format("H"), $dateTime->format("i") )->set(new \Butschster\CronExpression\Parts\Days\EveryDay($xdays))->getExpression();

this produice the cron : [46 13 */3 * *]

The goal is to get let's say we are 2023-04-10 13:46 and $xdays = 3 then next run = 2023-04-13 13:46 next is 2023-04-16 10:05:16…

But the result is not al all correct. So maybe the setup is wrong to have the lib recognize the "every x 'number of' days" ? The cron code is right though so I don't really underdand why it's failing.

This is a json result of the same setup looping $xdays from 1 to 9 to check the different 'next run date' : From the today date 2023-04-15 14:06 I was expecting dates to be the 16 (every 1 day), the 17 (every 2 days), the 18 (every 3 days), etc.

{"1":{"cron":"6 14 *\/1 * *","next":"18\/04\/2023 14:06:00"},"2":{"cron":"6 14 *\/2 * *","next":"21\/04\/2023 14:06:00"},"3":{"cron":"6 14 *\/3 * *","next":"22\/04\/2023 14:06:00"},"4":{"cron":"6 14 *\/4 * *","next":"25\/04\/2023 14:06:00"},"5":{"cron":"6 14 *\/5 * *","next":"26\/04\/2023 14:06:00"},"6":{"cron":"6 14 *\/6 * *","next":"01\/05\/2023 14:06:00"},"7":{"cron":"6 14 *\/7 * *","next":"01\/05\/2023 14:06:00"},"8":{"cron":"6 14 *\/8 * *","next":"01\/05\/2023 14:06:00"},"9":{"cron":"6 14 *\/9 * *","next":"01\/05\/2023 14:06:00"}}

Creeall avatar Apr 15 '23 12:04 Creeall