/**
  * Returns a readable runtime
  *
  * @param $indexer
  * @return mixed
  */
 protected function getRuntime($indexer)
 {
     $dateTimeUtils = new DateTimeUtils();
     $startTime = new \DateTime($indexer->getStartedAt());
     $endTime = new \DateTime($indexer->getEndedAt());
     if ($startTime > $endTime) {
         return 'index not finished';
     }
     $lastRuntime = $dateTimeUtils->getDifferenceAsString($startTime, $endTime);
     return $lastRuntime;
 }
Exemple #2
0
 /**
  * Returns a readable string with time difference
  *
  * @param PhpDateTime $time1
  * @param PhpDateTime $time2
  *
  * @return string
  */
 public function getDifferenceAsString(PhpDateTime $time1, PhpDateTime $time2)
 {
     if ($time1 == $time2) {
         return '0';
     }
     $interval = $time1->diff($time2);
     $years = $interval->format('%y');
     $months = $interval->format('%m');
     $days = $interval->format('%d');
     $hours = $interval->format('%h');
     $minutes = $interval->format('%i');
     $seconds = $interval->format('%s');
     $differenceString = ($years ? $years . 'Y ' : '') . ($months ? $months . 'M ' : '') . ($days ? $days . 'd ' : '') . ($hours ? $hours . 'h ' : '') . ($minutes ? $minutes . 'm ' : '') . ($seconds ? $seconds . 's ' : '');
     return trim($differenceString);
 }