calculateStartDifference static method
Returns the period between the start of the first period and the start
of the second period.
If first and second overlap:
- If the
firstperiod starts before thesecondperiod, the period will be from the start of thefirstperiod to the start of thesecondperiod. - If the
firstperiod starts after thesecondperiod, the period will be from the start of thesecondperiod to the start of thefirstperiod. - If both periods start at the same time,
nullwill 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;
}