diff --git a/library/Icinga/Util/Format.php b/library/Icinga/Util/Format.php
index 2b4bf9fa3..33c7ebd83 100644
--- a/library/Icinga/Util/Format.php
+++ b/library/Icinga/Util/Format.php
@@ -101,32 +101,20 @@ class Format
return self::showHourMin($duration);
}
- protected static function showHourMin($sec, $returnPrefix = false)
+ protected static function showHourMin($sec, $includePrefix = false)
{
$min = floor($sec / 60);
if ($min < 60) {
- if ($returnPrefix) {
- return 'For';
- } else {
- return $min . 'm ' . ($sec % 60) . 's';
- }
+ return ($includePrefix ? t('for') . ' ' : '') . $min . 'm ' . ($sec % 60) . 's';
}
$hour = floor($min / 60);
if ($hour < 24) {
- if ($returnPrefix) {
- return 'Since';
- } else {
- return date('H:i', time() - $sec);
- }
- }
- if ($returnPrefix) {
- return 'For';
- } else {
- return floor($hour / 24) . 'd ' . ($hour % 24) . 'h';
+ return ($includePrefix ? t('since') . ' ' : '') . date('H:i', time() - $sec);
}
+ return ($includePrefix ? t('for') . ' ' : '') . floor($hour / 24) . 'd ' . ($hour % 24) . 'h';
}
- protected static function smartTimeDiff($diff, $timestamp, $returnPrefix = false)
+ protected static function smartTimeDiff($diff, $timestamp, $includePrefix = false)
{
if ($timestamp === null || $timestamp === false) {
return '-';
@@ -140,19 +128,11 @@ class Format
}
if (abs($diff) > 3600 * 24 * 3) {
if (date('Y') === date('Y', $timestamp)) {
- if ($returnPrefix) {
- return 'Since';
- } else {
- return date('d.m.', $timestamp);
- }
- }
- if ($returnPrefix) {
- return 'Since';
- } else {
- return date('m.Y', $timestamp);
+ return ($includePrefix ? t('since') . ' ' : '') . date('d.m.', $timestamp);
}
+ return ($includePrefix ? t('since') . ' ' : '') . date('m.Y', $timestamp);
}
- return $prefix . self::showHourMin(abs($diff), $returnPrefix);
+ return $prefix . self::showHourMin(abs($diff), $includePrefix);
}
public static function timeSince($timestamp)
@@ -160,9 +140,13 @@ class Format
return self::smartTimeDiff(time() - $timestamp, $timestamp);
}
- public static function timeSincePrefix($timestamp)
+ public static function prefixedTimeSince($timestamp, $ucfirst = false)
{
- return self::smartTimeDiff(time() - $timestamp, $timestamp, true);
+ $result = self::smartTimeDiff(time() - $timestamp, $timestamp, true);
+ if ($ucfirst) {
+ $result = ucfirst($result);
+ }
+ return $result;
}
public static function timeUntil($timestamp)
@@ -170,9 +154,13 @@ class Format
return self::smartTimeDiff($timestamp - time(), $timestamp);
}
- public static function timeUntilPrefix($timestamp)
+ public static function prefixedTimeUntil($timestamp, $ucfirst)
{
- return self::smartTimeDiff($timestamp - time(), $timestamp, true);
+ $result = self::smartTimeDiff($timestamp - time(), $timestamp, true);
+ if ($ucfirst) {
+ $result = ucfirst($result);
+ }
+ return $result;
}
protected static function formatForUnits($value, & $units, $base)
diff --git a/library/Icinga/Web/View/helpers/format.php b/library/Icinga/Web/View/helpers/format.php
index 01ec92ea5..60861e7ee 100644
--- a/library/Icinga/Web/View/helpers/format.php
+++ b/library/Icinga/Web/View/helpers/format.php
@@ -15,9 +15,9 @@ $this->addHelperFunction('timeSince', function ($timestamp) {
. '';
});
-$this->addHelperFunction('timeSincePrefix', function ($timestamp) {
+$this->addHelperFunction('prefixedTimeSince', function ($timestamp, $ucfirst = false) {
return ''
- . $this->translate(Format::timeSincePrefix($timestamp))
+ . Format::prefixedTimeSince($timestamp, $ucfirst)
. ' ';
});
@@ -28,9 +28,9 @@ $this->addHelperFunction('timeUntil', function ($timestamp) {
. '';
});
-$this->addHelperFunction('timeUntilPrefix', function ($timestamp) {
+$this->addHelperFunction('prefixedTimeUntil', function ($timestamp, $ucfirst = false) {
if (! $timestamp) return '';
return ''
- . $this->translate(Format::timeUntilPrefix($timestamp))
+ . Format::prefixedTimeUntil($timestamp, $ucfirst)
. '';
});
diff --git a/modules/monitoring/application/clicommands/ListCommand.php b/modules/monitoring/application/clicommands/ListCommand.php
index 15224cb1a..71bf1083f 100644
--- a/modules/monitoring/application/clicommands/ListCommand.php
+++ b/modules/monitoring/application/clicommands/ListCommand.php
@@ -295,8 +295,7 @@ class ListCommand extends Command
$leaf,
$screen->underline($row->service_description),
$screen->colorize($utils->objectStateFlags('service', $row) . $perf, 'lightblue'),
- strtolower(Format::timeSincePrefix($row->service_last_state_change)),
- Format::timeSince($row->service_last_state_change)
+ Format::prefixedTimeSince($row->service_last_state_change, true)
);
if ($this->isVerbose) {
$out .= $emptyLine . preg_replace(
diff --git a/modules/monitoring/application/views/scripts/list/hosts.phtml b/modules/monitoring/application/views/scripts/list/hosts.phtml
index 2f2ddf4d3..d12b11a73 100644
--- a/modules/monitoring/application/views/scripts/list/hosts.phtml
+++ b/modules/monitoring/application/views/scripts/list/hosts.phtml
@@ -78,7 +78,7 @@ if ($hosts->count() === 0) {
= ucfirst($helper->monitoringState($host, 'host')); ?>
Backend = $this->backendName; ?> -= $ps->is_currently_running === '1' ? sprintf('has been running with PID %d %s ', $ps->process_id, strtolower($this->timeSincePrefix($ps->program_start_time))) . $this->timeSince($ps->program_start_time) : 'is not running'; ?>. += $ps->is_currently_running === '1' ? sprintf('has been running with PID %d ', $ps->process_id) . $this->prefixedTimeSince($ps->program_start_time) : 'is not running'; ?>.
>
= $this->translate($this->util()->getHostStateName($object->host_state)) ?> - = $this->timeSincePrefix($object->host_last_state_change) ?> = $this->timeSince($object->host_last_state_change) ?> + = $this->prefixedTimeSince($object->host_last_state_change, true) ?> |
= $this->escape($object->host_name) ?>host_address && $object->host_address !== $object->host_name): ?> @@ -18,7 +18,7 @@ |
= $this->translate($this->util()->getServiceStateName($object->service_state)) ?> - = $this->timeSincePrefix($object->service_last_state_change) ?> = $this->timeSince($object->service_last_state_change) ?> + = $this->prefixedTimeSince($object->service_last_state_change, true) ?> |
= $this->translate('Service') ?>: = $this->escape($object->service_description) ?> |