mergeWith method

Period? mergeWith(
  1. Period other
)

Returns a Period that is the union of this and other.

If other overlaps with this, the returned Period will be the union of the two Periods. Starting at the earliest Period.start and ending at the latest Period.end.

If other does not overlap with this, the returned Period will be null.

Implementation

Period? mergeWith(Period other) {
  if (doesNotOverlapWith(other)) return null;
  return Period(
    start: start.isBefore(other.start) ? start : other.start,
    end: end.isAfter(other.end) ? end : other.end,
  );
}