jQuery is Javascript, is a library with a set of features written in Javascript.
I would do that on the server side, in PHP. Because it is better to have HTML done when you leave the server and because the server always has the same internal time. If you do Javascript you need to know the client’s time (time zone) and adapt, it will take more work.
I leave an example in PHP. I created an array with a few days (you have to complete the rest). Then I’ll use this array where the $i
is the day of the week compared to date('w');
. You probably need 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;
jQuery is a library, not a language, Javascript is used on the client side, PHP is used on the server, so use PHP. You already have some code started?
– stderr
a logical problem in this is that it depends on the visitor’s browser. If the visitor’s PC is timed wrong, the messages will appear wrong. Another point is visitors from a different time zone. The safest is to get the date and time on the server itself and obviously the server adatetime must be correct and according to the local time zone..
– Daniel Omine