3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function getRoundedCutoff ($t) { list($hour, $min, $sec) = explode(':', $t); $rmin = $time[1] % 15; $dt = new DateTime( $t ); if ( $sec > 30 ) { $dt->add(new DateInterval('PT'.(60-$sec).'M')); } else { $dt->sub(new DateInterval('PT'.$sec.'M')); } if ( $rmin > 7 ) { $dt->add(new DateInterval('PT'.(15-$rmin).'M')); } else { $dt->sub(new DateInterval('PT'.$rmin.'M')); } return $dt->format('H:i:s'); } $times = array( '10:52:00', '10:52:59', '10:53:00', '10:50:00', '10:50:14', '10:50:59', '10:50:45', '01:12:00', '01:05:00', '01:58:00', '01:58:59', '01:59:59', '01:01:00', ); foreach ($times as $time) { var_dump($time.' -> '.getRoundedCutoff($time)); }
Output for 5.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Notice: Undefined variable: time in /in/XH9h1 on line 4 string(20) "10:52:00 -> 10:52:00" Notice: Undefined variable: time in /in/XH9h1 on line 4 string(20) "10:52:59 -> 10:53:59" Notice: Undefined variable: time in /in/XH9h1 on line 4 string(20) "10:53:00 -> 10:53:00" Notice: Undefined variable: time in /in/XH9h1 on line 4 string(20) "10:50:00 -> 10:50:00" Notice: Undefined variable: time in /in/XH9h1 on line 4 string(20) "10:50:14 -> 10:36:14" Notice: Undefined variable: time in /in/XH9h1 on line 4 string(20) "10:50:59 -> 10:51:59" Notice: Undefined variable: time in /in/XH9h1 on line 4 string(20) "10:50:45 -> 11:05:45" Notice: Undefined variable: time in /in/XH9h1 on line 4 string(20) "01:12:00 -> 01:12:00" Notice: Undefined variable: time in /in/XH9h1 on line 4 string(20) "01:05:00 -> 01:05:00" Notice: Undefined variable: time in /in/XH9h1 on line 4 string(20) "01:58:00 -> 01:58:00" Notice: Undefined variable: time in /in/XH9h1 on line 4 string(20) "01:58:59 -> 01:59:59" Notice: Undefined variable: time in /in/XH9h1 on line 4 string(20) "01:59:59 -> 02:00:59" Notice: Undefined variable: time in /in/XH9h1 on line 4 string(20) "01:01:00 -> 01:01:00"
Output for 5.2.0 - 5.2.17
Notice: Undefined variable: time in /in/XH9h1 on line 4 Fatal error: Call to undefined method DateTime::sub() in /in/XH9h1 on line 10
Process exited with code 255.
Output for 5.0.4 - 5.1.6
Notice: Undefined variable: time in /in/XH9h1 on line 4 Fatal error: Class 'DateTime' not found in /in/XH9h1 on line 5
Process exited with code 255.
Output for 5.0.0 - 5.0.3
Notice: Undefined variable: time in /in/XH9h1 on line 4 Fatal error: Class 'DateTime' not found in /in/XH9h1 on line 5
Process exited with code 255.
Output for 4.3.2 - 4.4.9
Notice: Undefined variable: time in /in/XH9h1 on line 4 Fatal error: Cannot instantiate non-existent class: datetime in /in/XH9h1 on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Notice: Undefined variable: time in /in/XH9h1 on line 4 Fatal error: Cannot instantiate non-existent class: datetime in /in/XH9h1 on line 5