Merge pull request #3858 from Icinga/feature/downtime-schedule-times
Require time output for downtime schedule and end/expire times
This commit is contained in:
commit
40529e76ef
|
@ -149,12 +149,13 @@ class DateFormatter
|
|||
*
|
||||
* @param int|float $time
|
||||
* @param bool $timeOnly
|
||||
* @param bool $requireTime
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function timeAgo($time, $timeOnly = false)
|
||||
public static function timeAgo($time, $timeOnly = false, $requireTime = false)
|
||||
{
|
||||
list($type, $ago, $invert) = static::diff($time);
|
||||
list($type, $ago, $invert) = static::diff($time, $requireTime);
|
||||
if ($timeOnly) {
|
||||
return $ago;
|
||||
}
|
||||
|
@ -185,12 +186,13 @@ class DateFormatter
|
|||
*
|
||||
* @param int|float $time
|
||||
* @param bool $timeOnly
|
||||
* @param bool $requireTime
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function timeSince($time, $timeOnly = false)
|
||||
public static function timeSince($time, $timeOnly = false, $requireTime = false)
|
||||
{
|
||||
list($type, $since, $invert) = static::diff($time);
|
||||
list($type, $since, $invert) = static::diff($time, $requireTime);
|
||||
if ($timeOnly) {
|
||||
return $since;
|
||||
}
|
||||
|
|
|
@ -38,25 +38,25 @@ $this->addHelperFunction('formatTime', function ($time) {
|
|||
return DateFormatter::formatTime($time);
|
||||
});
|
||||
|
||||
$this->addHelperFunction('timeAgo', function ($time, $timeOnly = false) {
|
||||
$this->addHelperFunction('timeAgo', function ($time, $timeOnly = false, $requireTime = false) {
|
||||
if (! $time) {
|
||||
return '';
|
||||
}
|
||||
return sprintf(
|
||||
'<span class="relative-time time-ago" title="%s">%s</span>',
|
||||
DateFormatter::formatDateTime($time),
|
||||
DateFormatter::timeAgo($time, $timeOnly)
|
||||
DateFormatter::timeAgo($time, $timeOnly, $requireTime)
|
||||
);
|
||||
});
|
||||
|
||||
$this->addHelperFunction('timeSince', function ($time, $timeOnly = false) {
|
||||
$this->addHelperFunction('timeSince', function ($time, $timeOnly = false, $requireTime = false) {
|
||||
if (! $time) {
|
||||
return '';
|
||||
}
|
||||
return sprintf(
|
||||
'<span class="relative-time time-since" title="%s">%s</span>',
|
||||
DateFormatter::formatDateTime($time),
|
||||
DateFormatter::timeSince($time, $timeOnly)
|
||||
DateFormatter::timeSince($time, $timeOnly, $requireTime)
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
)) ?>
|
||||
</span>
|
||||
<?php if (! $downtime->is_in_effect && $downtime->start >= time()): ?>
|
||||
<span><?= sprintf($this->translate('expires %s'), $this->timeUntil($downtime->end, false, true)) ?></span>
|
||||
<span><?= sprintf($this->translate('expires %s'), $this->timeUntil($downtime->is_flexible ? $downtime->scheduled_end : $downtime->end, false, true)) ?></span>
|
||||
<?php endif ?>
|
||||
<span class="comment-icons">
|
||||
<?php if ($downtime->is_flexible): ?>
|
||||
|
|
|
@ -52,29 +52,21 @@ if (empty($object->comments) && ! $addLink) {
|
|||
if ((bool) $downtime->is_in_effect) {
|
||||
$state = sprintf(
|
||||
$this->translate('expires %s', 'Last format parameter represents the downtime expire time'),
|
||||
$this->timeUntil($downtime->end)
|
||||
$this->timeUntil($downtime->end, false, true)
|
||||
);
|
||||
} else {
|
||||
if ($downtime->start <= time()) {
|
||||
$state = sprintf(
|
||||
$this->translate('ends %s', 'Last format parameter represents the end time'),
|
||||
$this->timeUntil($downtime->is_flexible ? $downtime->scheduled_end : $downtime->end)
|
||||
$this->timeUntil($downtime->is_flexible ? $downtime->scheduled_end : $downtime->end, false, true)
|
||||
);
|
||||
} else {
|
||||
if ((bool) $downtime->is_fixed) {
|
||||
$state = sprintf(
|
||||
$this->translate('scheduled %s', 'Last format parameter represents the time scheduled'),
|
||||
$this->timeUntil($downtime->start, false, true)
|
||||
);
|
||||
} else {
|
||||
$state = sprintf(
|
||||
$this->translate('scheduled flexible %s', 'Last format parameter represents the time scheduled'),
|
||||
$this->timeUntil($downtime->start, false, true)
|
||||
);
|
||||
}
|
||||
$state .= ' ' . sprintf(
|
||||
$state = sprintf(
|
||||
$this->translate('scheduled %s', 'Last format parameter represents the time scheduled'),
|
||||
$this->timeUntil($downtime->start, false, true)
|
||||
) . ' ' . sprintf(
|
||||
$this->translate('expires %s', 'Last format parameter represents the downtime expire time'),
|
||||
$this->timeUntil($downtime->end, false, true)
|
||||
$this->timeUntil($downtime->is_flexible ? $downtime->scheduled_end : $downtime->end, false, true)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue