isSameWeek method

bool isSameWeek(
  1. DateTime b
)

Implementation

bool isSameWeek(DateTime b) {
  /// Handle Daylight Savings by setting hour to 12:00 Noon
  /// rather than the default of Midnight
  final a = DateTime.utc(year, month, day);
  b = DateTime.utc(b.year, b.month, b.day);

  final diff = a.toUtc().difference(b.toUtc()).inDays;
  if (diff.abs() >= 7) {
    return false;
  }

  final min = a.isBefore(b) ? a : b;
  final max = a.isBefore(b) ? b : a;
  final result = max.weekday % 7 - min.weekday % 7 >= 0;
  return result;
}