Ver Mensaje Individual
  #2 (permalink)  
Antiguo 16/03/2015, 08:25
lavos
 
Fecha de Ingreso: noviembre-2009
Mensajes: 37
Antigüedad: 14 años, 5 meses
Puntos: 0
Respuesta: mejorar funcion cuenta horas habiles

ya lo solucione:
Código Javascript:
Ver original
  1. function calcularnombramiento(){
  2.     var inicinomb=document.getElementById('nombdesde').value;
  3.     var hoy = new Date(inicinomb);
  4.     var finnomb=document.getElementById('nombhasta').value;
  5.     var manana = new Date(finnomb);
  6.      var fechaformated=hoy.toLocaleFormat('%m/%d');
  7.     if(hoy.getDay() != 6 && hoy.getDay() != 0 && (estaarray(fechaformated) )){
  8.       i=1;    
  9.      }else{
  10.       i=0;  
  11.      }    
  12.     if(hoy.getDay() != 5 && hoy.getDay() != 6 && hoy.getDay() != 0 && estaarray(fechaformated) )){
  13.  
  14.      horahabil=9;
  15.      }else{
  16.      
  17.       horahabil=0;
  18.      }
  19.      
  20.       if(hoy.getDay() == 5 && hoy.getDay() != 6 && hoy.getDay() != 0 && (estaarray(fechaformated) )){
  21.    
  22.      horahabilv=8;
  23.      }else{
  24.  
  25.       horahabilv=0;
  26.      }
  27.    
  28.      
  29.     while (hoy<manana) {
  30.       hoy.setTime(hoy.getTime()+24*60*60*1000); // añadimos 1 día
  31.        var fechaformated=hoy.toLocaleFormat('%m/%d');
  32.       if (hoy.getDay() != 6 && hoy.getDay() != 0 && (estaarray(fechaformated))){
  33.         i++;
  34.     }
  35.     if (hoy.getDay() != 5 && hoy.getDay() != 6 && hoy.getDay() != 0 && (estaarray(fechaformated))){
  36.          horahabil+=9;
  37.     }
  38.     if (hoy.getDay() == 5 && hoy.getDay() != 6 && hoy.getDay() != 0 && (estaarray(fechaformated) )){
  39.           horahabilv+=8;
  40.     }
  41.         }
  42.         sumahorahabil=horahabil;
  43.         sumahorahabilv=horahabilv;  
  44.         total=sumahorahabilv+sumahorahabil;
  45.         document.getElementById('diasnomb').value=i;
  46.         document.getElementById('horasnomb').value=total;
  47.      }
Era solo evitar la multiplicacion de las horas por el dia