Created
May 4, 2018 20:36
-
-
Save jotapepinheiro/b31766166c329878c634470633e26fac to your computer and use it in GitHub Desktop.
Somar Horas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function soma_horas() { | |
$i = $s = $hour = $min = $sec = 0; | |
foreach (func_get_args() as $time) { | |
sscanf($time, '%d:%d:%d', $hour, $min, $sec); | |
$i += ($hour * 60) + $min + ($sec / 60); | |
$s += $sec; | |
} | |
if ($h = floor($i / 60)) { | |
$i %= 60; | |
$s %= 60; | |
} | |
return sprintf('%02d:%02d:%02d', $h, $i, $s); | |
} | |
echo soma_horas('01:50:50', '30:10:30', '02:10:15'); #34:11:35 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment