You are here

function embonus_seconds_to_time in Embedded Media Field 6.2

Display seconds as HH:MM:SS, with leading 0's.

Parameters

$seconds: The number of seconds to display.

1 call to embonus_seconds_to_time()
embonus_emfield_widget_extra in contrib/embonus/embonus.module
Implementation of hook_emfield_widget_extra().

File

contrib/embonus/embonus.module, line 144

Code

function embonus_seconds_to_time($seconds) {

  // Number of seconds in an hour.
  $unith = 3600;

  // Number of seconds in a minute.
  $unitm = 60;

  // '/' given value by num sec in hour... output = HOURS
  $hh = intval($seconds / $unith);

  // Multiply number of hours by seconds, then subtract from given value.
  // Output = REMAINING seconds.
  $ss_remaining = $seconds - $hh * 3600;

  // Take remaining seconds and divide by seconds in a min... output = MINS.
  $mm = intval($ss_remaining / $unitm);

  // Multiply number of mins by seconds, then subtract from remaining seconds.
  // Output = REMAINING seconds.
  $ss = $ss_remaining - $mm * 60;
  $output = '';

  // If we have any hours, then prepend that to our output.
  if ($hh) {
    $output .= "{$hh}:";
  }

  // Create a safe-for-output MM:SS.
  $output .= check_plain(sprintf($hh ? "%02d:%02d" : "%d:%02d", $mm, $ss));
  return $output;
}