trim method

List<Period> trim(
  1. List<Period> periods
)

Removes periods that do not overlap with this period and trims the ones that do overlap and are not fully contained by this period.

Implementation

List<Period> trim(List<Period> periods) {
  final localPeriods = [...periods];
  for (final period in [...periods]) {
    if (period.doesNotOverlapWith(this)) {
      localPeriods.remove(period);
    } else if (containsPartially(period)) {
      localPeriods
        ..remove(period)
        ..add(getIntersection(period)!);
    }
  }
  return localPeriods;
}