3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Converts a 'decimal time' in the format 1.5hours to DateInterval object * * @param Int $decimalTime * @return DateInterval */ function decTimeToInterval($decimalTime) { $hours = floor($decimalTime); $decimalTime -= $hours; $minutes = floor($decimalTime * 60); $decimalTime -= ($minutes/60); //$seconds = floor($decimalTime * 3600); $interval = new \DateInterval("PT{$hours}H{$minutes}M{$seconds}S"); return $interval; } echo decTimeToInterval(1.6890000)->format("%H:%I");
Output for git.master, git.master_jit
Warning: Undefined variable $seconds in /in/id082 on line 16 Fatal error: Uncaught Exception: Unknown or bad format (PT1H41MS) in /in/id082:16 Stack trace: #0 /in/id082(16): DateInterval->__construct('PT1H41MS') #1 /in/id082(20): decTimeToInterval(0.0056666666666667) #2 {main} thrown in /in/id082 on line 16
Process exited with code 255.
Output for rfc.property-hooks
Warning: Undefined variable $seconds in /in/id082 on line 16 Fatal error: Uncaught DateMalformedIntervalStringException: Unknown or bad format (PT1H41MS) in /in/id082:16 Stack trace: #0 /in/id082(16): DateInterval->__construct('PT1H41MS') #1 /in/id082(20): decTimeToInterval(0.0056666666666667) #2 {main} thrown in /in/id082 on line 16
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
75.07 ms | 401 KiB | 8 Q