union method

Interval union(
  1. Interval other
)

Implementation

Interval union(Interval other) {
  if (cross(other)) {
    if (end.isAfter(other.start) || end.isAtSameMomentAs(other.start)) {
      return Interval(start, other.end);
    } else if (other.end.isAfter(start) ||
        other.end.isAtSameMomentAs(start)) {
      return Interval(other.start, end);
    } else {
      throw RangeError('Error this: $this; other: $other');
    }
  } else {
    throw RangeError('Intervals don\'t cross');
  }
}