firstDayOfWeek method
Returns a new DateTime
on Monday of the current week.
Implementation
static DateTime firstDayOfWeek(DateTime day, [bool startOnMonday = 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 works from Sunday - Monday
int sub = startOnMonday ? (day.weekday % 7) - 1 : day.weekday % 7;
return day.subtract(new Duration(days: sub));
}