Skip to content

Instantly share code, notes, and snippets.

@dantetesta
Last active May 25, 2022 12:08
Show Gist options
  • Select an option

  • Save dantetesta/0be22ef2752c83d57c985d8340a62d5c to your computer and use it in GitHub Desktop.

Select an option

Save dantetesta/0be22ef2752c83d57c985d8340a62d5c to your computer and use it in GitHub Desktop.
/*BY: ASK JARVIS + DANTE TESTA */
<script>
var dia_semana = new Date().toLocaleString('pt-BR', {weekday: 'short'}).replace('.', '');
var hora_atual_inicial = dia_semana+'-ini';
var hora_atual_final = dia_semana+'-fim';
var hora_inicial = jQuery('.'+hora_atual_inicial+' h2').text();
var hora_final = jQuery('.'+hora_atual_final+' h2').text();
var hora_corrente = getCurrentTime();
//alert(hora_inicial + hora_final + hora_corrente);
const isOpenText = document.querySelector('#isopen');
if (isOpen(hora_inicial, hora_final, hora_corrente)) {
isOpenText.innerHTML = 'ABERTO';
} else {
isOpenText.innerHTML = 'FECHADO';
}
function isOpen(start, end, current) {
const startTime = start.split(':');
const endTime = end.split(':');
const currentTime = current.split(':');
const startHour = parseInt(startTime[0]);
const startMinute = parseInt(startTime[1]);
const endHour = parseInt(endTime[0]);
const endMinute = parseInt(endTime[1]);
const currentHour = parseInt(currentTime[0]);
const currentMinute = parseInt(currentTime[1]);
if (currentHour >= startHour && currentHour <= endHour) {
if (currentHour === startHour && currentMinute < startMinute) {
return false;
} else if (currentHour === endHour && currentMinute > endMinute) {
return false;
} else {
return true;
}
} else {
return false;
}
}
function getCurrentTime() {
const date = new Date();
const hours = date.getHours();
const minutes = date.getMinutes();
return `${hours}:${minutes}`;
}
/* tire essa linha de comentário para ocultar os campos
jQuery(".horarios").css('display','none');
tire essa linha */
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment