lastDayOfWeek method

DateTime lastDayOfWeek({
  1. bool startWeekOnMonday = true,
})

Return last day of the week

startWeekOnMonday - if true, first day of the week is Monday, otherwise Sunday

lastDayOfWeek - if true, last day of the week is Sunday, otherwise Saturday

Implementation

DateTime lastDayOfWeek({bool startWeekOnMonday = true}) {
  var lastDay = DateTime(year, month, day);
  while (lastDay.weekday != (startWeekOnMonday ? 7 : 1)) {
    lastDay = lastDay.add(const Duration(days: 1));
  }
  return lastDay;
}