{% macro format_duration(seconds) -%}
{% if seconds > 3600 %}
{{ (seconds / 3600) | round(3) }}h
{% elif seconds > 60 %}
{{ (seconds / 60) | round(3) }}m
{% elif seconds > 0.5 %}
{{ seconds | round(3) }}s
{% else %}
{{ (seconds * 1000) | round(3) }}ms
{% endif %}
{%- endmacro %}

{% macro format_nanoseconds(nanoseconds) -%}
{% set seconds = nanoseconds / 1_000_000_000 %}
{% if seconds > 0.5 %}
{{ seconds | round(3) }}s
{% else %}
{{ (nanoseconds / 1_000_000) | round(3) }}ms
{% endif %}
{%- endmacro %}

{% macro scenario(duration, preamble='') -%}
<p class="primary-text no-margin semi-bold" style="display: inline; line-height: normal;"
    data-testid="scenario-duration">
    {{ preamble }} {{ format_duration(duration) }}
</p>
{%- endmacro %}

{% macro feature(duration, preamble='') -%}
<p class="secondary-text" style="text-align: right;" data-testid="feature-duration">
    {{ preamble }} {{ format_duration(duration) }}
</p>
{%- endmacro %}

{% macro step(duration, preamble='') -%}
<p class="no-margin" style="display: inline;" data-testid="step-duration">
    {{ preamble }} {{ format_nanoseconds(duration) }}
</p>
{%- endmacro %}

{% macro statistics(duration, preamble='') -%}
<p class="stat-value" data-testid="total-duration">
    {{ preamble }} {{ format_duration(duration) }}
</p>
{%- endmacro %}