lastDayOfWeek method
Returns a new DateTime
on Saturday of the current week.
Implementation
static DateTime lastDayOfWeek(DateTime day, [bool endOnSunday = false]) {
// Handle Daylight Savings by setting hour to 12:00 Noon
// rather than the default of Midnight
var normDay = normalizeDate(day);
// Weekday is on a 1-7 scale Monday - Sunday,
// This Calendar's Week starts on Sunday
final sub =
endOnSunday ? 6 - (normDay.weekday % 7) : 7 - (normDay.weekday % 7);
return normDay.add(Duration(days: sub));
}