You are here

function _emvideo_convert_to_seconds in Embedded Media Field 6

Same name and namespace in other branches
  1. 6.3 contrib/emvideo/emvideo.theme.inc \_emvideo_convert_to_seconds()
  2. 6.2 contrib/emvideo/emvideo.theme.inc \_emvideo_convert_to_seconds()

Convert time from field into seconds.

Parameters

$time: Raw timemarker input from field.

1 call to _emvideo_convert_to_seconds()
emvideo_convert_to_seconds in contrib/emvideo/emvideo.module

File

contrib/emvideo/emvideo.theme.inc, line 348
This defines the various theme functions for Embedded Video Field (emvideo).

Code

function _emvideo_convert_to_seconds($time) {
  $time_in_seconds = 0;
  $time_split = split(':', $time);
  $count = count($time_split);

  // If it is already in seconds then don't do anything.
  if ($count == 1) {
    return intval($time);
  }
  foreach ($time_split as $unit) {
    $count--;

    // If hours or minutes multiply by appropriate amount.
    if ($count > 0) {

      // If it is hours multiply by 36000 if minutes multiply by 60.
      $time_in_seconds += $unit * pow(60, $count);
    }
    else {

      // If we are on the seconds unit then we do not need to do anything.
      $time_in_seconds += $unit;
    }
  }
  return $time_in_seconds;
}