3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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 7.1.0
object(DateTime)#2 (3) { ["date"]=> string(26) "2014-06-05 09:27:29.004085" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.28, 7.0.14
object(DateTime)#2 (3) { ["date"]=> string(26) "2014-06-05 09:27:29.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 7.0.6
object(DateTime)#2 (3) { ["date"]=> string(26) "2016-05-08 08:08:30.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 7.0.5
object(DateTime)#2 (3) { ["date"]=> string(26) "2016-04-05 21:05:32.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 7.0.4
object(DateTime)#2 (3) { ["date"]=> string(26) "2016-03-15 07:22:03.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 7.0.3
object(DateTime)#2 (3) { ["date"]=> string(26) "2016-03-22 07:54:25.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 7.0.2
object(DateTime)#2 (3) { ["date"]=> string(26) "2016-03-27 13:39:42.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 7.0.1
object(DateTime)#2 (3) { ["date"]=> string(26) "2016-03-28 18:40:52.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 7.0.0
object(DateTime)#2 (3) { ["date"]=> string(26) "2016-03-29 20:21:16.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for hhvm-3.12.0
object(DateTime)#2 (3) { ["date"]=> string(26) "2016-04-04 12:34:47.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for hhvm-3.10.0

Process exited with code 153.
Output for 5.6.21
object(DateTime)#2 (3) { ["date"]=> string(26) "2016-05-05 03:28:06.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.20
object(DateTime)#2 (3) { ["date"]=> string(26) "2016-04-12 19:56:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.19
object(DateTime)#2 (3) { ["date"]=> string(26) "2016-03-10 15:28:29.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.18
object(DateTime)#2 (3) { ["date"]=> string(26) "2016-03-17 23:14:11.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.17
object(DateTime)#2 (3) { ["date"]=> string(26) "2016-03-22 12:12:57.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.16
object(DateTime)#2 (3) { ["date"]=> string(26) "2016-03-30 22:07:01.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.15
object(DateTime)#2 (3) { ["date"]=> string(26) "2016-03-31 22:59:47.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.14
object(DateTime)#2 (3) { ["date"]=> string(26) "2016-04-05 01:34:24.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.13
object(DateTime)#2 (3) { ["date"]=> string(26) "2016-04-19 05:29:44.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.12
object(DateTime)#2 (3) { ["date"]=> string(26) "2016-04-24 19:06:43.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.11
object(DateTime)#2 (3) { ["date"]=> string(26) "2016-04-26 02:06:23.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.10
object(DateTime)#2 (3) { ["date"]=> string(26) "2016-04-28 03:56:42.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.9
object(DateTime)#2 (3) { ["date"]=> string(26) "2016-05-02 08:54:10.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.8
object(DateTime)#2 (3) { ["date"]=> string(26) "2016-05-03 16:54:27.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.6.7
object(DateTime)#2 (3) { ["date"]=> string(26) "2016-05-30 11:13:14.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.35
object(DateTime)#2 (3) { ["date"]=> string(26) "2016-05-25 07:09:33.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.34
object(DateTime)#2 (3) { ["date"]=> string(26) "2016-04-13 22:21:59.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.33
object(DateTime)#2 (3) { ["date"]=> string(26) "2016-03-13 18:17:55.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.32
object(DateTime)#2 (3) { ["date"]=> string(26) "2016-03-22 01:05:51.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.31
object(DateTime)#2 (3) { ["date"]=> string(26) "2016-03-23 14:59:53.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.30
object(DateTime)#2 (3) { ["date"]=> string(26) "2016-04-05 01:08:27.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.29
object(DateTime)#2 (3) { ["date"]=> string(26) "2016-04-19 19:34:48.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.28
object(DateTime)#2 (3) { ["date"]=> string(26) "2016-04-25 22:12:28.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.27
object(DateTime)#2 (3) { ["date"]=> string(26) "2016-04-26 00:43:17.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.26
object(DateTime)#2 (3) { ["date"]=> string(26) "2016-05-01 06:22:46.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.25
object(DateTime)#2 (3) { ["date"]=> string(26) "2016-05-03 12:26:11.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.5.24
object(DateTime)#2 (3) { ["date"]=> string(26) "2016-05-26 19:21:45.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.45
object(DateTime)#2 (3) { ["date"]=> string(26) "2015-09-08 00:33:07.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.44
object(DateTime)#2 (3) { ["date"]=> string(26) "2015-09-08 21:37:16.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.43
object(DateTime)#2 (3) { ["date"]=> string(26) "2015-09-08 21:37:13.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.42
object(DateTime)#2 (3) { ["date"]=> string(26) "2015-09-08 21:37:11.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.41
object(DateTime)#2 (3) { ["date"]=> string(26) "2015-09-08 21:37:09.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.40
object(DateTime)#2 (3) { ["date"]=> string(26) "2015-09-08 21:37:06.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.39
object(DateTime)#2 (3) { ["date"]=> string(26) "2015-09-08 21:37:05.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.38
object(DateTime)#2 (3) { ["date"]=> string(26) "2015-03-08 18:25:34.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.35 - 5.4.37
object(DateTime)#2 (3) { ["date"]=> string(26) "2015-03-08 18:25:25.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.34
object(DateTime)#2 (3) { ["date"]=> string(26) "2015-03-08 18:25:24.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.32
object(DateTime)#2 (3) { ["date"]=> string(26) "2014-09-16 10:25:03.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.31
object(DateTime)#2 (3) { ["date"]=> string(26) "2014-09-16 10:25:01.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.30
object(DateTime)#2 (3) { ["date"]=> string(26) "2014-09-16 10:24:57.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.29
object(DateTime)#2 (3) { ["date"]=> string(19) "2014-09-16 10:24:57" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.22 - 5.4.28
object(DateTime)#2 (3) { ["date"]=> string(19) "2014-06-05 09:27:33" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.2 - 5.4.21
object(DateTime)#2 (3) { ["date"]=> string(19) "2014-06-05 09:27:34" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.4.0 - 5.4.1
object(DateTime)#2 (3) { ["date"]=> string(19) "2014-06-05 09:27:35" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/NHEmG on line 53
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in /in/NHEmG on line 18
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_CONST, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/NHEmG on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_CONST, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/NHEmG on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/NHEmG on line 5
Process exited with code 255.