diff --git a/lib/Framework/Twig.php b/lib/Framework/Twig.php index db791ec..2bbbfff 100644 --- a/lib/Framework/Twig.php +++ b/lib/Framework/Twig.php @@ -6,6 +6,7 @@ namespace JeroenED\Framework; use Twig\Environment; use Twig\Loader\FilesystemLoader; +use Twig\TwigFilter; use Twig\TwigFunction; class Twig @@ -19,6 +20,7 @@ class Twig $this->environment = new Environment($loader); $this->kernel = $kernel; $this->addFunctions(); + $this->addFilters(); } public function render(string $template, array $vars = []): string @@ -32,6 +34,28 @@ class Twig return $this->kernel->getRouter()->getUrlForRoute($route); }); $this->environment->addFunction($path); + } + public function addFilters() { + $secondsToInterval = new TwigFilter('interval', function(int $time) { + $days = floor($time / (60 * 60 * 24)); + $time -= $days * (60 * 60 * 24); + + $hours = floor($time / (60 * 60)); + $time -= $hours * (60 * 60); + + $minutes = floor($time / 60); + $time -= $minutes * 60; + + $seconds = floor($time); + $time -= $seconds; + + return "{$days}d {$hours}h {$minutes}m {$seconds}s"; + }); + $this->environment->addFilter($secondsToInterval); + } + + + } \ No newline at end of file diff --git a/templates/job/overview.html.twig b/templates/job/overview.html.twig index 42e82af..d46af73 100644 --- a/templates/job/overview.html.twig +++ b/templates/job/overview.html.twig @@ -20,8 +20,8 @@ {{ job.name }} {{ job.data.host }} - {{ job.delay }} - {{ job.nextrun }} + {{ job.delay | interval }} + {{ job.nextrun | date("d/m/Y H:i:s") }}