3v4l.org

run code in 300+ PHP versions simultaneously
<?php class DTBug { private $intervals = [ '1min' => null, '1day' => null, '1wk' => null, ]; private $inspectCalc; public function __construct($inspectStored=false, $inspectCalc=false) { $this->inspectCalc = $inspectCalc; $this->intervals['1min'] = new \DateInterval("PT1M"); $this->intervals['1day'] = new \DateInterval("P1D"); $this->intervals['1wk'] = new \DateInterval("P7D"); if ($inspectStored) { array_map(function($s) { var_export($s, true); }, $this->intervals); } } public function compare(DateTimeInterface $start, DateTimeInterface $end) { $diff = $start->diff($end, true); if ($this->inspectCalc) { var_export($diff, true); } if ($diff < $this->intervals['1min']) { $op = "less than a minute"; } elseif ($diff < $this->intervals['1day']) { $op = "between an minute and a day"; } elseif ($diff < $this->intervals['1wk']) { $op = "between a day and a week"; } else { $op = "greater than a week"; } $this->output($start, $end, $op); } private function output(DateTimeInterface $start, DateTimeInterface $end, $op) { echo $start->format("Y-m-d H:i:s")." is ".$op." from ".$end->format("Y-m-d H:i:s")."\n"; } } echo "\nTesting without looking at the intervals:\n"; $bug = new DTBug; $bug->compare(new DateTimeImmutable("2016-05-16 09:12:32"), new DateTimeImmutable("2016-05-16 09:13:35")); // 1min 3sec $bug->compare(new DateTimeImmutable("2016-05-16 09:12:32"), new DateTimeImmutable("2016-05-16 12:13:35")); // 3hrs 1min 3sec $bug->compare(new DateTimeImmutable("2016-05-16 09:12:32"), new DateTimeImmutable("2016-05-18 09:13:35")); // 2day 1min 3sec $bug->compare(new DateTimeImmutable("2016-05-16 09:12:32"), new DateTimeImmutable("2016-07-16 09:13:35")); // 2mon 1min 3sec echo "\nTesting whilst looking at the stored intervals:\n"; $debug = new DTBug(true); $debug->compare(new DateTimeImmutable("2016-05-16 09:12:32"), new DateTimeImmutable("2016-05-16 09:13:35")); // 1min 3sec $debug->compare(new DateTimeImmutable("2016-05-16 09:12:32"), new DateTimeImmutable("2016-05-16 12:13:35")); // 3hrs 1min 3sec $debug->compare(new DateTimeImmutable("2016-05-16 09:12:32"), new DateTimeImmutable("2016-05-18 09:13:35")); // 2day 1min 3sec $debug->compare(new DateTimeImmutable("2016-05-16 09:12:32"), new DateTimeImmutable("2016-07-16 09:13:35")); // 2mon 1min 3sec echo "\nTesting whilst looking at the calculated intervals only:\n"; $debug = new DTBug(false, true); $debug->compare(new DateTimeImmutable("2016-05-16 09:12:32"), new DateTimeImmutable("2016-05-16 09:13:35")); // 1min 3sec $debug->compare(new DateTimeImmutable("2016-05-16 09:12:32"), new DateTimeImmutable("2016-05-16 12:13:35")); // 3hrs 1min 3sec $debug->compare(new DateTimeImmutable("2016-05-16 09:12:32"), new DateTimeImmutable("2016-05-18 09:13:35")); // 2day 1min 3sec $debug->compare(new DateTimeImmutable("2016-05-16 09:12:32"), new DateTimeImmutable("2016-07-16 09:13:35")); // 2mon 1min 3sec echo "\nTesting whilst looking at the both intervals:\n"; $debug = new DTBug(true, true); $debug->compare(new DateTimeImmutable("2016-05-16 09:12:32"), new DateTimeImmutable("2016-05-16 09:13:35")); // 1min 3sec $debug->compare(new DateTimeImmutable("2016-05-16 09:12:32"), new DateTimeImmutable("2016-05-16 12:13:35")); // 3hrs 1min 3sec $debug->compare(new DateTimeImmutable("2016-05-16 09:12:32"), new DateTimeImmutable("2016-05-18 09:13:35")); // 2day 1min 3sec $debug->compare(new DateTimeImmutable("2016-05-16 09:12:32"), new DateTimeImmutable("2016-07-16 09:13:35")); // 2mon 1min 3sec
Output for 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Testing without looking at the intervals: Warning: Cannot compare DateInterval objects in /in/TrPvp on line 29 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 31 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 33 2016-05-16 09:12:32 is greater than a week from 2016-05-16 09:13:35 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 29 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 31 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 33 2016-05-16 09:12:32 is greater than a week from 2016-05-16 12:13:35 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 29 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 31 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 33 2016-05-16 09:12:32 is greater than a week from 2016-05-18 09:13:35 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 29 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 31 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 33 2016-05-16 09:12:32 is greater than a week from 2016-07-16 09:13:35 Testing whilst looking at the stored intervals: Warning: Cannot compare DateInterval objects in /in/TrPvp on line 29 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 31 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 33 2016-05-16 09:12:32 is greater than a week from 2016-05-16 09:13:35 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 29 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 31 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 33 2016-05-16 09:12:32 is greater than a week from 2016-05-16 12:13:35 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 29 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 31 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 33 2016-05-16 09:12:32 is greater than a week from 2016-05-18 09:13:35 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 29 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 31 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 33 2016-05-16 09:12:32 is greater than a week from 2016-07-16 09:13:35 Testing whilst looking at the calculated intervals only: Warning: Cannot compare DateInterval objects in /in/TrPvp on line 29 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 31 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 33 2016-05-16 09:12:32 is greater than a week from 2016-05-16 09:13:35 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 29 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 31 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 33 2016-05-16 09:12:32 is greater than a week from 2016-05-16 12:13:35 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 29 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 31 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 33 2016-05-16 09:12:32 is greater than a week from 2016-05-18 09:13:35 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 29 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 31 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 33 2016-05-16 09:12:32 is greater than a week from 2016-07-16 09:13:35 Testing whilst looking at the both intervals: Warning: Cannot compare DateInterval objects in /in/TrPvp on line 29 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 31 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 33 2016-05-16 09:12:32 is greater than a week from 2016-05-16 09:13:35 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 29 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 31 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 33 2016-05-16 09:12:32 is greater than a week from 2016-05-16 12:13:35 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 29 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 31 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 33 2016-05-16 09:12:32 is greater than a week from 2016-05-18 09:13:35 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 29 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 31 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 33 2016-05-16 09:12:32 is greater than a week from 2016-07-16 09:13:35
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Testing without looking at the intervals: Warning: Cannot compare DateInterval objects in /in/TrPvp on line 29 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 31 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 33 2016-05-16 09:12:32 is greater than a week from 2016-05-16 09:13:35 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 29 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 31 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 33 2016-05-16 09:12:32 is greater than a week from 2016-05-16 12:13:35 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 29 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 31 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 33 2016-05-16 09:12:32 is greater than a week from 2016-05-18 09:13:35 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 29 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 31 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 33 2016-05-16 09:12:32 is greater than a week from 2016-07-16 09:13:35 Testing whilst looking at the stored intervals: Warning: Cannot compare DateInterval objects in /in/TrPvp on line 29 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 31 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 33 2016-05-16 09:12:32 is greater than a week from 2016-05-16 09:13:35 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 29 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 31 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 33 2016-05-16 09:12:32 is greater than a week from 2016-05-16 12:13:35 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 29 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 31 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 33 2016-05-16 09:12:32 is greater than a week from 2016-05-18 09:13:35 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 29 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 31 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 33 2016-05-16 09:12:32 is greater than a week from 2016-07-16 09:13:35 Testing whilst looking at the calculated intervals only: Warning: Cannot compare DateInterval objects in /in/TrPvp on line 29 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 31 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 33 2016-05-16 09:12:32 is greater than a week from 2016-05-16 09:13:35 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 29 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 31 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 33 2016-05-16 09:12:32 is greater than a week from 2016-05-16 12:13:35 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 29 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 31 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 33 2016-05-16 09:12:32 is greater than a week from 2016-05-18 09:13:35 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 29 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 31 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 33 2016-05-16 09:12:32 is greater than a week from 2016-07-16 09:13:35 Testing whilst looking at the both intervals: Warning: Cannot compare DateInterval objects in /in/TrPvp on line 29 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 31 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 33 2016-05-16 09:12:32 is greater than a week from 2016-05-16 09:13:35 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 29 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 31 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 33 2016-05-16 09:12:32 is greater than a week from 2016-05-16 12:13:35 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 29 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 31 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 33 2016-05-16 09:12:32 is greater than a week from 2016-05-18 09:13:35 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 29 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 31 Warning: Cannot compare DateInterval objects in /in/TrPvp on line 33 2016-05-16 09:12:32 is greater than a week from 2016-07-16 09:13:35
Output for 5.5.8 - 5.5.35, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33
Testing without looking at the intervals: 2016-05-16 09:12:32 is greater than a week from 2016-05-16 09:13:35 2016-05-16 09:12:32 is greater than a week from 2016-05-16 12:13:35 2016-05-16 09:12:32 is greater than a week from 2016-05-18 09:13:35 2016-05-16 09:12:32 is greater than a week from 2016-07-16 09:13:35 Testing whilst looking at the stored intervals: 2016-05-16 09:12:32 is less than a minute from 2016-05-16 09:13:35 2016-05-16 09:12:32 is less than a minute from 2016-05-16 12:13:35 2016-05-16 09:12:32 is less than a minute from 2016-05-18 09:13:35 2016-05-16 09:12:32 is less than a minute from 2016-07-16 09:13:35 Testing whilst looking at the calculated intervals only: 2016-05-16 09:12:32 is greater than a week from 2016-05-16 09:13:35 2016-05-16 09:12:32 is greater than a week from 2016-05-16 12:13:35 2016-05-16 09:12:32 is greater than a week from 2016-05-18 09:13:35 2016-05-16 09:12:32 is greater than a week from 2016-07-16 09:13:35 Testing whilst looking at the both intervals: 2016-05-16 09:12:32 is between an minute and a day from 2016-05-16 09:13:35 2016-05-16 09:12:32 is between an minute and a day from 2016-05-16 12:13:35 2016-05-16 09:12:32 is between a day and a week from 2016-05-18 09:13:35 2016-05-16 09:12:32 is greater than a week from 2016-07-16 09:13:35
Output for 5.5.0 - 5.5.7
Testing without looking at the intervals: Fatal error: DateTime::diff() must be derived from DateTimeImmutable::diff in Unknown on line 0
Process exited with code 255.

preferences:
216.53 ms | 401 KiB | 227 Q