I am trying to create a page that grabs a set of PDFs sorted by date. I can't seem to increment the date correctly. I'm not sure what's going wrong here. I rewrote the code twice now. No luck.
The current issue is that the set variables for the date do not keep the value of the date as a whole. IE incrementing from 12, 31, 2018, or in the case of the URL format 20181231, should result urlIncremented=20190101. January 1st, 2019, but the result of my code is urlIncremented=20181232.
The end result of one loop if set to June 8th 2018, should be: url20180608
I've searched for advice on here, and found a JS file called Date.JS; I've imported it and it was looking promising but just consoles out a part of its code, namely:
function () {
   if (this._isSecond) {
        this._isSecond=false;
        return this;
   }
   if (this._same) {
        this._same=this._is=false;
        var o1=this.toObject(),
            o2=(arguments[0] || new Date()).toObject(), 
            v="",
            k=j.toLowerCase();
        for (var m=(px.length-1); m>-1; m--) { 
            v=px[m].toLowerCase();
            if (o1[v]!=o2[v]) { 
                return false;
            }
            if (k==v) { 
                break;
            }
        }
        return true;
   }
   if (j.substring(j.length-1)!="s") { 
       j+="s";
   }
   return this["add"+j](this._orient);
}
Just a heads up I do not yet know jQuery, I was just playing with it to see if it would help..
Here is my actual code.
 let url = "blank",
        firstRun = true;
    
    /* 
    function setDateByIncrement(currentSetDate){
      let newDate,
          currentDate = new Date(),
          day = currentDate.getDate()+1,
          month = currentDate.getMonth() + 1,
          year = currentDate.getFullYear();
    
      console.log(newDate);
      newDate = (year+month+day);
      console.log(newDate);
      return newDate;
    }
    */
    
    // use on First run to set the url and date.
    //3
    function setURL(){
      let urlIncremented = url + dateIncrementMethod();
      return urlIncremented;
    }
    
    // will open x number of new windows containing URL
    //2
    function grabOpenPDF(maxNumberDays){
      let urlSet = setURL();
      
      //Set the variable for max days.
      for(let x = 0; x < maxNumberDays; x++){
        //window.open(urlSet);
        console.log("It works: " + x);
        urlSet = setURL();
      }
    }
    
    /* TODO Add automatic download for MASS print.
    function downloadPDF(){
      
    }
    */
    
    //Starts the task. 
    //1
    function start(load){
      console.log("Current Address: " + url);
      if(load === 1){
        console.log("Event load active. ");
        let maxDay = document.querySelector('#maxNumberDays').value;;
        grabOpenPDF(maxDay);
      }else{
        console.log("Event load skip. ")
        let maxDay = document.getElementById('maxNumberDays').value;
        
      }
    }
    
    //4
    function dateIncrementMethod(current){
      let dateIncrement;
      if(firstRun=== true){
        var today = new Date($('#date-input').val());
        console.log("FirstRun check in 4. ")
      }
      firstRun = false;
      
      var tomorrow = today.add(1).day;
      console.log(tomorrow);
      
      return tomorrow;
    }
      /* Possibly Deprecated  
      //let dateIncrement;
          let date = new Date($('#date-input').val());
          console.log(date);
          day = date.getDate() + 1;
      if(firstRun === true){
          month = date.getMonth() + 1;
          year = date.getFullYear();
          //dateIncrement = (parseToAPI(year, month, day));
          firstRun = false;
          parseToAPI(year, month, day);
        }else{
          day = date.getDate()+1;
          parseToAPI(year, month, day);
        }
    }
    */
    function parseToAPI(year, month, day){
      let apiDate;
      console.log("Entered parse");
      this.day = day;
      this.month = month;
      let d = this.day.toString(),
          m = this.month.toString();
          if(d.length === 1){
            console.log("Entered First IF");
            this.day = ('0') + day;
            //console.log(day);
          }
          if(m.length === 1){
            console.log("Entered Second IF")
            this.month = ('0') + month;
          }
      apiDate = (year + "" + "" + month + "" + day);
      console.log(apiDate);
      return apiDate;
    }<!DOCTYPE html>
<html>
<script src="https://code.jquery.com/jquery-2.0.3.js"></script>
<script src="https://doc-0k-6g-docs.googleusercontent.com/docs/securesc/77gdpvi38k94jj7nmfcm2n3tq7a0ifhu/ehjuusajghqnne5r2ncfvj30cmbll20p/1545105600000/17500114768188980350/17500114768188980350/1CDff-uWGahZX7aLt6WQfV1-R5PFHwiK8?e=download&nonce=52qkphatg2scm&user=17500114768188980350&hash=3uc9iql9m90vcrv3a7mhg8fdjce1b4fe.js"></script>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>JS Bin</title>
</head>
<body>
    <input type="date" id="date-input" required />
        <input type="maxNumberDays" id="maxNumberDays" max="31" required />
        <button id="startPDFApp" onClick="start()">Print PDFs</button>
        <button id="startPDFApp" onClick="start(1)">Load PDFs</button>
        <div id="info"></div>
    </body>
</html> 
     
     
     
    