DateInterval constructor

DateInterval({
  1. DateTime? startDate,
  2. DateTime? endDate,
  3. int period = 1,
  4. Intervals interval = Intervals.once,
  5. Iterable<DateTime>? skipDates,
  6. Iterable<int>? additionalDaysOfTheMonth,
})

Creates an instance of the DateInterval class. period must be greater than 0 or it will throw an ArgumentError.

Implementation

DateInterval({
  DateTime? startDate,
  DateTime? endDate,
  this.period = 1,
  this.interval = Intervals.once,
  Iterable<DateTime>? skipDates,
  Iterable<int>? additionalDaysOfTheMonth,
}) {
  if (period < 1) {
    throw ArgumentError.value(
        period, 'period', 'Period must be 1 or greater.');
  }

  if (skipDates != null) {
    this.skipDates.addAll(skipDates);
  }

  this.startDate = startDate == null
      ? DateTime.now().withZeroTime()
      : startDate.withZeroTime();
  this.endDate = endDate?.withZeroTime();

  for (final day in additionalDaysOfTheMonth ?? <int>[]) {
    if (day < 1 || day > 31) continue;
    if (additionalDates.contains(day) || day == startDate!.day) continue;

    additionalDates.add(day);
  }
}