getSchedule method

  1. @override
List<DateTime> getSchedule(
  1. DateTime from,
  2. DateTime to, [
  3. int max = 100
])
override

An ordered list of timestamp generated by this trigger for a given period. This is mainly used for persistently scheduling a list of AppTasks from triggers that implement the Schedulable interface.

Implementation

@override
List<DateTime> getSchedule(DateTime from, DateTime to, [int max = 100]) {
  assert(to.isAfter(from));
  final List<DateTime> schedule = [];

  final startDay = DateTime(from.year, from.month, from.day);
  final toDay = DateTime(to.year, to.month, to.day);
  var day = startDay;
  var count = 0;

  while (day.isBefore(toDay) && count < max) {
    for (var time in samplingTimes) {
      final date = DateTime(
          day.year, day.month, day.day, time.hour, time.minute, time.second);
      if (date.isAfter(from) && date.isBefore(to)) schedule.add(date);
    }

    day = day.add(const Duration(days: 1));
    count++;
  }
  return schedule;
}