Check if operating hours are in the chosen time range JQuery / Javascript [duplicate]

0

How can I check if the operating_table is within the selected range? Example: a bar works from 8:00 am to 1:00 p.m., a user chose the time interval from 12:00 to 9:00 p.m., how to check if this bar is open in that chosen time range?

var intervalo_escolhido = [12,21];
var horario_funcionamento = [08,13];
    
asked by anonymous 07.06.2018 / 20:16

2 answers

0

verificaHorario(7, 16);

function verificaHorario(horario_inicial, horario_final) {
  var horario_funcionamento = [08, 13];
  for (var horario = horario_inicial; horario <= horario_final; horario++) {
    if (horario < horario_funcionamento[0] || horario >= horario_funcionamento[1]) {
      alert("Horario indisponivel dentro do intervalo escolhido: " + horario);
    } else {
      alert("Horario disponivel dentro do intervalo escolhido: " + horario);
    }
  }
}

I hope you have understood the question and helped. If not, let me know that I'll try to help you again.

    
07.06.2018 / 21:07
0

Using this data you have placed you can check by the index of the arrays:

function VerificaRange(range){
  var horario_funcionamento = [08,13];
  if (range[0] >= horario_funcionamento[0] && range[1] <= horario_funcionamento[1]){
    return true;
  }
  else{
    return false;
  }      
}

var intervalo_escolhido = [12,21];
//return false;
var insideRange = VerificaRAnge(intervalo_escolhido);
    
07.06.2018 / 21:08