diff --git a/src/BusinessDays/Calculator.php b/src/BusinessDays/Calculator.php index 76ea0df..3c7b7e7 100644 --- a/src/BusinessDays/Calculator.php +++ b/src/BusinessDays/Calculator.php @@ -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'); @@ -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 */