Skip to content

Commit

Permalink
Merge 487671b into 0a66655
Browse files Browse the repository at this point in the history
  • Loading branch information
royopa committed Jan 23, 2018
2 parents 0a66655 + 487671b commit fc7549c
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/BusinessDays/Calculator.php
Expand Up @@ -120,6 +120,10 @@ private function getFreeWeekDays()
*/
public function addBusinessDays($howManyDays)
{
if ($howManyDays < 1) {
throw new \InvalidArgumentException('The parameter $howManyDays must be greater than 0');
}

$iterator = 0;
while ($iterator < $howManyDays) {
$this->getDate()->modify('+1 day');
Expand All @@ -131,6 +135,29 @@ public function addBusinessDays($howManyDays)
return $this;
}

/**
* @param int $howManyDays
*
* @return $this
*/
public function subBusinessDays($howManyDays)
{
if ($howManyDays < 1) {
throw new \InvalidArgumentException('The parameter $howManyDays must be greater than 0');
}

$iterator = 0;
while ($iterator < $howManyDays) {
if ($this->isBusinessDay($this->getDate())) {
$iterator++;
}
if ($iterator < $howManyDays) { //Don`t modify the date if we are on the last iteration
$this->getDate()->modify('-1 day');
}
}
return $this;
}

/**
* @return \DateTime
*/
Expand Down

0 comments on commit fc7549c

Please sign in to comment.