Problema con funcion setInterval
Publicado por Carlos (2 intervenciones) el 09/10/2016 23:06:56
Buenos dias/tardes/noches... espero que todos se encuentren bien, me dirijo hoy a uds. a ver si por favor me pueden solucionar un problema con la funcion setInterval de JavaScript estoy haciendo un contador regresivo para una serie de eventos que ocurren en X dia de la semana, toda la funcionalidad del archivo js esta operativa menos la del setInterval, no encuentro en que lugar esta la falla y quisiera saber si alguno de uds. podria ayudarme... de antemano mil gracias.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
var horaEv, horas, minutos, segundos, tServidor, tEvento, timer;
var fecha = new Date();
function obtenerDia(){
var dia = fecha.getUTCDay();
return dia;
}
function obtenerHora(){
horas = fecha.getUTCHours();
minutos = fecha.getUTCMinutes();
segundos = fecha.getUTCSeconds();
horas -= 4;
}
function evento(horaEvento){
horaEv = horaEvento.split(":");
for(var i = 0; i < horaEv.length; i++){
horaEv[i] = parseInt(horaEv[i]);
}
}
function convertirASegundos(){
var tEspera;
tServidor = ((horas*3600) + (minutos*60)) + segundos;
tEvento = (horaEv[0]*3600) + (horaEv[1]*60) + horaEv[2];
tEspera = tEvento - tServidor;
return tEspera;
}
function evaluarTiempos(){
var eval;
if(tServidor > tEvento){
eval = false;
}
else{
eval = true;
}
return eval;
}
function tw(dia){
var bool, tEspera;
if(dia == 0){
evento('13:30:00');
tEspera = convertirASegundos();
bool = evaluarTiempos();
if(bool == false){
evento('17:00:00');
tEspera = convertirASegundos();
bool = evaluarTiempos();
if(bool == false){
evento('21:00:00');
tEspera = convertirASegundos();
bool = evaluarTiempos();
}
}
convertirAHoras(tEspera, "hora");
}
}
function cronograma(){
var dia = obtenerDia();
obtenerHora();
tw(dia);
timer = setInterval(tw, 1000);
}
function convertirAHoras(tiempo, contenedor){
var h, m, s, aux;
h = Math.trunc(tiempo/3600);
m = Math.trunc((tiempo - (h*3600))/60);
s = Math.trunc(tiempo - ((h*3600) + (m*60)));
document.getElementById(contenedor).textContent = h+":"+m+":"+s;
}
document.addEventListener("DOMContentLoaded", cronograma, false);
Valora esta pregunta


0