def duration_string(sec):
    """Formats a time interval to a readable string"""
    sec = float(int(sec))
    if sec > 60 * 60 * 24:
        return "%.1f days" % (sec / float(60 * 60 * 24))
    if sec > 60 * 60:
        return "%.1f hours" % (sec / float(60 * 60))
    if sec > 60:
        return "%.1f minutes" % (sec / float(60))
    return "%d seconds" % sec