function google_analytics_counter_sec2hms in Google Analytics Counter 7.3
Same name and namespace in other branches
- 7.2 google_analytics_counter.module \google_analytics_counter_sec2hms()
Convert seconds to hours, minutes and seconds.
1 call to google_analytics_counter_sec2hms()
- google_analytics_counter_details in ./
google_analytics_counter.module - More information relevant to Google Analytics statistics for this site.
File
- ./
google_analytics_counter.module, line 431 - Basic functions for this module.
Code
function google_analytics_counter_sec2hms($sec, $padHours = FALSE) {
// start with a blank string
$hms = "";
// do the hours first: there are 3600 seconds in an hour, so if we divide
// the total number of seconds by 3600 and throw away the remainder, we're
// left with the number of hours in those seconds
$hours = intval(intval($sec) / 3600);
// add hours to $hms (with a leading 0 if asked for)
$hms .= $padHours ? str_pad($hours, 2, "0", STR_PAD_LEFT) . "h " : $hours . "h ";
// dividing the total seconds by 60 will give us the number of minutes
// in total, but we're interested in *minutes past the hour* and to get
// this, we have to divide by 60 again and then use the remainder
$minutes = intval($sec / 60 % 60);
// add minutes to $hms (with a leading 0 if needed)
$hms .= str_pad($minutes, 2, "0", STR_PAD_LEFT) . "m ";
// seconds past the minute are found by dividing the total number of seconds
// by 60 and using the remainder
$seconds = intval($sec % 60);
// add seconds to $hms (with a leading 0 if needed)
$hms .= str_pad($seconds, 2, "0", STR_PAD_LEFT);
// done!
return $hms . 's';
}