differenceBetween method

List<Period> differenceBetween(
  1. Period other
)

Returns a list of Periods that are the difference between this and other.

If other does not overlap with this, the returned list will contain both this and other.

If other overlaps with this, the returned list will contain the difference between the two. If both start at the same time, the returned list will contain the period between the two Period.end values. If both end at the same time, the returned list will contain the period between the two Period.start values.

If they are equal, the returned list will be empty.

Implementation

List<Period> differenceBetween(Period other) {
  if (doesNotOverlapWith(other)) return [this, other];
  final periods = <Period>[];
  final before = calculateStartDifference(other, this);
  if (before != null) periods.add(before);
  final after = calculateEndDifference(other, this);
  if (after != null) periods.add(after);
  return periods;
}