3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php date_default_timezone_set('Europe/Minsk'); $a = new DateTimeImmutable("2015-01-01 11:00:00"); $daySchedule = [ 'from' => '10:00+03:00', 'till' => '21:00+03:00', ]; $from = explode(':', substr($daySchedule['from'], 0, 5)); $till = explode(':', substr($daySchedule['till'], 0, 5)); $fromTz = new \DateTimeZone(substr($daySchedule['from'], 5)); $tillTz = new \DateTimeZone(substr($daySchedule['till'], 5)); $b = $a->setTime($from[0], $from[1]); $b = $b->setTimezone($fromTz); var_dump($a > $b, $a, $b); var_dump($a->getTimestamp()); var_dump($b->getTimestamp()); var_dump($a > $b, $a, $b);
based on g8j0v
Output for 7.0.20, 7.1.5 - 7.2.0
bool(true) object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2015-01-01 11:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(12) "Europe/Minsk" } object(DateTimeImmutable)#5 (3) { ["date"]=> string(26) "2015-01-01 10:00:00.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+03:00" } int(1420099200) int(1420095600) bool(true) object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2015-01-01 11:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(12) "Europe/Minsk" } object(DateTimeImmutable)#5 (3) { ["date"]=> string(26) "2015-01-01 10:00:00.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+03:00" }
Output for 5.5.24 - 7.0.6, 7.1.0
bool(false) object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2015-01-01 11:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(12) "Europe/Minsk" } object(DateTimeImmutable)#5 (3) { ["date"]=> string(26) "2015-01-01 10:00:00.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+03:00" } int(1420099200) int(1420095600) bool(true) object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2015-01-01 11:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(12) "Europe/Minsk" } object(DateTimeImmutable)#5 (3) { ["date"]=> string(26) "2015-01-01 10:00:00.000000" ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+03:00" }
Output for 5.4.11 - 5.4.45
Fatal error: Class 'DateTimeImmutable' not found in /in/PKhKl on line 5
Process exited with code 255.
Output for 5.3.21 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/PKhKl on line 7
Process exited with code 255.