calculateStartDifference static method

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

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

If first and second overlap:

  • If the first period starts before the second period, the period will be from the start of the first period to the start of the second period.
  • If the first period starts after the second period, the period will be from the start of the second period to the start of the first period.
  • If both periods start at the same time, null will be returned.

If first and second do not overlap, the period that occurs before the other will be returned (whichever period starts first chronologically).

Implementation

static Period? calculateStartDifference(Period first, Period second) {
  if (first.overlapsWith(second)) {
    if (first.startsBefore(second.start)) {
      return Period(start: first.start, end: second.start);
    }
    if (first.startsAfter(second.start)) {
      return Period(start: second.start, end: first.start);
    }
    return null;
  }
  if (first.occursBefore(second)) return first;
  return second;
}