public static function PHP_Timer::secondsToTimeString

Formats the elapsed time as a string.

Parameters

float $time:

Return value

string

2 calls to PHP_Timer::secondsToTimeString()
PHP_Timer::timeSinceStartOfRequest in drupal/core/vendor/phpunit/php-timer/PHP/Timer.php
Formats the elapsed time since the start of the request as a string.
PHP_TimerTest::testSecondsToTimeString in drupal/core/vendor/phpunit/php-timer/Tests/TimerTest.php
@covers PHP_Timer::secondsToTimeString

File

drupal/core/vendor/phpunit/php-timer/PHP/Timer.php, line 94

Class

PHP_Timer
Utility class for timing.

Code

public static function secondsToTimeString($time) {
  $buffer = '';
  $hours = sprintf('%02d', $time >= 3600 ? floor($time / 3600) : 0);
  $minutes = sprintf('%02d', $time >= 60 ? floor($time / 60) - 60 * $hours : 0);
  $seconds = sprintf('%02d', $time - 60 * 60 * $hours - 60 * $minutes);
  if ($hours == 0 && $minutes == 0) {
    $seconds = sprintf('%1d', $seconds);
    $buffer .= $seconds . ' second';
    if ($seconds != '1') {
      $buffer .= 's';
    }
  }
  else {
    if ($hours > 0) {
      $buffer = $hours . ':';
    }
    $buffer .= $minutes . ':' . $seconds;
  }
  return $buffer;
}