addWeekdaysBySkippingWeekends method

DateTime addWeekdaysBySkippingWeekends(
  1. int daysToAdd
)

Implementation

DateTime addWeekdaysBySkippingWeekends(int daysToAdd) {
  DateTime result = this;

  while (daysToAdd > 0) {
    result = result.add(const Duration(days: 1));
    if (result.weekday == DateTime.saturday ||
        result.weekday == DateTime.sunday) {
      continue; // Skip weekends
    }
    daysToAdd--;
  }

  return result;
}