diff --git a/views/components/_utils.njk b/views/components/_utils.njk new file mode 100644 index 0000000..7bb2b17 --- /dev/null +++ b/views/components/_utils.njk @@ -0,0 +1,32 @@ +{% 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 %} \ No newline at end of file diff --git a/views/pages/mapSingle.njk b/views/pages/mapSingle.njk index c03091e..4b0b424 100644 --- a/views/pages/mapSingle.njk +++ b/views/pages/mapSingle.njk @@ -1,5 +1,6 @@ {% extends "../templates/basic.njk" %} {% import "../components/_map.njk" as mapComponent %} +{% import "../components/_utils.njk" as utils %} {% set map = data.map %} {% set raceLeaderboard = data.raceLeaderboard %} {% set teamLeaderboard = data.teamLeaderboard %} @@ -114,14 +115,7 @@

{{ record.rank }}.

{{ record.player }}

-

- {{ (record.time - (record.time % 60)) / 60 }}: - {%- if record.time | round % 60 > 9 %} - {{- record.time | round % 60 }} - {%- else -%} - 0{{- record.time | round % 60 }} - {%- endif %} -

+

{{ utils.fancyTime(record.time) }}

{% endfor %}