date = $startDate; $this->holidays = $holidays; $this->nonBusinessDays = $nonBusinessDays; $this->assocHollyday(); } public function assocHollyday() { $this->holidays[] = new DateTime((date('Y')+1)."-01-01"); $this->holidays[] = new DateTime(date('Y')."-01-01"); $this->holidays[] = new DateTime(date('Y')."-05-01"); $this->holidays[] = new DateTime(date('Y')."-05-08"); $this->holidays[] = new DateTime(date('Y')."-07-14"); $this->holidays[] = new DateTime(date('Y')."-08-15"); $this->holidays[] = new DateTime(date('Y')."-11-11"); $this->holidays[] = new DateTime(date('Y')."-12-25"); } public function addBusinessDays($howManyDays) { $i = 0; while ($i < $howManyDays) { $this->date->modify("+1 day"); if ($this->isBusinessDay($this->date)) { $i++; } } } public function addDaysWithCheckLastDay($howManyDays) { $i = 0; while ($i < $howManyDays) { $this->date->modify("+1 day"); $i++; } if (!$this->isBusinessDay($this->date)) { $this->date->modify("+1 day"); } } public function getDate() { return $this->date; } private function isBusinessDay(DateTime $date) { if (in_array((int)$date->format('N'), $this->nonBusinessDays)) { return false; //Date is a nonBusinessDay. } foreach ($this->holidays as $day) { if ($date->format('Y-m-d') == $day->format('Y-m-d')) { return false; //Date is a holiday. } } return true; //Date is a business day. } } }