-2
    //Reset At Midnight
function resetAtMidnight() {
    var now = new Date();
    var night = new Date(
        now.getFullYear(),
        now.getMonth(),
        now.getDate() + 1, // the next day, ...
        0, 0, 0 // ...at 00:00:00 hours
    );
    var msToMidnight = night.getTime() - now.getTime();

    setTimeout(function() {
        reset();              //      <-- This is the function being called at midnight.
        resetAtMidnight();    //      Then, reset again next midnight.
    }, msToMidnight);
}


function reset() {
     $('#calendar').fullCalendar('today');
}     

I am trying to have FullCalendar.js update the current day everyday at midnight. I pulled this reset snippet from another post on here - but the reset function does not seem to execute.

John
  • 17
  • 3
  • Hi John, it's unclear what you're asking here, and you seem to be mixing libraries together (is this a jQuery question?). Maybe a more complete example of what you're trying to accomplish, perhaps with a [JSFiddle](http://jsfiddle.net/) would help other users understand your question. – Chaim Eliyah Jan 11 '19 at 23:17
  • Sorry I'm not sure what you're trying to achieve and why? Can you clarify? – ADyson Jan 14 '19 at 20:51

1 Answers1

0

You have not provided full detail so I don't know what exactly you need but following code might help you to solve your issue.

You can check midnight quite easily using moment.js library. Following code was taken from another post Best Way to detect midnight and reset data

$(document).ready(function() {
  var midnight = "0:00:00";
  var now = null;

  setInterval(function() {
    now = moment().format("H:mm:ss");
    if (now === midnight) {
      alert('reset() function here');
    }
    $("#time").text(now);
  }, 1000);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.23.0/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<code id="time"></code>

Fullcontrol:

You can either use rerenderEvents or refetchEvents as per your requirement. So it will be something like this

function reset(){
    $('#calendar').fullCalendar('rerenderEvents');
OR

    $('#calendar').fullCalendar('refetchEvents');
}

If you want to re-draw the fullcontrol then here is another informative post 're-draw fullcalendar'

As post suggested you can do

$('#calendar').fullCalendar('destroy');
$('#calendar').fullCalendar('render');
Ali Faraz
  • 31
  • 1
  • 5