From 7165e8de3c241a5189a264ef7095921f001a7b43 Mon Sep 17 00:00:00 2001 From: Julien Dephix Date: Thu, 16 Mar 2017 13:36:48 +0100 Subject: [PATCH] show build duration on Dashboard -> Latest Builds if a build is not pending then its duration will be displayed next to last updated time, with time units: 1h 28m 52s --- src/PHPCensor/Model/Build.php | 28 ++++++++++++++++++++- src/PHPCensor/View/Home/ajax-timeline.phtml | 11 ++++++-- src/PHPCensor/View/Home/index.phtml | 17 +++++++++---- src/PHPCensor/View/layout.phtml | 8 +++--- 4 files changed, 52 insertions(+), 12 deletions(-) diff --git a/src/PHPCensor/Model/Build.php b/src/PHPCensor/Model/Build.php index 0d3539db..5568a429 100644 --- a/src/PHPCensor/Model/Build.php +++ b/src/PHPCensor/Model/Build.php @@ -830,7 +830,7 @@ class Build extends Model if (empty($this->currentBuildPath)) { $buildDirectory = $this->getId() . '_' . substr(md5(microtime(true)), 0, 5); - $this->currentBuildPath = + $this->currentBuildPath = RUNTIME_DIR . 'builds' . DIRECTORY_SEPARATOR . @@ -883,6 +883,32 @@ class Build extends Model return $end->getTimestamp() - $start->getTimestamp(); } + /** + * get time a build has been running for in hour/minute/seconds format (e.g. 1h 21m 45s) + * @return string + */ + public function getPrettyDuration() + { + $start = $this->getStarted(); + if (!$start) { + $start = new \DateTime(); + } + $end = $this->getFinished(); + if (!$end) { + $end = new \DateTime(); + } + + $diff = date_diff($start, $end); + $parts = []; + foreach (['y', 'm', 'd', 'h', 'i', 's'] as $time_part) { + if ($diff->{$time_part} != 0) { + $parts[] = $diff->{$time_part} . ($time_part == 'i' ? 'm' : $time_part); + } + } + + return implode(" ", $parts); + } + /** * Create a working copy by cloning, copying, or similar. * diff --git a/src/PHPCensor/View/Home/ajax-timeline.phtml b/src/PHPCensor/View/Home/ajax-timeline.phtml index 3c808490..e2144337 100644 --- a/src/PHPCensor/View/Home/ajax-timeline.phtml +++ b/src/PHPCensor/View/Home/ajax-timeline.phtml @@ -48,7 +48,14 @@
  • - format('H:i:s'); ?> + + format('H:i:s'); + if ($build->getStatus() != \PHPCensor\Model\Build::STATUS_PENDING) { + echo ' (' . $build->getPrettyDuration() . ')'; + } + ?> +

    getProject()->getTitle(); ?> @@ -62,7 +69,7 @@

    - getProject()->getBranch(); ?> - + getProject()->getBranch(); ?> - getCommitId() !== 'Manual') { print sprintf( diff --git a/src/PHPCensor/View/Home/index.phtml b/src/PHPCensor/View/Home/index.phtml index 085f49f7..5ceecd2c 100644 --- a/src/PHPCensor/View/Home/index.phtml +++ b/src/PHPCensor/View/Home/index.phtml @@ -63,9 +63,9 @@ if ($updated->format('Y-m-d') != $last->format('Y-m-d')): $last = $updated; ?>
  • - - format('Y-m-d'); ?> - + + format('Y-m-d'); ?> +
  • @@ -74,7 +74,14 @@
  • - format('H:i:s'); ?> + + format('H:i:s'); + if ($build->getStatus() != \PHPCensor\Model\Build::STATUS_PENDING) { + echo ' (' . $build->getPrettyDuration() . ')'; + } + ?> +

    getProject()->getTitle(); ?> @@ -88,7 +95,7 @@

    - getProject()->getBranch(); ?> - + getProject()->getBranch(); ?> - getCommitId() !== 'Manual') { print sprintf( diff --git a/src/PHPCensor/View/layout.phtml b/src/PHPCensor/View/layout.phtml index 19cddb47..8dc09c5a 100644 --- a/src/PHPCensor/View/layout.phtml +++ b/src/PHPCensor/View/layout.phtml @@ -170,7 +170,7 @@ - +
      @@ -183,10 +183,10 @@
    - +
  • - +
  • @@ -249,7 +249,7 @@ - +