generateDayList method

  1. @useResult
List<DateTime> generateDayList(
  1. int days, {
  2. bool isStartOfDay = true,
})

Returns a list of DateTime objects for consecutive days.

Starts from this and generates days number of dates. If isStartOfDay is true (default), each date after the first is set to midnight; the first entry is always this, unchanged.

When isStartOfDay is false, each date keeps the wall-clock time of this. A day on which that time does not exist (a clock-change gap) gets the shifted time for that day only.

NOTE: returns an empty list when days is 0. Audited: 2026-06-12 11:26 EDT

Implementation

@useResult
List<DateTime> generateDayList(int days, {bool isStartOfDay = true}) {
  DateTime currentDate = this;

  return List<DateTime>.generate(
    days,
    (_) {
      final DateTime result = currentDate;
      // Midnight lists can chain, since truncation discards any shift. A
      // kept time of day must come from `this`: chaining it carried a
      // gap-shifted hour (02:30 -> 03:30) into every later day.
      if (isStartOfDay) {
        currentDate = result.nextDay();
      } else {
        currentDate = _nextDayAtTimeOf(this, result);
      }

      return result;
    },
  );
}