icingaweb2/library/Icinga/Web/View/helpers/format.php

50 lines
1.6 KiB
PHP
Raw Normal View History

<?php
/* Icinga Web 2 | (c) 2013-2015 Icinga Development Team | http://www.gnu.org/licenses/gpl-2.0.txt */
namespace Icinga\Web\View;
use Icinga\Web\Url;
use Icinga\Util\Format;
$this->addHelperFunction('format', function () {
return Format::getInstance();
});
$this->addHelperFunction('timeSince', function ($timestamp) {
return sprintf(
2014-06-27 23:37:39 +02:00
'<span class="timesince" title="%s">%s</span>',
date('Y-m-d H:i:s', $timestamp), // TODO: internationalized format
Format::timeSince($timestamp)
);
});
$this->addHelperFunction('prefixedTimeSince', function ($timestamp, $ucfirst = false) {
return sprintf(
2014-06-27 23:37:39 +02:00
'<span class="timesince" title="%s">%s</span>',
date('Y-m-d H:i:s', $timestamp), // TODO: internationalized format
Format::prefixedTimeSince($timestamp, $ucfirst)
);
});
$this->addHelperFunction('timeUntil', function ($timestamp) {
if (! $timestamp) return '';
return sprintf(
'<span class="timeuntil" title="%s">%s</span>',
date('Y-m-d H:i:s', $timestamp), // TODO: internationalized format
Format::timeUntil($timestamp)
);
});
$this->addHelperFunction('prefixedTimeUntil', function ($timestamp, $ucfirst = false) {
if (! $timestamp) return '';
return sprintf(
'<span class="timeuntil" title="%s">%s</span>',
date('Y-m-d H:i:s', $timestamp), // TODO: internationalized format
Format::prefixedTimeUntil($timestamp, $ucfirst)
);
});
$this->addHelperFunction('dateTimeRenderer', function ($dateTimeOrTimestamp, $future = false) {
return DateTimeRenderer::create($dateTimeOrTimestamp, $future);
});