2014-03-17 17:14:16 +01:00
|
|
|
<?php
|
2015-02-04 10:46:36 +01:00
|
|
|
/* Icinga Web 2 | (c) 2013-2015 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-04-10 14:19:08 +02:00
|
|
|
'<span class="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-04-10 14:19:08 +02:00
|
|
|
'<span class="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
|
|
|
});
|
|
|
|
|
2015-05-19 09:56:20 +02:00
|
|
|
$this->addHelperFunction('timeUntil', 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-04-10 14:19:08 +02:00
|
|
|
'<span class="time-until" title="%s">%s</span>',
|
2015-05-19 13:25:57 +02:00
|
|
|
DateFormatter::formatDateTime($time),
|
2015-05-19 09:56:20 +02:00
|
|
|
DateFormatter::timeUntil($time, $timeOnly)
|
2014-06-20 12:28:55 +02:00
|
|
|
);
|
2014-03-17 17:14:16 +01:00
|
|
|
});
|