3v4l.org

run code in 300+ PHP versions simultaneously
<?php class BusinessDaysCalculator { const MONDAY = 1; const TUESDAY = 2; const WEDNESDAY = 3; const THURSDAY = 4; const FRIDAY = 5; const SATURDAY = 6; const SUNDAY = 7; /** * DateTime $startDate Date to start calculations from * DateTime[] $holidays Array of holidays, holidays are no conisdered business days. * int[] $nonBusinessDays Array of days of the week which are not business days. */ public function __construct(DateTime $startDate, array $holidays, array $nonBusinessDays) { $this->date = $startDate; $this->holidays = $holidays; $this->nonBusinessDays = $nonBusinessDays; } public function addBusinessDays($howManyDays) { $i = 0; while ($i < $howManyDays) { $date->modify("+1 day"); if ($this->isBusinessDay($date)) { $i++; } } } 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->nonBusinessDays 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. } } $calculator = new BusinessDayCalculator( [new DateTime()], // Today [new DateTime("2014-06-01"), new DateTime("2014-06-02")], [BusinessDaysCalculator::SATURDAY, BusinessDaysCalculator::FRIDAY] ); $calculator->addBusinessDays(3); // Add three business days var_dump($calculator->getDate());
Output for git.master, git.master_jit, rfc.property-hooks
Fatal error: Uncaught Error: Class "BusinessDayCalculator" not found in /in/Acq3N:51 Stack trace: #0 {main} thrown in /in/Acq3N on line 51
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
39.79 ms | 401 KiB | 8 Q