import bisect


def clip_around_detections(detections, time_interval):
    """Return the narrowest sublist of detections (a list of Detections)
    containing time_interval.

    """
    times = [d.timestamp for d in detections]
    lo = bisect.bisect(times, time_interval[0]) - 1
    hi = bisect.bisect_left(times, time_interval[1]) + 1
    return detections[lo:hi]