getDateTimeValues method
Returns a list of DateTime values that are contained in this Period.
The next function is used to calculate the DateTime values for the
returned list.
The next function is called with the last DateTime value, or start.
The next function must return a DateTime value that is contained in
this Period.
The next function must return a DateTime value that is not after the
end value of this Period.
When the next function returns null, the iteration stops.
Implementation
List<DateTime> getDateTimeValues(DateTime? Function(DateTime last) next) {
final dates = <DateTime>[];
var last = start;
while (endsAfter(last)) {
final nextDate = next(last);
if (nextDate == null) break;
if (contains(nextDate)) {
dates.add(nextDate);
last = dates.last;
} else {
throw ArgumentError.value(
nextDate,
'next',
'The next date must be contained in the period',
);
}
}
return dates;
}