isSameWeek method
Whether or not two dates are in the same week
Implementation
static bool isSameWeek(DateTime a, DateTime b) {
// Handle Daylight Savings by setting hour to 12:00 Noon rather than the default of Midnight
a = new DateTime.utc(a.year, a.month, a.day, 12);
b = new DateTime.utc(b.year, b.month, b.day, 12);
var diff = a.difference(b).inDays;
if (diff.abs() >= 7) {
return false;
}
var min = a.isBefore(b) ? a : b;
var max = a.isBefore(b) ? b : a;
return max.weekday % 7 - min.weekday % 7 >= 0;
}