invertRangesList static method

Iterable<EllaTimeRange> invertRangesList(
  1. List<EllaTimeRange> ranges
)

Implementation

static Iterable<EllaTimeRange> invertRangesList(List<EllaTimeRange> ranges) sync*
{
  if (ranges.isEmpty) {
    return;
  }

  if (ranges.first.begin.seconds > 0) {
    yield new EllaTimeRange(new EllaTime(0), ranges.first.begin);
  }

  for (int i = 1; i < ranges.length; i++)
  {
    EllaTimeRange lastRange = ranges[i - 1];
    EllaTimeRange currentRange = ranges[i];
    yield new EllaTimeRange(lastRange.end, currentRange.begin);
  }

  if (ranges.last.end.seconds < EllaTime.secondsPerDay) {
    yield new EllaTimeRange(ranges.last.end, new EllaTime(EllaTime.secondsPerDay));
  }
}