From 1686ee4d73ea8a5a8c0db04c8a63906e7a2a8c13 Mon Sep 17 00:00:00 2001 From: Frank Bergkemper Date: Fri, 31 Oct 2014 11:44:26 +0000 Subject: [PATCH] Bugfix Issue #57 --- .../Application/View/Helper/Expiration.php | 8 ++-- .../View/Helper/HumanReadableTimeperiod.php | 37 ++++++++++--------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/module/Application/src/Application/View/Helper/Expiration.php b/module/Application/src/Application/View/Helper/Expiration.php index dd9ff046..0da5dd40 100644 --- a/module/Application/src/Application/View/Helper/Expiration.php +++ b/module/Application/src/Application/View/Helper/Expiration.php @@ -28,7 +28,7 @@ use Zend\View\Helper\AbstractHelper; /** - * + * */ class Expiration extends AbstractHelper { @@ -36,8 +36,8 @@ class Expiration extends AbstractHelper protected $result; /** - * @method - * @return string + * @method + * @return string * @param * @param */ @@ -59,7 +59,7 @@ public function __invoke($retention, $lastwritten, $volstatus) $d2 = mktime(0, 0, 0, (int)$t2[1],(int)$t2[2],(int)$t2[0]); $interval = ($d2 - $d1) / (3600 * 24); $retention = round(($retention / 60 / 60 / 24 ), 2, PHP_ROUND_HALF_EVEN); - $this->result = ($retention - $interval); + $this->result = round(($retention - $interval), 2, PHP_ROUND_HALF_EVEN); if($this->result <= 0) { return $this->result = "expired"; diff --git a/module/Application/src/Application/View/Helper/HumanReadableTimeperiod.php b/module/Application/src/Application/View/Helper/HumanReadableTimeperiod.php index 44c3c807..455ae44a 100644 --- a/module/Application/src/Application/View/Helper/HumanReadableTimeperiod.php +++ b/module/Application/src/Application/View/Helper/HumanReadableTimeperiod.php @@ -3,7 +3,7 @@ /** * * bareos-webui - Bareos Web-Frontend - * + * * @link https://github.com/bareos/bareos-webui for the canonical source repository * @copyright Copyright (c) 2013-2014 dass-IT GmbH (http://www.dass-it.de/) * @license GNU Affero General Public License (http://www.gnu.org/licenses/) @@ -28,7 +28,7 @@ use Zend\View\Helper\AbstractHelper; /** - * + * */ class HumanReadableTimeperiod extends AbstractHelper { @@ -37,8 +37,8 @@ class HumanReadableTimeperiod extends AbstractHelper /** * A function for making timeperiods human readable - * @method - * @return string + * @method + * @return string * @param * @param */ @@ -51,32 +51,32 @@ public function __invoke($time, $format="short") else { $this->result = "-"; - $dateTime = date_create($time); + $dateTime = date_create($time); $timestamp = date_format($dateTime, 'U'); $seconds = time() - $timestamp; if($format == "short") { $units = array( - 'y' => $seconds / 31556926 % 12, - 'w' => $seconds / 604800 % 52, + 'y' => $seconds / 31556926 % 12, + 'w' => $seconds / 604800 % 52, 'd' => $seconds / 86400 % 7, - 'h' => $seconds / 3600 % 24, - 'm' => $seconds / 60 % 60, + 'h' => $seconds / 3600 % 24, + 'm' => $seconds / 60 % 60, 's' => $seconds % 60 - ); + ); foreach($units as $key => $value) { if($value > 0) { $res[] = $value . $key; - } - } - + } + } + $this->result = join(' ', $res) . " ago"; - } + } elseif($format == "long") { - + $units = array( 'Year(s)' => $seconds / 31556926 % 12, 'Week(s)' => $seconds / 604800 % 52, @@ -90,8 +90,8 @@ public function __invoke($time, $format="short") if($value > 0) { $res[] = $value . $key; } - } - + } + $this->result = join(' ', $res) . " ago"; } @@ -109,6 +109,7 @@ public function __invoke($time, $format="short") return $this->result = "today"; } elseif($interval <= 31 && $interval >= 1) { + $interval = round($interval, 0, PHP_ROUND_HALF_UP); $this->result = "about " . $interval . " day(s) ago"; } elseif($interval >= 31 && $interval <= 365) { @@ -121,7 +122,7 @@ public function __invoke($time, $format="short") } } - + return $this->result; }