<commit_before>from datetime import time

from django.utils.safestring import mark_safe
from django.utils.translation import ugettext as _
from django import template


register = template.Library()

@register.filter
def sec_to_time(sec):
    """ Converts seconds to a time object

    >>> t = sec_to_time(1000)
    >>> (t.hour, t.minute, t.second)
    (0, 16, 40)
    """

    s = int(sec)
    hour = int(s / 60 / 60)
    minute = int((s / 60) % 60)
    sec = int(s % 60 )
    return time(hour, minute, sec)


@register.filter
@mark_safe
def format_duration(sec):
    """ Converts seconds into a duration string

    >>> format_duration(1000)
    '0h 16m 40s'

    """
    hours = int(sec / 60 / 60)
    minutes = int((sec / 60) % 60)
    seconds = int(sec % 60)
    return _('{h}h {m}m {s}s').format(h=hours, m=minutes, s=seconds)<commit_msg>Format short durations without "0 hours"<commit_after>from datetime import time

from django.utils.safestring import mark_safe
from django.utils.translation import ugettext as _
from django import template


register = template.Library()

@register.filter
def sec_to_time(sec):
    """ Converts seconds to a time object

    >>> t = sec_to_time(1000)
    >>> (t.hour, t.minute, t.second)
    (0, 16, 40)
    """

    s = int(sec)
    hour = int(s / 60 / 60)
    minute = int((s / 60) % 60)
    sec = int(s % 60 )
    return time(hour, minute, sec)


@register.filter
@mark_safe
def format_duration(sec):
    """ Converts seconds into a duration string

    >>> format_duration(1000)
    '16m 40s'

    >>> format_duration(10009)
    '2h 46m 49s'
    """
    hours = int(sec / 60 / 60)
    minutes = int((sec / 60) % 60)
    seconds = int(sec % 60)

    if hours:
        return _('{h}h {m}m {s}s').format(h=hours, m=minutes, s=seconds)
    else:
        return _('{m}m {s}s').format(m=minutes, s=seconds)
{'fraction_non_alphanumeric': 0.14123376623376624, 'fraction_numerical': 0.046536796536796536, 'mean_word_length': 2.9593147751605997, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6863022', 'n_tokens_mistral': 736, 'n_tokens_neox': 641, 'n_words': 182}