calculateEndDifference static method

Period? calculateEndDifference(
  1. Period first,
  2. Period second
)

Returns the period between the end of the first period and the end of the second period.

If first and second do not overlap, the period that occurs after will be returned.

If the first period ends after the second period, the period will be from the end of the second period to the end of the first period.

If the first period ends before the second period, the period will be from the end of the first period to the end of the second period.

If both periods end at the same time, null will be returned.

Implementation

static Period? calculateEndDifference(Period first, Period second) {
  if (first.overlapsWith(second)) {
    if (first.endsAfter(second.end)) {
      return Period(start: second.end, end: first.end);
    } else if (first.endsBefore(second.end)) {
      return Period(start: first.end, end: second.end);
    }
  } else {
    if (first.occursAfter(second)) return first;
    return second;
  }
  return null;
}