def apply_uem_time(segments, times):
    """Using UEM start and final time, removes segments before and after, and splits if segment spans either start or final time."""
    new_segments, start, final = [], times[0], times[1]
    for [beg, dur, end, spkr] in segments:
        if start < beg and end < final:
            new_segments.append([beg, dur, end, spkr])
        elif beg < start < end and end < final:
            new_segments.append([start, end - start, end, spkr])
        elif start < beg and beg < final < end:
            new_segments.append([beg, final - beg, final, spkr])
        elif beg < start < end and beg < final < end:
            new_segments.append([start, final - start, final, spkr])
    return new_segments