Skip to content

Commit

Permalink
Merge pull request #129 from firoxer/master
Browse files Browse the repository at this point in the history
Handle 0-sized steps somewhat more sanely
  • Loading branch information
dragonmantank committed Nov 30, 2016
2 parents 3750e17 + 1caefe2 commit 1d5c609
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Cron/AbstractField.php
Expand Up @@ -76,8 +76,13 @@ public function isInRange($dateValue, $value)
public function isInIncrementsOfRanges($dateValue, $value)
{
$parts = array_map('trim', explode('/', $value, 2));
$stepSize = isset($parts[1]) ? $parts[1] : 0;
if (($parts[0] == '*' || $parts[0] === '0') && 0 !== $stepSize) {
$stepSize = isset($parts[1]) ? (int) $parts[1] : 0;

if ($stepSize === 0) {
return false;
}

if (($parts[0] == '*' || $parts[0] === '0')) {
return (int) $dateValue % $stepSize == 0;
}

Expand Down
2 changes: 2 additions & 0 deletions tests/Cron/AbstractFieldTest.php
Expand Up @@ -61,6 +61,8 @@ public function testTestsIfInIncrementsOfRanges()
$this->assertFalse($f->isInIncrementsOfRanges(3, '2-59'));
$this->assertFalse($f->isInIncrementsOfRanges(3, '2'));
$this->assertFalse($f->isInIncrementsOfRanges(3, '*'));
$this->assertFalse($f->isInIncrementsOfRanges(0, '*/0'));
$this->assertFalse($f->isInIncrementsOfRanges(1, '*/0'));

$this->assertTrue($f->isInIncrementsOfRanges(4, '4/10'));
$this->assertTrue($f->isInIncrementsOfRanges(14, '4/10'));
Expand Down

0 comments on commit 1d5c609

Please sign in to comment.