ENHANCEMENT: clearer use of time

This commit is contained in:
Jeroen De Meerleer 2022-01-26 15:34:32 +01:00
parent 3e69582786
commit 3c5ef172b0
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
2 changed files with 11 additions and 7 deletions

View File

@ -54,23 +54,26 @@ class Twig
}
public function addFilters() {
$secondsToInterval = new TwigFilter('interval', function(int $time) {
$secondsToInterval = new TwigFilter('interval', function(int|float $time) {
$return = '';
$days = floor($time / (60 * 60 * 24));
$time -= $days * (60 * 60 * 24);
$return .= ($days != 0) ? "{$days}d " : '';
$hours = floor($time / (60 * 60));
$time -= $hours * (60 * 60);
$return .= ($hours != 0) ? "{$hours}h " : '';
$minutes = floor($time / 60);
$time -= $minutes * 60;
$return .= ($minutes != 0) ? "{$minutes}m " : '';
$seconds = floor($time);
$time -= $seconds;
$time = round($time, 3);
$return .= ($time != 0) ? "{$time}s " : '';
return "{$days}d {$hours}h {$minutes}m {$seconds}s";
return $return;
});
$this->environment->addFilter($secondsToInterval);
$parseTags = new TwigFilter('parsetags', function(string $text) {
$results = [];
preg_match_all('/\[([A-Za-z0-9 \-]+)\]/', $text, $results);
@ -82,6 +85,7 @@ class Twig
return $text;
});
$this->environment->addFilter($secondsToInterval);
$this->environment->addFilter($parseTags);
}

View File

@ -15,7 +15,7 @@
<button class="accordion-button{% if loop.index != 1 %} collapsed{% endif %}" type="button" data-bs-toggle="collapse" data-bs-target="#run-{{ run.id }}" aria-expanded="{% if loop.index != 1 %}true{% else %}false{% endif %}" aria-controls="run-{{ run.id }}">
<div>
<div class="d-md-inline d-block text-left">{{ run.timestamp | date("d/m/Y H:i:s") }}</div>
<div class="d-md-inline d-block text-left">(exit code: {{ run.exitcode }} | runtime: {{ run.runtime | format_number({fraction_digit: 3}) }})</div>
<div class="d-md-inline d-block text-left">(exit code: {{ run.exitcode }} | runtime: {{ run.runtime | interval }})</div>
{% if 'M' in run.flags %}
<div class="d-md-inline d-block text-left">Manual Run</div>
{% endif %}