next static method

DateTime next(
  1. int day, [
  2. DateTime? from
])

Implementation

static DateTime next(int day, [DateTime? from]) {
  final current = from ?? DateTime.now();

  final weekday = current.weekday == DateTime.sunday ? 0 : current.weekday;

  final diff = day - weekday;

  final duration = Duration(days: (diff >= 0 ? 0 : 7) + diff);

  final that = current.add(duration);

  return DateTime(that.year, that.month, that.day);
}