ddstats-server/views/components/_utils.njk

32 lines
948 B
Plaintext

{% macro fancyTime(inputSecs) %}
{% set seconds = inputSecs | round(0, "floor") %}
{% set hourSecs = seconds % 3600 %}
{% set hours = (seconds - hourSecs) / 3600 %}
{% set minSecs = (seconds - hours * 3600) % 60 %}
{% set mins = (seconds - hours * 3600 - minSecs) / 60 %}
{% set secsMillis = (inputSecs - hours * 3600 - mins * 60) | round(2) | float %}
{% set secs = secsMillis | round(0, "floor") %}
{% set millis = ((secsMillis - (secsMillis | round(0, "floor"))) * 100) | round(2) %}
{%- if hours -%}
{{- hours -}}:
{%- endif -%}
{%- if mins < 10 -%}
0{{- mins -}}:
{%- elif mins > 9 -%}
{{- mins -}}:
{%- endif -%}
{%- if secs < 10 -%}
0{{- secs -}}.
{%- elif secs > 9 -%}
{{- secs -}}.
{%- endif -%}
{%- if millis < 10 -%}
0{{- millis -}}
{%- elif millis > 9 -%}
{{- millis -}}
{%- endif -%}
{% endmacro %}