get_timedelta_str

    Returns:
        str: timedelta_str, formated time string

    References:
        http://stackoverflow.com/questions/8906926/formatting-python-timedelta-objects

    Example:
        >>> # ENABLE_DOCTEST
        >>> from utool.util_time import *  # NOQA
        >>> timedelta = get_unix_timedelta(10)
        >>> timedelta_str = get_timedelta_str(timedelta)
        >>> result = (timedelta_str)
        >>> print(result)
        10 seconds

def get_timedelta_str(timedelta, exclude_zeros=False):
    """
    get_timedelta_str

    Returns:
        str: timedelta_str, formated time string

    References:
        http://stackoverflow.com/questions/8906926/formatting-python-timedelta-objects

    Example:
        >>> # ENABLE_DOCTEST
        >>> from utool.util_time import *  # NOQA
        >>> timedelta = get_unix_timedelta(10)
        >>> timedelta_str = get_timedelta_str(timedelta)
        >>> result = (timedelta_str)
        >>> print(result)
        10 seconds
    """
    if timedelta == datetime.timedelta(0):
        return '0 seconds'
    days = timedelta.days
    hours, rem = divmod(timedelta.seconds, 3600)
    minutes, seconds = divmod(rem, 60)
    fmtstr_list = []
    fmtdict = {}

    def append_cases(unit, fmtlbl):
        if not exclude_zeros or unit != 0:
            if unit == 1:
                fmtstr_list.append('{%s} %s' % (fmtlbl, fmtlbl))
            else:
                fmtstr_list.append('{%s} %ss' % (fmtlbl, fmtlbl))
            fmtdict[fmtlbl] = unit

    if abs(days) > 0:
        append_cases(days, 'day')
    if len(fmtstr_list) > 0 or abs(hours) > 0:
        append_cases(hours, 'hour')
    if len(fmtstr_list) > 0 or abs(minutes) > 0:
        append_cases(minutes, 'minute')
    if len(fmtstr_list) > 0 or abs(seconds) > 0:
        append_cases(seconds, 'second')
    fmtstr = ' '.join(fmtstr_list)
    timedelta_str = fmtstr.format(**fmtdict)
    return timedelta_str