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
day = new DateTime.utc(day.year, day.month, day.day, 12);
// Weekday is on a 1-7 scale Monday - Sunday,
// This Calendar's Week starts on Sunday
int sub = endOnSunday ? 6 - (day.weekday % 7) : 7 - (day.weekday % 7);
return day.add(new Duration(days: sub));
}