'disable button while retrieving data from local storage and updating the date input

I am trying to implement a function that checks if the date and time I choose have already been chosen before, if so, it gives an error, if not it lets me carry on with adding the ticket. The current function does save options to local storage, however it looks like it doesn't retrieve them for me and allows me to choose the same date twice.

var count = 0;
function store() {

  let clickCounter = localStorage.getItem("clickCount");
  if (!clickCounter) {
    localStorage.setItem("clickCount", 0);
    clickCounter = "0";
  }
  clickCounter = parseInt(clickCounter);
  document.getElementById('inc').value = ++count;
  if (clickCounter == 100) {
    console.log("Limit reached");
    return;
  } else {
    localStorage.setItem("clickCount", clickCounter + 1);
  }
  console.log("Saving");
  var e = document.getElementById("time");
  var time = e.options[e.selectedIndex].text;
  var date = document.querySelector("input").value;

  localStorage.setItem(JSON.stringify(time), date);

  console.log(localStorage);
  if (!localStorage.getItem("history")) {
    localStorage.setItem("history", "[]");
  }
  const history = JSON.parse(localStorage.getItem("history"));
  history.push({ [JSON.stringify(time)]: date });
  localStorage.setItem("history", JSON.stringify(history));
  console.log(localStorage.getItem("history"));

}

function myDate(date) {

  var today = new Date();
  var newDate = new Date(date);
  var nextWeek = new Date();
  var pastWeek = new Date();
  nextWeek.setDate(nextWeek.getDate() + 7);
  pastWeek.setDate(pastWeek.getDate() - 7);
  const dateInput = document.getElementById('date');

  if (newDate < pastWeek || newDate > nextWeek) {
    document.getElementById("time").disabled = true;
    console.log("error")

    return;
  } else {
    document.getElementById("time").disabled = false;
  }
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source