lastDayOfWeek static method
Returns start of the last day of the week for specified dateTime.
For example: (2020, 4, 9, 15, 16) -> (2020, 4, 12, 0, 0, 0, 0).
You can define first weekday (Monday, Sunday or Saturday) with
parameter firstWeekday. It should be one of the constant values
DateTime.monday, ..., DateTime.sunday.
By default it's DateTime.monday, so the last day will be DateTime.sunday.
Implementation
static DateTime lastDayOfWeek(DateTime dateTime, {int? firstWeekday}) {
assert(firstWeekday == null || firstWeekday > 0 && firstWeekday < 8);
var days = (firstWeekday ?? DateTime.monday) - 1 - dateTime.weekday;
if (days < 0) days += DateTime.daysPerWeek;
return _date(
dateTime.isUtc, dateTime.year, dateTime.month, dateTime.day + days);
}