def time_to_str(sec):
    """Convert seconds to days, hours, minutes and seconds."""
    days, remainder = divmod(sec, 60 * 60 * 24)
    hours, remainder = divmod(remainder, 60 * 60)
    minutes, seconds = divmod(remainder, 60)
    _str = ""
    if days > 0:
        _str += "{:d} days, ".format(int(days))
    if hours > 0:
        _str += "{:d} hours, ".format(int(hours))
    if minutes > 0:
        _str += "{:d} minutes, ".format(int(minutes))
    _str += "{:d} seconds".format(int(seconds))
    return _str