You are here

public function FeedsYoutubeParser::secsToTime in Feeds: YouTube Parser 6

Same name and namespace in other branches
  1. 7.2 FeedsYoutubeParser.inc \FeedsYoutubeParser::secsToTime()

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

Parameters

$seconds: The number of seconds to display.

2 calls to FeedsYoutubeParser::secsToTime()
FeedsYoutubeParser::parseAtom in ./FeedsYoutubeParser.inc
Parse Atom feed
FeedsYoutubeParser::parseRss20 in ./FeedsYoutubeParser.inc
Parse RSS 2.0 feed

File

./FeedsYoutubeParser.inc, line 160
Feeds parser class for Youtube

Class

FeedsYoutubeParser
Class definition for Youtube Parser.

Code

public function secsToTime($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 .= sprintf($hh ? "%02d:%02d" : "%d:%02d", $mm, $ss);
  return $output;
}