def make_trips_diary(valid_segments, missing_segments):
    """
    Zips together lists of valid segments and missing segments in timestamp order
    into continuous trip diary.
    """
    if not missing_segments:
        return valid_segments
    trips = []
    missing_iter = iter(missing_segments)
    missing_test_segment = next(missing_iter)
    trip_idx = 0
    missing_idxs = []
    for valid_segment in valid_segments:
        if not missing_test_segment:
            trips.append(valid_segment)
            trip_idx += 1
        elif missing_test_segment and valid_segment[0
            ].timestamp_UTC < missing_test_segment[0].timestamp_UTC:
            trips.append(valid_segment)
            trip_idx += 1
        else:
            trips.append(missing_test_segment)
            missing_idxs.append(trip_idx)
            trip_idx += 1
            trips.append(valid_segment)
            trip_idx += 1
            missing_test_segment = next(missing_iter, None)
    diary = {'trips': trips, 'missing': missing_idxs}
    return diary
