DurationRange constructor

DurationRange(
  1. Duration start,
  2. Duration stop, [
  3. Duration step = const Duration(seconds: 1)
])

Returns an iterable of integers from start inclusive to stop inclusive with step.

print(DurationRange(Duration(seconds: 10), Duration(seconds: 21), Duration(seconds: 2)));
=> [0:00:10.000000, 0:00:12.000000, 0:00:14.000000, 0:00:16.000000, 0:00:18.000000, 0:00:20.000000]

Implementation

factory DurationRange(Duration start, Duration stop,
    [Duration step = const Duration(seconds: 1)]) {
  if (step == Duration()) {
    throw ArgumentError.value(step, 'step', 'cannot be 0');
  }

  if (stop < start) {
    if (!step.isNegative) {
      step = -step;
    }
  } else {
    if (step.isNegative) {
      step = -step;
    }
  }
  return DurationRange._(start, stop, step);
}