isSameWeek method

bool isSameWeek (DateTime a DateTime b)

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
  final normA = normalizeDate(a);
  final normB = normalizeDate(b);

  var diff = normA.difference(normB).inDays;
  if (diff.abs() >= 7) {
    return false;
  }

  var min = normA.isBefore(normB) ? normA : normB;
  var max = normA.isBefore(normB) ? normB : normA;

  return max.weekday % 7 - min.weekday % 7 >= 0;
}