2

I see the example for repeating events in the code but I'm confused as to how it works. How would I go about adding an event (adding events as an array for now) which occur every Monday at 4:30pm? I'm trying to use the basicWeek view.

Pranay Rana
  • 175,020
  • 35
  • 237
  • 263
user326649
  • 21
  • 1
  • 2
  • The answers here are now out of date. See http://stackoverflow.com/questions/15161654/recurring-events-in-fullcalendar – DanielST Aug 28 '15 at 16:02

2 Answers2

1

The event Model in fullCalendar doesn't support adding directly "repeating" events using the array event source.

What you need to do is use either an external feed (JSON URL) or use the javascript function to generate the events. Either way your "source" would have the logic to do repeating events and just full out all of the dates of the repeated events in the time range given..

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 a weekly repeat, you'll have to build the logic for any other repeat interval accordingly. Or find an existing class to manage repeating events.

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

Urkle
  • 1,520
  • 13
  • 12
0

I think you can use cookies for this :

Steps

  1. you create one cookie -- in which you set date time of the next monday(use the algo to get next monday date) document.cookie = 'ppkcookie1=DateTime; path=/'
  2. check that cookie is expire on the given date-- means after seven days
  3. if the cookie is not there create cookies by next monday date
  4. if the cookie is there than create compare date
  5. if date is less than the current date update value and fire the even you want
  6. To check the value of the cookie at specific interval use SetInterval function http://www.elated.com/articles/javascript-timers-with-settimeout-and-setinterval/

Following is 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);
}
Pranay Rana
  • 175,020
  • 35
  • 237
  • 263