[ create a new paste ] login | about

Link: http://codepad.org/nU9tLJGQ    [ raw code | output | fork ]

PHP, pasted on Feb 15:
<?php
   function roundDurationUp($duration_string='') {
     $parts = explode(':', $duration_string);
     // only deal with valid duration strings
     if (count($parts) != 3)
       return 0;
    
     // round the seconds up to minutes
     if ($parts[2] > 30)
       $parts[1]++;
    
     // round the minutes up to hours
     if ($parts[1] > 30)
       $parts[0]++;
    
     return $parts[0];
    }

print '24:00:02 => '.roundDurationUp('24:00:02'); // prints 24
print '<br />33:15:05 => '.roundDurationUp('33:15:05'); // prints 33
print '<br />48:40:30 => '.roundDurationUp('48:40:30'); // prints 49

?>


Output:
1
24:00:02 => 24<br />33:15:05 => 33<br />48:40:30 => 49


Create a new paste based on this one


Comments: