Skip to content

Commit

Permalink
Merge pull request mtdowling#28 from EimantasMorkunas/master
Browse files Browse the repository at this point in the history
Fixed infinite loop when resolving last weekday of the month from literals
  • Loading branch information
dragonmantank authored Dec 19, 2018
2 parents 34318b4 + 8572241 commit 02b8123
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Cron/DayOfWeekField.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ public function isSatisfiedBy(DateTime $date, $value)

// Find out if this is the last specific weekday of the month
if (strpos($value, 'L')) {
$weekday = str_replace('7', '0', substr($value, 0, strpos($value, 'L')));
$weekday = $this->convertLiterals(substr($value, 0, strpos($value, 'L')));
$weekday = str_replace('7', '0', $weekday);

$tdate = clone $date;
$tdate->setDate($currentYear, $currentMonth, $lastDayOfMonth);
while ($tdate->format('w') != $weekday) {
Expand Down
12 changes: 12 additions & 0 deletions tests/Cron/DayOfWeekFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,18 @@ public function testHandlesZeroAndSevenDayOfTheWeekValues()
$this->assertTrue($f->isSatisfiedBy(new DateTime('2014-04-20 00:00:00'), '7#3'));
}

/**
* @covers \Cron\DayOfWeekField::isSatisfiedBy
*/
public function testHandlesLastWeekdayOfTheMonth()
{
$f = new DayOfWeekField();
$this->assertTrue($f->isSatisfiedBy(new DateTime('2018-12-28 00:00:00'), 'FRIL'));
$this->assertTrue($f->isSatisfiedBy(new DateTime('2018-12-28 00:00:00'), '5L'));
$this->assertFalse($f->isSatisfiedBy(new DateTime('2018-12-21 00:00:00'), 'FRIL'));
$this->assertFalse($f->isSatisfiedBy(new DateTime('2018-12-21 00:00:00'), '5L'));
}

/**
* @see https://github.com/mtdowling/cron-expression/issues/47
*/
Expand Down

0 comments on commit 02b8123

Please sign in to comment.