-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathFuncaoDeIntervalo
23 lines (19 loc) · 1004 Bytes
/
FuncaoDeIntervalo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
var horainicial = "8:00:00";
var intervaloFormato = "0:00:05";
var intervaloSplit = intervaloFormato.split(':');
var intervaloSegundos = parseInt(intervaloSplit[0]) * 3600 + parseInt(intervaloSplit[1]) * 60 + parseInt(intervaloSplit[2]);
var data = new Date();
var horas = data.getHours();
var minutos = data.getMinutes();
var segundos = data.getSeconds();
var horaminutosegundo = horas.toString().padStart(2, '0') + ':' + minutos.toString().padStart(2, '0') + ':' + segundos.toString().padStart(2, '0');
var horainicialSplit = horainicial.split(':');
var horaInicialEmSegundos = parseInt(horainicialSplit[0]) * 3600 + parseInt(horainicialSplit[1]) * 60 + parseInt(horainicialSplit[2]);
var horaAtualEmSegundos = horas * 3600 + minutos * 60 + segundos;
var diferenca = horaAtualEmSegundos - horaInicialEmSegundos;
var ciclos = Math.floor(diferenca / intervaloSegundos);
if (ciclos % 2 === 0) {
node.send([{ payload: "ligado" }, null])
} else {
node.send([null, { payload: "desligado" }])
}