Format a duration value in seconds to a readable form.
558933
def fmt_duration(duration):
    
    try:
        return fmt.human_duration(float(duration), 0, 2, True)
    except (ValueError, TypeError):
        return "N/A".rjust(len(fmt.human_duration(0, 0, 2, True)))
1205018
def pprint(self, seconds):
        
        return ("%d:%02d:%02d.%03d", reduce(lambda ll, b: divmod(ll[0], b) + ll[1:], [(seconds * 1000,), 1000, 60, 60]))
1234423
def format_seconds(seconds, hide_seconds=False):
    
    if seconds <= 60:
        return str(seconds)
    output = ""
    for period, period_seconds in (
        ('y', 31557600),
        ('d', 86400),
        ('h', 3600),
        ('m', 60),
        ('s', 1),
    ):
        if seconds >= period_seconds and not (hide_seconds and period == 's'):
            output += str(int(seconds / period_seconds))
            output += period
            output += " "
            seconds = seconds % period_seconds
    return output.strip()
1342838
def seconds_to_hms_verbose(t):
    
    hours = int((t / 3600))
    mins = int((t / 60) % 60)
    secs = int(t % 60)
    return ' '.join([
        (hours + ' hour' + ('s' if hours > 1 else '')) if hours > 0 else '',
        (mins + ' minute' + ('s' if mins > 1 else '')) if mins > 0 else '',
        (secs + ' second' + ('s' if secs > 1 else '')) if secs > 0 else ''
    ])
216659
def seconds_to_hms(seconds):
    
    hours = int(seconds / 3600.0)
    minutes = int((seconds / 60.0) % 60.0)
    secs = float(seconds % 60.0)
    return "{0:02d}:{1:02d}:{2:02.6f}".format(hours, minutes, secs)
81301
def parse_duration(value: StrIntFloat) -> timedelta:
    
    if isinstance(value, timedelta):
        return value

    if isinstance(value, (int, float)):
        # bellow code requires a string
        value = str(value)

    match = standard_duration_re.match(value) or iso8601_duration_re.match(value)
    if not match:
        raise errors.DurationError()

    kw = match.groupdict()
    sign = -1 if kw.pop('sign', '+') == '-' else 1
    if kw.get('microseconds'):
        kw['microseconds'] = kw['microseconds'].ljust(6, '0')

    if kw.get('seconds') and kw.get('microseconds') and kw['seconds'].startswith('-'):
        kw['microseconds'] = '-' + kw['microseconds']

    kw_ = {k: float(v) for k, v in kw.items() if v is not None}

    return sign * timedelta(**kw_)
21197
def parse_seconds(value):
        '''
        
        '''
        svalue = str(value)
        colons = svalue.count(':')
        if colons == 2:
            hours, minutes, seconds = [int(v) for v in svalue.split(':')]
        elif colons == 1:
            hours, minutes = [int(v) for v in svalue.split(':')]
            seconds = 0
        elif colons == 0:
            hours = 0
            minutes = 0
            seconds = int(svalue)
        else:
            raise ValueError('Must be in seconds or HH:MM:SS format')
        return Seconds.from_hms(hours, minutes, seconds)
113491
def format_time(seconds):
    """"""
    minute = 60
    hour = minute * 60
    day = hour * 24
    week = day * 7

    result = []
    for name, dur in [
            ('week', week), ('day', day), ('hour', hour),
            ('minute', minute), ('second', 1)
    ]:
        if seconds > dur:
            value = seconds // dur
            result.append(
                '{0} {1}{2}'.format(int(value), name, 's' if value > 1 else '')
            )
            seconds = seconds % dur
    return ' '.join(result)
601783
def convert_timeval(seconds_since_epoch):
    """"""
    frac, whole = math.modf(seconds_since_epoch)
    microseconds = math.floor(frac * 1000000)
    seconds = math.floor(whole)
    return seconds, microseconds
1142915
def _x_format(self):
        """"""

        def timedelta_to_str(x):
            td = timedelta(seconds=x)
            return self.x_value_formatter(td)

        return timedelta_to_str
1154196
def timedelta_to_duration(obj):
    
    minutes, hours, days = 0, 0, 0
    seconds = int(obj.total_seconds())
    if seconds > 59:
        minutes = seconds // 60
        seconds = seconds % 60
    if minutes > 59:
        hours = minutes // 60
        minutes = minutes % 60
    if hours > 23:
        days = hours // 24
        hours = hours % 24
    response = []
    if days:
        response.append('%sd' % days)
    if hours:
        response.append('%sh' % hours)
    if minutes:
        response.append('%sm' % minutes)
    if seconds or not response:
        response.append('%ss' % seconds)
    return "".join(response)
395443
def formatDuration( value, option = "hours" )
      option = "hours" if option.nil?
      if value.nil?
         value = ""
      else   
         seconds = (value.to_i/1000)
         minutes = (seconds/60)
         hours = (minutes/60)
         days = (hours/24)
         if option == "days"
            value = days.to_s
         elsif option == "hours"
            value = hours.to_s
         elsif option == "minutes"
            value = minutes.to_s
         end
      end
      value
   end
1150486
def time(self):
        

        def format_response(value):
            """Format a TIME response into a datetime.datetime

            :param list value: TIME response is a list of the number
                of seconds since the epoch and the number of micros
                as two byte strings
            :rtype: float

            """
            seconds, micros = value
            return float(seconds) + (float(micros) / 1000000.0)

        return self._execute([b'TIME'], format_callback=format_response)
1316487
def duration(seconds):
    """"""
    if seconds < 1:
        return 'less than 1 sec'
    seconds = int(round(seconds))
    components = []
    for magnitude, label in ((3600, 'hr'), (60, 'min'), (1, 'sec')):
        if seconds >= magnitude:
            components.append('{} {}'.format(seconds // magnitude, label))
            seconds %= magnitude
    return ' '.join(components)
506515
def toStringDuration (duration):
    

    table = (
        ('%dms'      , 1e-3, 1e3),
        (u'%d\u03BCs', 1e-6, 1e6),
        ('%dns'      , 1e-9, 1e9)
    )

    if duration > 1:
        return '%fs' % duration

    for format, threshold, factor in table:
        if duration > threshold:
            return format % int(duration * factor)

    return '%fs' % duration
840135
def humanize_time(secs):
    
    if secs is None:
        return '--'

    if secs < 1:
        return "{:.2f}ms".format(secs*1000)
    elif secs < 10:
        return "{:.2f}s".format(secs)
    else:
        mins, secs = divmod(secs, 60)
        hours, mins = divmod(mins, 60)
        return '{:02d}:{:02d}:{:02d}'.format(int(hours), int(mins), int(secs))
136362
def humanize_duration(duration):
    
    days = duration.days
    hours = int(duration.seconds / 3600)
    minutes = int(duration.seconds % 3600 / 60)
    seconds = int(duration.seconds % 3600 % 60)

    parts = []
    if days > 0:
        parts.append(u'%s %s' % (days, pluralize(days, _('day,days'))))

    if hours > 0:
        parts.append(u'%s %s' % (hours, pluralize(hours, _('hour,hours'))))

    if minutes > 0:
        parts.append(u'%s %s' % (minutes, pluralize(minutes, _('minute,minutes'))))

    if seconds > 0:
        parts.append(u'%s %s' % (seconds, pluralize(seconds, _('second,seconds'))))

    return ', '.join(parts) if len(parts) != 0 else _('< 1 second')