Convert seconds to h:m:s

Discussion in 'General' started by bogus, Jul 9, 2008.

  1. bogus

    Joined:
    Jul 8, 2007
    Messages:
    5
    Likes Received:
    0
    May be someone else would like change the seconds to h:m;s for "Duration" in his CDR Rport.
    Or maybe to devs would like to make it configurable through Preferences :)
    Otherwise for it's for me, so that I can find this information after the next upgrade easily :whistle:

    The small function for that I found on the net.
    (please see http://www.laughing-buddha.net/jon/php/sec2hms/ for more information)


    To integrate is I had to change the line 244 in /var/www/html/modules/cdrreport/index.php

    from
    Code:
    244 $arrTmp[7] = $cdr[8];
    to
    Code:
    244 $arrTmp[7] = sec2hms($cdr[8], true); 
    // false = no leading zero for hours below 10 
    // true = add leading zero to hours below 10
    and to add the function to end of the file at line 286

    before
    Code:
    284        return $oGrid->fetchGrid($arrGrid, $arrData,$arrLang);
    285    }
    286    }
    287    ?>
    EOF
    after
    Code:
    284        return $oGrid->fetchGrid($arrGrid, $arrData,$arrLang);
    285     }
    286	}
    287	function sec2hms ($sec, $padHours) 
    288	{
    289	// holds formatted string
    290	$hms = "";
    291	
    292	// there are 3600 seconds in an hour, so if we
    293	// divide total seconds by 3600 and throw away
    294	// the remainder, we've got the number of hours
    295	$hours = intval(intval($sec) / 3600); 
    296	// add to $hms, with a leading 0 if asked for
    297	$hms .= ($padHours) 
    298     ? str_pad($hours, 2, "0", STR_PAD_LEFT). ':'
    299     : $hours. ':';
    300 
    301	// dividing the total seconds by 60 will give us
    302	// the number of minutes, but we're interested in 
    303	// minutes past the hour: to get that, we need to 
    304	// divide by 60 again and keep the remainder
    305	$minutes = intval(($sec / 60) % 60); 
    306
    307     // then add to $hms (with a leading 0 if needed)
    308     $hms .= str_pad($minutes, 2, "0", STR_PAD_LEFT). ':';
    309
    310     // seconds are simple - just divide the total
    311     // seconds by 60 and keep the remainder
    312	$seconds = intval($sec % 60); 
    313
    314     // add to $hms, again with a leading 0 if needed
    315     $hms .= str_pad($seconds, 2, "0", STR_PAD_LEFT);
    316	
    317	// done!
    318	return $hms;
    319	}
    320	?>
    EOF
    I hope someone could find this info useful.<br><br>Post edited by: bogus, at: 2008/07/08 20:56
     

Share This Page