isPeakTime method

bool isPeakTime(
  1. DateTime time
)

Whether or not the given time is considered peak time.

That is:

  • weekdays from opening to 9:30 AM as well as 3-7 PM
  • weekends from midnight to closing

Implementation

bool isPeakTime(DateTime time) {
  final bool isWeekend =
      time.day == DateTime.saturday || time.day == DateTime.sunday;

  if (isWeekend) {
    return true;
  }

  final bool isPeakMorning =
      time.hour < 9 || (time.hour == 9 && time.minute < 30);
  final bool isPeakEvening = time.hour >= 15 && time.hour < 19;

  return isPeakMorning || isPeakEvening;
}