dateRange function
Generates a range of dates from start to end inclusive, stepping by stepDays days.
Audited: 2026-06-12 11:26 EDT
Implementation
Iterable<DateTime> dateRange(DateTime start, DateTime end, {int stepDays = 1}) sync* {
if (stepDays <= 0) return;
final DateTime startDate = DateTime(start.year, start.month, start.day);
final DateTime endDate = DateTime(end.year, end.month, end.day);
DateTime current = startDate;
while (!current.isAfter(endDate)) {
yield current;
// Step by calendar day, not by Duration, so each result stays at local midnight
// across DST changes. Day overflow is meant to roll into the next month or year.
// ignore: saropa_lints/avoid_datetime_constructor, saropa_lints/avoid_datetime_constructor_unvalidated -- steps stepDays (guarded > 0) calendar days from a valid DateTime; rollover is intended; the result lands in a local
current = DateTime(current.year, current.month, current.day + stepDays);
}
}