3v4l.org

run code in 300+ PHP versions simultaneously
<?php function calculate_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 $this->obj_logger->debug("Pickup time/now hour diff is " . $obj_pickup_time->diff($obj_now)->h); if ($obj_now->diff($obj_pickup_time)->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; } } $this->obj_logger->debug("Adding $int_add_days days to " . $obj_pickup_time->format('Y-m-d H:i')); if ($int_add_days > 0) { $obj_pickup_time->add(new DateInterval('P' . $int_add_days . 'D')); } $this->obj_logger->debug("Pickup time is now " . $obj_pickup_time->format('Y-m-d H:i')); return $obj_pickup_time; } echo calculate_pickup_time('18:00')->format('Y-m-d H:i:s');;
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.35
Fatal error: Using $this when not in object context in /in/mAOMP on line 16
Process exited with code 255.
Output for 5.2.10 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/mAOMP on line 5 Fatal error: Call to undefined method DateTime::createFromFormat() in /in/mAOMP on line 13
Process exited with code 255.
Output for 5.2.0 - 5.2.9
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/mAOMP on line 5 Fatal error: Call to undefined method DateTime::createfromformat() in /in/mAOMP on line 13
Process exited with code 255.
Output for 5.0.0 - 5.0.5, 5.1.0 - 5.1.6
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/mAOMP on line 5 Fatal error: Class 'DateTime' not found in /in/mAOMP on line 8
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_NEW in /in/mAOMP on line 5
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/mAOMP on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/mAOMP on line 5
Process exited with code 255.

preferences:
232.12 ms | 1386 KiB | 125 Q