Error generating date range with js

0

I have the following code to get a range of dates and send to my PHP function (which is ok already):

    function calcular(){
        var quantidade = document.getElementById('qnt').value;
        var inicio = document.getElementById('inicio').value;
        var fim = document.getElementById('fim').value;
        var total = (((Date.parse(fim)) - (Date.parse(inicio))) / (24 * 60 * 60 * 1000));
        total++;//para incluir o primeiro dia    
        document.getElementById('dias').innerHTML=(total)+" dias<br>";
        qtd = quantidade/total;
        document.getElementById('entrevistas').innerHTML=(qtd)+" entrevistas p/ dia<br>";
    
        inicio = new Date(Date.parse(inicio));    
    
        for(i=1;i<=total;i++)    {
            var dia = new Date();
            dia.setDate(inicio.getDate()+i);
            document.getElementById('resultado').innerHTML += "<input type='checkbox' checked onclick='redivide()' name='dias' value='"+dia+"'>"+(dia.getDate())+"/"+(dia.getMonth()+1)+"/"+dia.getFullYear()+"<br>";            
        }
       
        document.getElementById('resultado').innerHTML += "<input type='button' onclick='envia()' value='Salvar'><div id='resultado2'></div>";       
    
    }
    
    function redivide(){
        var checks = document.getElementsByName('dias');
        var total=0;
        for(i=0;i<checks.length;i++){
            if(checks[i].checked){
                total++;
            }
        }
        var quantidade = document.getElementById('qnt').value;
        document.getElementById('entrevistas').innerHTML=(quantidade/total)+" entrevistas p/ dia<br>";
        
        }
    
    function envia(){
        var checks = document.getElementsByName('dias');
        var vetor_datas = []; var j=0;
        for(i=0;i<checks.length;i++){
            if(checks[i].checked){
                vetor_datas[j] = checks[i].value;
                j++;
            }
        }
        document.getElementById('resultado2').innerHTML = vetor_datas;
    }
    <!DOCTYPE html>
    <html lang="pt-br">
    <head> 
       
       <meta charset="utf-8">
    </head>
    
    
    <body>
        Início <input type="date" id="inicio" value="2018-10-10">
        Fim <input type="date" id="fim" value="2018-10-15">
        Quantidade <input type='number' id="qnt" value='300'>
        <input type="button" value="Calcular" onclick="calcular()"><br>
        <div id='dias'></div>
        <div id='entrevistas'></div>
        <div id="resultado"></div>
    </body>
    </html>

My problem:

When I try to generate for a range that starts on the first day of the month, it gives error in the script. I tried to pack here but I could not. The interesting thing is that it works for the other dates (the beginning of the interval is not the first day of the month).

    
asked by anonymous 20.11.2018 / 12:33

0 answers