Simplified timediffmin filter
This commit is contained in:
parent
80204a3583
commit
49f92dcdef
|
@ -2,29 +2,9 @@
|
|||
|
||||
require_once("../vendor/autoload.php");
|
||||
|
||||
function timeago() {
|
||||
return new \Twig\TwigFilter('timeago', function ($ago, $now) {
|
||||
|
||||
$time = strtotime($now) - strtotime($ago);
|
||||
|
||||
$units = array (
|
||||
31536000 => 'year',
|
||||
2592000 => 'month',
|
||||
604800 => 'week',
|
||||
86400 => 'day',
|
||||
3600 => 'hour',
|
||||
60 => 'minute',
|
||||
1 => 'second'
|
||||
);
|
||||
|
||||
foreach ($units as $unit => $val) {
|
||||
if ($time < $unit) continue;
|
||||
$numberOfUnits = floor($time / $unit);
|
||||
return ($val == 'second')? 'a few seconds ago' :
|
||||
(($numberOfUnits > 1) ? $numberOfUnits : 'a')
|
||||
.' '.$val.(($numberOfUnits > 1) ? 's' : '').' ago';
|
||||
}
|
||||
|
||||
function timediffmin() {
|
||||
return new \Twig\TwigFilter('timediffmin', function ($ago, $now) {
|
||||
return round((strtotime($now) - strtotime($ago)) / 60);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ class UptimeStatus {
|
|||
|
||||
$loader = new \Twig\Loader\FilesystemLoader("../view/");
|
||||
$twig = new \Twig\Environment($loader, $twig_config);
|
||||
$twig->addFilter(\Filters\timeago());
|
||||
$twig->addFilter(\Filters\timediffmin());
|
||||
$twig->addFilter(\Filters\isof());
|
||||
|
||||
echo $twig->render('index.twig', $this->data);
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
{% endfor %}
|
||||
</div>
|
||||
<div class="time">
|
||||
<div>{{ (monitor.heartbeats | first).time | timeago((monitor.heartbeats | last).time) }}</div>
|
||||
<div>{{ (monitor.heartbeats | first).time | timediffmin((monitor.heartbeats | last).time) }} min</div>
|
||||
<div>now</div>
|
||||
</div>
|
||||
</div>
|
Loading…
Reference in a new issue