Remove 00 for hours or Minutes when the actual duration is less than an hour for Time formatter

Created on 23 September 2023, over 1 year ago

Problem/Motivation

When using the Time formatter, it is currently displaying "00" for hours when the actual duration is less than an hour which can be misleading and unnecessary.

Steps to reproduce

Go to settings and set formatter to Time format

Twig Result :

<div class="field__item">

<!-- THEME DEBUG -->
<!-- THEME HOOK: 'duration_field_duration_time' -->
<!-- BEGIN OUTPUT from 'modules/contrib/duration_field/templates/duration-field-duration-time.html.twig' -->

00:48:09

<!-- END OUTPUT from 'modules/contrib/duration_field/templates/duration-field-duration-time.html.twig' -->

</div>
Feature request
Status

Active

Version

2.1

Component

Miscellaneous

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @yabikami
  • I fixed this in my theme by creating the file "duration-field-duration-time.html.twig" in my custom themes template folder (/web/themes/custom/mytheme/templates/duration-field-duration-time.html.twig).

    Use this content in your "duration-field-duration-time.html.twig" to only print hours when available:

    {% if year or month or day %}
    {{ year }}/{{ month }}/{{day}}
    {% endif %}
    
    {% if hour or minute or second %}
      {% if hour > 0 %}
        {{ hour }}:{{ minute }}:{{ second }}
      {% else %}
        {{ minute }}:{{ second }}
      {% endif %}
    {% endif %}
    
Production build 0.71.5 2024