3v4l.org

run code in 300+ PHP versions simultaneously
<?php date_default_timezone_set('UTC'); function get_pickup_time($str_cutoff_time, $int_flags = 0) { if (!preg_match('#^\d{2}:\d{2}$#', $str_cutoff_time)) { throw new \LogicException('Cutoff time must be expressed in 24 hour hh:mm format'); } $obj_now = new DateTime; $int_today = (int)$obj_now->format('N'); $int_add_days = 0; // cutoff time - 2 hr pickup window $obj_pickup_time = DateTime::createFromFormat('H:i', $str_cutoff_time)->sub(new DateInterval('PT2H')); // 2 hr lead time if ($obj_pickup_time->diff($obj_now)->h >= 2) { if (($int_today === 6 && !($int_flags & self::PICKUP_ALLOW_SATURDAY)) || ($int_today === 7 && !($int_flags & self::PICKUP_ALLOW_SUNDAY))) { // we don't deliver today $int_add_days = 8 - $int_today; } } else { if ($int_today === 5 && !($int_flags & self::PICKUP_ALLOW_SATURDAY)) { // today is friday and we don't do saturday $int_add_days = $int_flags & self::PICKUP_ALLOW_SUNDAY ? 2 : 3; } else if ($int_today === 6 && !($int_flags & self::PICKUP_ALLOW_SUNDAY)) { // today is saturday and we don't do sunday $int_add_days = 2; } else { $int_add_days = 1; } } if ($int_add_days > 0) { $obj_pickup_time->add(new DateInterval('P' . $int_add_days . 'D')); } return $obj_pickup_time; } var_dump((new DateTime)->format('Y-m-d H:i'), get_pickup_time('17:00')->format('Y-m-d H:i'));
Output for 5.6.28
string(16) "2014-11-06 13:00" string(16) "2014-11-06 15:00"
Output for 5.6.19
string(16) "2016-03-07 03:51" string(16) "2016-03-07 15:00"
Output for 5.6.18
string(16) "2016-03-14 16:49" string(16) "2016-03-15 15:00"
Output for 5.6.15
string(16) "2016-03-28 18:37" string(16) "2016-03-28 15:00"
Output for 5.6.14
string(16) "2016-04-01 21:08" string(16) "2016-04-01 15:00"
Output for 5.6.13
string(16) "2016-04-15 01:10" string(16) "2016-04-15 15:00"
Output for 5.6.12
string(16) "2016-04-19 14:38" string(16) "2016-04-20 15:00"
Output for 5.6.11
string(16) "2016-04-22 21:34" string(16) "2016-04-22 15:00"
Output for 5.6.9
string(16) "2016-04-27 04:27" string(16) "2016-04-27 15:00"
Output for 5.6.8
string(16) "2016-04-29 12:18" string(16) "2016-04-29 15:00"
Output for 5.6.7
string(16) "2016-05-25 02:09" string(16) "2016-05-25 15:00"
Output for 5.5.33
string(16) "2016-03-08 14:42" string(16) "2016-03-09 15:00"
Output for 5.5.32
string(16) "2016-03-16 20:35" string(16) "2016-03-16 15:00"
Output for 5.5.30
string(16) "2016-03-31 20:39" string(16) "2016-03-31 15:00"
Output for 5.5.28
string(16) "2016-04-20 17:41" string(16) "2016-04-20 15:00"
Output for 5.5.27
string(16) "2016-04-21 19:59" string(16) "2016-04-21 15:00"
Output for 5.5.26
string(16) "2016-04-26 01:50" string(16) "2016-04-26 15:00"
Output for 5.5.25
string(16) "2016-04-28 07:48" string(16) "2016-04-28 15:00"
Output for 5.5.24
string(16) "2016-05-23 14:40" string(16) "2016-05-24 15:00"
Output for 5.4.43 - 5.4.45
string(16) "2015-09-07 08:12" string(16) "2015-09-07 15:00"
Output for 5.4.41 - 5.4.42
string(16) "2015-06-16 11:43" string(16) "2015-06-16 15:00"
Output for 5.4.36 - 5.4.40
string(16) "2015-05-13 15:05" string(16) "2015-05-14 15:00"
Output for 5.4.35
string(16) "2015-05-13 15:04" string(16) "2015-05-14 15:00"
Output for 5.4.0 - 5.4.34
string(16) "2014-11-06 13:00" string(16) "2014-11-07 15:00"
Output for 5.3.0 - 5.3.29
Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /in/JOhgB on line 40
Process exited with code 255.
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/JOhgB on line 7 Parse error: syntax error, unexpected T_OBJECT_OPERATOR in /in/JOhgB on line 40
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/JOhgB on line 7 Parse error: parse error, unexpected T_OBJECT_OPERATOR in /in/JOhgB on line 40
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_NEW in /in/JOhgB on line 7
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_NEW in /in/JOhgB on line 7
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/JOhgB on line 7
Process exited with code 255.

preferences:
255.92 ms | 1395 KiB | 154 Q