3v4l.org

run code in 300+ PHP versions simultaneously
<?php function addRollover($givenDate, $addtime, $dayStart, $dayEnd, $weekDaysOnly) { //Break the working day start and end times into hours, minuets $dayStart = explode(',', $dayStart); $dayEnd = explode(',', $dayEnd); //Create required datetime objects and hours interval $datetime = new DateTime($givenDate); $endofday = clone $datetime; $endofday->setTime($dayEnd[0], $dayEnd[1]); //set end of working day time $interval = 'PT'.$addtime.'H'; //Add hours onto initial given date $datetime->add(new DateInterval($interval)); //if initial date + hours is after the end of working day if($datetime > $endofday) { //get the difference between the initial date + interval and the end of working day in seconds $seconds = $datetime->getTimestamp()- $endofday->getTimestamp(); //Loop to next day while(true) { $endofday->add(new DateInterval('PT24H'));//Loop to next day by adding 24hrs $nextDay = $endofday->setTime($dayStart[0], $dayStart[1]);//Set day to working day start time //If the next day is on a weekend and the week day only param is true continue to add days if(in_array($nextDay->format('l'), array('Sunday')) && $weekDaysOnly) { continue; } else //If not a weekend { $tmpDate = clone $nextDay; $tmpDate->setTime($dayEnd[0], $dayEnd[1]);//clone the next day and set time to working day end time $nextDay->add(new DateInterval('PT'.$seconds.'S')); //add the seconds onto the next day //if the next day time is later than the end of the working day continue loop if($nextDay > $tmpDate) { $seconds = $nextDay->getTimestamp()-$tmpDate->getTimestamp(); $endofday = clone $tmpDate; $endofday->setTime($dayStart[0], $dayStart[1]); } else //else return the new date. { return $endofday; } } } } return $datetime; } $currentTime = '2015-02-08 02:30:00'; $dayStart = '9,00'; $dayEnd = '18,00'; $date = strtotime($currentTime); $currentHour = date('H', $date); if ($currentHour < 9){ echo $date->format('Y-m-d 9:i:s'); } $future = addRollover($currentTime, 10, $dayStart, $dayEnd, true); echo "Results: </br>"; echo $future->format('Y-m-d H:i:s').'</br>';

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.60.0220.00016.75
8.3.50.0050.01222.95
8.3.40.0070.00719.09
8.3.30.0070.00719.26
8.3.20.0000.00820.30
8.3.10.0000.00821.73
8.3.00.0050.00319.02
8.2.180.0110.01118.53
8.2.170.0000.01422.96
8.2.160.0000.01420.35
8.2.150.0080.00024.18
8.2.140.0060.00324.66
8.2.130.0090.00026.16
8.2.120.0080.00020.80
8.2.110.0070.01019.33
8.2.100.0040.00818.08
8.2.90.0060.00319.39
8.2.80.0080.00017.97
8.2.70.0050.00317.75
8.2.60.0040.00418.04
8.2.50.0060.00318.07
8.2.40.0000.00819.97
8.2.30.0080.00018.28
8.2.20.0000.00817.97
8.2.10.0020.00518.12
8.2.00.0050.00318.13
8.1.280.0220.00925.92
8.1.270.0040.00422.14
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0000.00921.12
8.1.230.0090.00317.51
8.1.220.0000.00817.77
8.1.210.0050.00318.77
8.1.200.0090.00017.72
8.1.190.0060.00317.38
8.1.180.0030.00519.26
8.1.170.0060.00318.91
8.1.160.0050.00322.14
8.1.150.0080.00019.01
8.1.140.0040.00417.65
8.1.130.0030.00317.82
8.1.120.0040.00417.68
8.1.110.0000.00817.71
8.1.100.0040.00417.53
8.1.90.0000.00817.66
8.1.80.0000.00717.74
8.1.70.0070.00017.71
8.1.60.0030.00617.80
8.1.50.0000.00717.77
8.1.40.0040.00417.58
8.1.30.0040.00417.88
8.1.20.0080.00017.77
8.1.10.0000.00717.66
8.1.00.0000.00817.61
8.0.300.0000.01018.77
8.0.290.0040.00417.00
8.0.280.0070.00018.47
8.0.270.0040.00417.14
8.0.260.0060.00017.25
8.0.250.0080.00017.31
8.0.240.0030.00317.29
8.0.230.0000.00717.24
8.0.220.0030.00317.11
8.0.210.0070.00017.09
8.0.200.0050.00317.15
8.0.190.0080.00017.15
8.0.180.0070.00017.14
8.0.170.0040.00417.17
8.0.160.0040.00417.30
8.0.150.0000.00717.11
8.0.140.0080.00317.17
8.0.130.0030.00313.53
8.0.120.0040.00417.13
8.0.110.0040.00417.21
8.0.100.0000.01017.00
8.0.90.0040.00417.14
8.0.80.0060.00917.21
8.0.70.0000.00817.23
8.0.60.0070.00017.19
8.0.50.0050.00317.20
8.0.30.0090.00917.46
8.0.20.0100.01017.40
8.0.10.0040.00417.22
8.0.00.0100.00816.86
7.4.330.0050.00015.09
7.4.320.0030.00316.59
7.4.300.0000.00616.70
7.4.290.0000.00716.61
7.4.280.0000.00716.77
7.4.270.0040.00416.82
7.4.260.0000.00816.79
7.4.250.0000.00716.75
7.4.240.0010.00616.71
7.4.230.0070.00016.73
7.4.220.0090.01416.75
7.4.210.0160.00316.74
7.4.200.0000.00716.89
7.4.160.0100.00716.85
7.4.150.0150.00317.40
7.4.140.0090.00817.86
7.4.130.0080.01116.69
7.4.120.0110.00816.75
7.4.110.0070.01016.77
7.4.100.0130.00616.82
7.4.90.0170.00016.58
7.4.80.0090.00919.39
7.4.70.0150.00316.76
7.4.60.0070.01016.90
7.4.50.0030.00316.79
7.4.40.0060.01116.59
7.4.30.0030.01316.83
7.4.00.0090.00915.18
7.3.330.0000.00713.46
7.3.320.0000.00513.41
7.3.310.0070.00016.43
7.3.300.0030.00316.47
7.3.290.0050.01016.50
7.3.280.0090.00916.56
7.3.270.0060.01317.40
7.3.260.0100.01016.61
7.3.250.0090.00816.83
7.3.240.0030.01416.45
7.3.230.0130.01016.49
7.3.210.0030.01316.66
7.3.200.0030.01419.39
7.3.190.0110.00616.52
7.3.180.0060.01016.81
7.3.170.0100.00616.82
7.3.160.0100.01316.69
7.3.10.0070.00516.79
7.3.00.0040.01116.82
7.2.330.0090.00916.87
7.2.320.0070.01016.89
7.2.310.0120.01216.51
7.2.300.0080.00816.88
7.2.290.0060.01216.65
7.2.130.0050.00717.10
7.2.120.0050.00816.89
7.2.110.0070.00516.97
7.2.100.0040.00816.82
7.2.90.0110.00216.96
7.2.80.0080.00517.02
7.2.70.0050.00616.90
7.2.60.0110.00316.95
7.2.50.0090.00816.94
7.2.40.0060.01017.00
7.2.30.0090.00716.76
7.2.20.0100.00617.14
7.2.10.0140.00317.11
7.2.00.0050.01017.91
7.1.250.0080.00615.94
7.1.200.0030.00915.98
7.1.100.0070.00718.35
7.1.70.0030.00717.19
7.1.60.0070.01819.57
7.1.50.0090.01517.14
7.1.00.0070.07322.52
7.0.200.0070.00317.02
7.0.140.0100.03322.10
7.0.110.0100.04320.07
7.0.100.0070.03720.12
7.0.90.0030.04020.08
7.0.80.0070.04319.89
7.0.70.0030.04719.97
7.0.60.0070.06319.97
7.0.50.0170.03019.90
7.0.40.0030.05319.71
7.0.30.0170.06019.78
7.0.20.0030.08019.84
7.0.10.0200.07719.85
7.0.00.0230.07719.70
5.6.280.0070.07021.17
5.6.260.0130.03020.77
5.6.250.0030.04020.69
5.6.240.0030.04020.71
5.6.230.0100.03320.59
5.6.220.0030.04720.69
5.6.210.0070.05720.74
5.6.200.0030.06020.58
5.6.190.0170.07020.54
5.6.180.0070.08320.61
5.6.170.0100.08020.62
5.6.160.0030.08020.65
5.6.150.0100.08320.87
5.6.140.0100.07320.63
5.6.130.0130.07320.73
5.6.120.0100.08020.57
5.6.110.0130.08020.70
5.6.100.0170.08020.60
5.6.90.0070.08320.71
5.6.80.0030.08020.09
5.6.70.0130.07320.10
5.6.60.0130.07319.98
5.6.50.0200.06720.07
5.6.40.0070.08319.93
5.6.30.0200.06720.01
5.6.20.0170.05720.23
5.6.10.0170.06719.93
5.6.00.0030.08020.22
5.5.380.0000.05717.65
5.5.370.0070.04017.62
5.5.360.0030.08017.69
5.5.350.0030.04317.78
5.5.340.0030.04018.13
5.5.330.0030.04318.23
5.5.320.0100.07318.23
5.5.310.0030.08017.84
5.5.300.0130.06318.23
5.5.290.0130.08018.13
5.5.280.0170.07017.93
5.5.270.0130.07318.12
5.5.260.0130.07318.09
5.5.250.0030.08717.74
5.5.240.0100.08017.62
5.5.230.0200.07017.29
5.5.220.0030.07317.48
5.5.210.0100.07717.48
5.5.200.0030.08317.45
5.5.190.0030.08017.32
5.5.180.0130.06317.29
5.5.160.0070.07717.24
5.5.150.0100.06717.45
5.5.140.0000.04317.18
5.5.130.0070.07717.48
5.5.120.0130.04017.27
5.5.110.0000.08317.28
5.5.100.0070.06017.48
5.5.90.0030.05717.35
5.5.80.0130.07717.38
5.5.70.0170.07017.37
5.5.60.0100.07317.37
5.5.50.0070.07717.15
5.5.40.0070.07317.37
5.5.30.0070.08717.20
5.5.20.0070.07717.16
5.5.10.0070.05317.07
5.5.00.0070.08317.32
5.4.450.0030.08319.64
5.4.440.0100.07719.30
5.4.430.0070.08019.55
5.4.420.0200.06719.35
5.4.410.0100.07719.44
5.4.400.0100.04719.00
5.4.390.0030.06719.04
5.4.380.0100.07719.18
5.4.370.0070.07319.01
5.4.360.0030.08019.23
5.4.350.0030.08319.21
5.4.340.0030.07719.31
5.4.320.0070.08018.97
5.4.310.0100.06319.14
5.4.300.0030.06319.23
5.4.290.0030.08019.00
5.4.280.0100.06718.98
5.4.270.0100.08019.14
5.4.260.0100.06719.00
5.4.250.0170.06719.31
5.4.240.0100.07319.00
5.4.230.0200.05318.99
5.4.220.0070.07718.98
5.4.210.0070.08018.98
5.4.200.0130.07319.00
5.4.190.0030.07319.25
5.4.180.0170.07019.00
5.4.170.0130.07319.23
5.4.160.0130.06718.97
5.4.150.0070.08319.07
5.4.140.0100.07016.54
5.4.130.0100.06316.45
5.4.120.0130.06316.44
5.4.110.0170.07016.59
5.4.100.0070.07716.57
5.4.90.0070.06316.49
5.4.80.0030.06716.45
5.4.70.0100.06716.53
5.4.60.0100.07016.54
5.4.50.0100.07016.38
5.4.40.0130.07016.44
5.4.30.0070.07016.48
5.4.20.0100.07016.56
5.4.10.0100.05016.62
5.4.00.0030.07315.89
5.3.290.0070.07714.77
5.3.280.0070.08314.63
5.3.270.0030.08314.66
5.3.260.0130.06714.66
5.3.250.0000.08314.71
5.3.240.0100.07714.66
5.3.230.0030.07714.63
5.3.220.0130.06714.71
5.3.210.0100.05714.62
5.3.200.0000.07014.58
5.3.190.0030.07314.60
5.3.180.0070.07314.80
5.3.170.0100.06714.71
5.3.160.0100.08014.67
5.3.150.0070.07014.72
5.3.140.0100.06314.43
5.3.130.0200.06314.69
5.3.120.0130.07314.65
5.3.110.0070.07314.57
5.3.100.0100.07714.19
5.3.90.0130.07014.02
5.3.80.0030.06014.06
5.3.70.0130.07014.01
5.3.60.0070.07014.15
5.3.50.0000.08013.96
5.3.40.0030.04713.96
5.3.30.0100.08013.78
5.3.20.0100.07013.85
5.3.10.0100.05713.67
5.3.00.0070.06313.71
5.2.170.0030.04311.17
5.2.160.0070.03011.14
5.2.150.0000.06011.30
5.2.140.0030.07011.18
5.2.130.0070.06011.25
5.2.120.0000.06711.08
5.2.110.0070.04010.98
5.2.100.0000.03711.11
5.2.90.0070.05711.20
5.2.80.0030.03311.34
5.2.70.0070.06311.11
5.2.60.0030.06711.08
5.2.50.0070.06011.13
5.2.40.0070.05711.04
5.2.30.0070.06010.95
5.2.20.0100.06011.04
5.2.10.0130.05310.87
5.2.00.0030.06310.59
5.1.60.0070.05310.19
5.1.50.0000.05010.19
5.1.40.0100.04310.19
5.1.30.0030.06010.43
5.1.20.0130.05010.35
5.1.10.0000.06010.26
5.1.00.0030.02710.19
5.0.50.0070.04310.19
5.0.40.0030.02710.19
5.0.30.0000.05010.19
5.0.20.0000.04710.19
5.0.10.0100.02310.19
5.0.00.0030.06310.19
4.4.90.0100.03010.19
4.4.80.0030.03710.19
4.4.70.0100.03010.19
4.4.60.0070.02310.19
4.4.50.0030.04010.19
4.4.40.0130.04010.19
4.4.30.0030.03310.19
4.4.20.0000.02310.19
4.4.10.0000.03710.19
4.4.00.0000.05310.19
4.3.110.0070.03010.19
4.3.100.0030.03310.19
4.3.90.0030.03310.19
4.3.80.0030.03710.19
4.3.70.0070.03010.19
4.3.60.0030.03310.19
4.3.50.0030.03010.19
4.3.40.0030.05010.19
4.3.30.0000.03010.19
4.3.20.0030.03310.19
4.3.10.0000.03710.19
4.3.00.0000.03010.19

preferences:
61.17 ms | 401 KiB | 5 Q