until method

Iterable<DateTime> until(
  1. DateTime to, {
  2. Duration by = const Duration(days: 1),
})

Returns a lazy Iterable<DateTime> that contains all dates from this to to including this but excluding to.

The steps between the dates can be specified by setting by which defaults to one day.

See also rangeTo.

Example:

// all days of 2020 (2020/01/01 ... 2020/12/31);
DateTime(2020).until(DateTime(2021));

// all full hours of 2020/01/01
DateTime(2020, 1, 1).until(DateTime(2020, 1, 2), by: 1.hours);

Implementation

Iterable<DateTime> until(DateTime to,
    {Duration by = const Duration(days: 1)}) sync* {
  for (var date in rangeTo(to, by: by).withoutLast()) {
    yield date;
  }
}