jQuery is JavaScript, it's a library with a set of features written in JavaScript.
I would do this on the server side in PHP. Because it is better to have HTML done when leaving the server and because the server always has the same internal time. If you do in JavaScript you need to know the time of the client (time zone) and adapt, it will give more work.
I leave an example in PHP. I created an array with a few days (you have to complete the rest). Then iterate this array where $i
is the day of the week to compare with date('w');
. You probably have to adjust the server time with your local time. You can do this here: $hora = intval(date('h')) +/- x horas;
.
Example:
$horario = array(
0 => array('weekday'=> 'Segunda', 'open'=>array(array(8, 14), array(16, 23))),
1 => array('weekday'=> 'Terça', 'open'=>array(array(8, 14), array(16, 23))),
2 => array('weekday'=> 'Quarta', 'open'=>array(array(8, 14), array(16, 23)))
);
$dia_semana = date('w');
$hora = intval(date('h'));
$status = 'Fechado';
$html = '<h3>Informações</h3>';
for($i = 0; $i < count($horario); $i++){
$dia = $horario[$i];
$html.= "<h4>".$dia['weekday']."</h4>";
foreach($dia['open'] as $horas){
if ($dia_semana == $i && $hora > $horas[0] && $hora < $horas[1]) $status = 'Aberto';
$html.= "<p>".$horas[0]." - ".$horas[1]."</p>";
}
}
$html.= "<p><strong>".$status."</strong></p>";
echo $html;
Example online: link