def _get_intervals(start_event, end_events, messages, label):
    """
    Search messages for all [start_event,end_event] intervals. Return them as
    tuples of the form (start_timestamp, end_timestamp, label).
    """
    intervals = []

    # Return an empty list of intervals of messages is empty
    if not messages:
        return intervals

    # The name of a message's 'event' field depends on its class.
    attr_name = None
    sample_msg = messages[0]
    if sample_msg.__class__.__name__ == '_mrta__ExperimentEvent':
        attr_name = 'event'
    elif sample_msg.__class__.__name__ == '_mrta__TaskStatus':
        attr_name = 'status'
    else:
        # Should actually raise an error here
        print('Unrecognized message class: {0}'.format(sample_msg.__class__.__name__))
        return intervals

    last_start_stamp = None
    for message in messages:
        event = message.__getattribute__(attr_name)
        if event == start_event:
            last_start_stamp = message.header.stamp.secs + (message.header.stamp.nsecs/1000000000.)
            continue
        elif event in end_events:
            if not last_start_stamp:
                # print("count_interval_time(): {0} not preceded by {1}!".format(event, start_event))
                continue
            else:
                end_stamp = message.header.stamp.secs + (message.header.stamp.nsecs/1000000000.)
                intervals.append([last_start_stamp, end_stamp, label])
                last_start_stamp = None

    # print("total: {0}".format(interval_times))
    return intervals