2014-03-17 17:14:16 +01:00
|
|
|
<?php
|
2016-02-08 15:41:00 +01:00
|
|
|
/* Icinga Web 2 | (c) 2014 Icinga Development Team | GPLv2+ */
|
2014-03-17 17:14:16 +01:00
|
|
|
|
|
|
|
namespace Icinga\Web\View;
|
|
|
|
|
2015-05-19 09:56:20 +02:00
|
|
|
use Icinga\Date\DateFormatter;
|
2014-03-17 17:14:16 +01:00
|
|
|
use Icinga\Util\Format;
|
|
|
|
|
|
|
|
$this->addHelperFunction('format', function () {
|
|
|
|
return Format::getInstance();
|
|
|
|
});
|
|
|
|
|
2015-05-19 10:10:23 +02:00
|
|
|
$this->addHelperFunction('formatDate', function ($date) {
|
|
|
|
if (! $date) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
return DateFormatter::formatDate($date);
|
|
|
|
});
|
|
|
|
|
|
|
|
$this->addHelperFunction('formatDateTime', function ($dateTime) {
|
|
|
|
if (! $dateTime) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
return DateFormatter::formatDateTime($dateTime);
|
|
|
|
});
|
|
|
|
|
2015-05-22 10:04:00 +02:00
|
|
|
$this->addHelperFunction('formatDuration', function ($seconds) {
|
|
|
|
if (! $seconds) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
return DateFormatter::formatDuration($seconds);
|
|
|
|
});
|
|
|
|
|
2015-05-19 10:10:23 +02:00
|
|
|
$this->addHelperFunction('formatTime', function ($time) {
|
|
|
|
if (! $time) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
return DateFormatter::formatTime($time);
|
|
|
|
});
|
|
|
|
|
2015-05-19 09:56:20 +02:00
|
|
|
$this->addHelperFunction('timeAgo', function ($time, $timeOnly = false) {
|
|
|
|
if (! $time) {
|
2015-05-18 14:40:55 +02:00
|
|
|
return '';
|
|
|
|
}
|
2014-06-20 12:28:55 +02:00
|
|
|
return sprintf(
|
2015-10-28 10:41:22 +01:00
|
|
|
'<span class="relative-time time-ago" title="%s">%s</span>',
|
2015-05-19 13:25:57 +02:00
|
|
|
DateFormatter::formatDateTime($time),
|
2015-05-19 09:56:20 +02:00
|
|
|
DateFormatter::timeAgo($time, $timeOnly)
|
2014-06-20 12:28:55 +02:00
|
|
|
);
|
2014-03-17 17:14:16 +01:00
|
|
|
});
|
|
|
|
|
2015-05-19 09:56:20 +02:00
|
|
|
$this->addHelperFunction('timeSince', function ($time, $timeOnly = false) {
|
|
|
|
if (! $time) {
|
2015-05-18 14:40:55 +02:00
|
|
|
return '';
|
|
|
|
}
|
2014-06-20 12:28:55 +02:00
|
|
|
return sprintf(
|
2015-10-28 10:41:22 +01:00
|
|
|
'<span class="relative-time time-since" title="%s">%s</span>',
|
2015-05-19 13:25:57 +02:00
|
|
|
DateFormatter::formatDateTime($time),
|
2015-05-19 09:56:20 +02:00
|
|
|
DateFormatter::timeSince($time, $timeOnly)
|
2014-06-20 12:28:55 +02:00
|
|
|
);
|
2014-05-29 11:26:02 +02:00
|
|
|
});
|
|
|
|
|
2019-07-11 13:03:04 +02:00
|
|
|
$this->addHelperFunction('timeUntil', function ($time, $timeOnly = false, $requireTime = false) {
|
2015-05-19 09:56:20 +02:00
|
|
|
if (! $time) {
|
2015-05-18 14:40:55 +02:00
|
|
|
return '';
|
|
|
|
}
|
2014-06-20 12:28:55 +02:00
|
|
|
return sprintf(
|
2015-10-28 10:41:22 +01:00
|
|
|
'<span class="relative-time time-until" title="%s">%s</span>',
|
2015-05-19 13:25:57 +02:00
|
|
|
DateFormatter::formatDateTime($time),
|
2019-07-11 13:03:04 +02:00
|
|
|
DateFormatter::timeUntil($time, $timeOnly, $requireTime)
|
2014-06-20 12:28:55 +02:00
|
|
|
);
|
2014-03-17 17:14:16 +01:00
|
|
|
});
|