import _slicedToArray from '@babel/runtime/helpers/slicedToArray';

function isInTimeRange(_ref) {
  var daysOfWeek = _ref.daysOfWeek,
    start = _ref.start,
    end = _ref.end,
    _ref$now = _ref.now,
    now = _ref$now === void 0 ? new Date() : _ref$now;
  if (!Array.isArray(daysOfWeek) || daysOfWeek.length === 0 || !start || !end) {
    return false; // 没有定义有效的时间段
  }
  var dayOfWeek = now.getDay();
  var inTime = dayOfWeek === 0 && daysOfWeek.includes(7) || daysOfWeek.includes(dayOfWeek);
  if (!inTime) {
    return false; // 不在时间段内
  }
  var _start$split$map = start.split(':').map(Number),
    _start$split$map2 = _slicedToArray(_start$split$map, 2),
    startHour = _start$split$map2[0],
    startMinute = _start$split$map2[1];
  var _end$split$map = end.split(':').map(Number),
    _end$split$map2 = _slicedToArray(_end$split$map, 2),
    endHour = _end$split$map2[0],
    endMinute = _end$split$map2[1];
  if (isNaN(startHour) || isNaN(startMinute) || isNaN(endHour) || isNaN(endMinute)) {
    return false; // 非法时间格式
  }
  // 计算今天的凌晨时间
  var midnight = new Date(now.getFullYear(), now.getMonth(), now.getDate());
  // 计算开始时间与结束时间
  var startDate = new Date(midnight.getTime() + startHour * 60 * 60 * 1000 + startMinute * 60 * 1000);
  var endDate = new Date(midnight.getTime() + endHour * 60 * 60 * 1000 + endMinute * 60 * 1000);
  // 判断当前时间是否在指定时间段内
  var currentTime = now.getTime();
  if (currentTime >= startDate.getTime() && currentTime <= endDate.getTime()) {
    return true; // 当前在指定时间段内
  }
  return false; // 当前不在指定时间段内
}

export { isInTimeRange };
