matches method

bool matches(
  1. DateTime time
)

Whether time is an occurrence, to the minute.

Implementation

bool matches(DateTime time) {
  if (!_minutes.contains(time.minute)) return false;
  if (!_hours.contains(time.hour)) return false;
  if (!_months.contains(time.month)) return false;

  // Dart's Monday..Sunday is 1..7; cron's Sunday is 0.
  final int weekday = time.weekday == DateTime.sunday ? 0 : time.weekday;
  final bool domMatch = _daysOfMonth.contains(time.day);
  final bool dowMatch = _daysOfWeek.contains(weekday);

  // The rule people get wrong. When both day fields are restricted, cron
  // takes either -- `0 0 1 * MON` is the 1st OR a Monday. Read as an AND it
  // runs when the 1st happens to be a Monday, about once a year, which
  // looks like the scheduler being broken rather than the expression being
  // misread.
  if (dayOfMonthRestricted && dayOfWeekRestricted) {
    return domMatch || dowMatch;
  }
  return domMatch && dowMatch;
}