How to add events that repeat on specific days of the week indefinitely with fullcalendar

I see an example of repetition events

in the code, but I don't understand how it works. How can I add an event (adding events

as an array at the moment) that happens every Monday at 4:30 pm? I am trying to use the basicWeek view.

+2


a source to share


2 answers


The event model in fullCalendar does not support adding "recurring" events directly using an array event source.

What you need to do is either use an external feed (JSON URL) or use a javascript function to generate events. In any case, your "source" will have logic to repeat events and simply fill in all dates of repeated events in the given time range.

For example using a Javascript function.



function MyEvents(start,end, callback) {
  var events = [];
  // Setup the meeting on the this weeks "monday"
  var meeting = new Date(start.getFullYear(),
                         start.getMonth(),
                         start.getDate(),
                         4, 30, 00);
  meeting.setDate((meeting.getDate() - meeting.getDay()) + 1);

  while (meeting <= end) {
    events.push({
      id: 2,
      title: "Monday Meeting",
      start: new Date(meeting.valueOf()),
      allDay: false
    });
    // increase by one week
    meeting.setDate(meeting.getDate() + 7);
  }
  callback(events);
}
$('#calendar').fullCalendar({
    //.... Other settings here
    events: MyEvents
    //....
});

      

This only handles the weekly retry, you will need to build logic for any other retry interval accordingly. Or find an existing class for handling recurring events.

To see this code in action, here is the jsbin link http://jsbin.com/usori3/edit

+1


a source


I think you can use cookies for this:

Steps

  • you create one cookie where you set the end date of next Monday (use algo to get next Monday date) document.cookie = "Ppkcookie1 = DateTime; path = / '
  • check that the cookie expires on a given date - means after seven days
  • If cookie does not create cookies by next Monday date
  • if the cookie exists than create a comparison date
  • if the date is less than the current version update the date and runs even the ones you want
  • To check the value of the cookie at a specific interval, use the SetInterval function http://www.elated.com/articles/javascript-timers-with-settimeout-and-setinterval/


Below is a sample code for cookies:

function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name,"",-1);
}

      

0


a source







All Articles