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; /** * @param DateTime $startDate Date to start calculations from * @param DateTime[] $holidays Array of holidays, holidays are no conisdered business days. * @param 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) { $this->date->modify("+1 day"); if ($this->isBusinessDay($this->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->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. } } $calculator = new BusinessDaysCalculator( 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
Deprecated: Creation of dynamic property BusinessDaysCalculator::$date is deprecated in /in/NHEmG on line 19 Deprecated: Creation of dynamic property BusinessDaysCalculator::$holidays is deprecated in /in/NHEmG on line 20 Deprecated: Creation of dynamic property BusinessDaysCalculator::$nonBusinessDays is deprecated in /in/NHEmG on line 21 object(DateTime)#2 (3) { ["date"]=> string(26) "2017-07-04 21:59:14.003758" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for git.master_jit
Deprecated: Creation of dynamic property BusinessDaysCalculator::$date is deprecated in /in/NHEmG on line 19 Deprecated: Creation of dynamic property BusinessDaysCalculator::$holidays is deprecated in /in/NHEmG on line 20 Deprecated: Creation of dynamic property BusinessDaysCalculator::$nonBusinessDays is deprecated in /in/NHEmG on line 21 object(DateTime)#2 (3) { ["date"]=> string(26) "2017-07-04 21:59:14.003792" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for rfc.property-hooks
Deprecated: Creation of dynamic property BusinessDaysCalculator::$date is deprecated in /in/NHEmG on line 19 Deprecated: Creation of dynamic property BusinessDaysCalculator::$holidays is deprecated in /in/NHEmG on line 20 Deprecated: Creation of dynamic property BusinessDaysCalculator::$nonBusinessDays is deprecated in /in/NHEmG on line 21 object(DateTime)#2 (3) { ["date"]=> string(26) "2017-07-04 21:59:14.006922" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }

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:
49.97 ms | 402 KiB | 8 Q