diff --git a/src/Cron/CronExpression.php b/src/Cron/CronExpression.php index f71490e1..fa2acf1a 100644 --- a/src/Cron/CronExpression.php +++ b/src/Cron/CronExpression.php @@ -410,6 +410,14 @@ protected function getRunDate($currentTime = null, int $nth = 0, bool $invert = $domRunDates = $domExpression->getMultipleRunDates($nth + 1, $currentTime, $invert, $allowCurrentDate, $timeZone); $dowRunDates = $dowExpression->getMultipleRunDates($nth + 1, $currentTime, $invert, $allowCurrentDate, $timeZone); + if ($parts[self::DAY] === '?' || $parts[self::DAY] === '*') { + $domRunDates = []; + } + + if ($parts[self::WEEKDAY] === '?' || $parts[self::WEEKDAY] === '*') { + $dowRunDates = []; + } + $combined = array_merge($domRunDates, $dowRunDates); usort($combined, function ($a, $b) { return $a->format('Y-m-d H:i:s') <=> $b->format('Y-m-d H:i:s'); diff --git a/tests/Cron/CronExpressionTest.php b/tests/Cron/CronExpressionTest.php index 84b953be..61be75cf 100644 --- a/tests/Cron/CronExpressionTest.php +++ b/tests/Cron/CronExpressionTest.php @@ -704,4 +704,24 @@ public function testIssue131() $prev = $e->getPreviousRunDate(new \DateTime('2022-08-20 03:44:02')); $this->assertEquals($expected, $prev); } + + public function testIssue128() + { + $e = new CronExpression('0 20 L 6,12 ?'); + $expected = new \DateTime('2022-12-31 20:00:00'); + $next = $e->getNextRunDate(new \DateTime('2022-08-20 03:44:02')); + $this->assertEquals($expected, $next); + + $expected = new \DateTime('2023-12-31 20:00:00'); + $next = $e->getNextRunDate(new \DateTime('2022-08-20 03:44:02'), 2); + $this->assertEquals($expected, $next); + + $expected = new \DateTime('2022-06-30 20:00:00'); + $prev = $e->getPreviousRunDate(new \DateTime('2022-08-20 03:44:02')); + $this->assertEquals($expected, $prev); + + $expected = new \DateTime('2021-12-31 20:00:00'); + $prev = $e->getPreviousRunDate(new \DateTime('2022-08-20 03:44:02'), 1); + $this->assertEquals($expected, $prev); + } }