Skip to content

Instantly share code, notes, and snippets.

@petrusnog
Last active October 27, 2020 15:06
Show Gist options
  • Select an option

  • Save petrusnog/15229f84a83f7b9531c64e7ce92da6a1 to your computer and use it in GitHub Desktop.

Select an option

Save petrusnog/15229f84a83f7b9531c64e7ce92da6a1 to your computer and use it in GitHub Desktop.
Horário Bool - Função que retorna true ou false mediante o horário.
<?php
//
// Horário Bool - Função que retorna true ou false mediante o horário da requisição.
//
function horario_bool () {
$dias_da_semana = [
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday'
];
if ( in_array( date('l'), $dias_da_semana ) ) {
date_default_timezone_set('America/Fortaleza');
$horario_atual = new DateTime( date('H:i:s') );
$horario_inicio = new DateTime('08:00:00');
//Definindo intervalo de horas mediante dia da semana.
switch ( date('l') ) {
case 'Saturday' :
$horario_fim = new DateTime('12:00:00');
break;
default :
$horario_fim = new DateTime('16:00:00');
}
if ( $horario_atual >= $horario_inicio && $horario_atual <= $horario_fim ) {
return true;
} else {
return false;
}
} else {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment