views:

133

answers:

1

By looking at the code I've provided below, does anyone know why the repeat is not consistent throughout each month? What I mean by this is for the first month that displays up until the end, the repeat works fine, then towards the end of the month onwards, the repeat is not displaying correctly. The output of the below code can be seen here on jsbin just click preview.

 (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);

      var endmeeting = new Date(2010, 07, 06, 8, 00, 00);

      meeting.setDate((meeting.getDate() - meeting.getDay()) + 1);

      var newEnd = new Date(end);
      var maxEnd = new Date((newEnd.getFullYear() + 1), newEnd.getMonth(), newEnd.getDate());

      //==========Calculate Repeat===========//
      var oneDay = 1000 * 60 * 60 * 24;
      var date1 = meeting.getTime();
      var date2 = endmeeting.getTime();
      var difference = Math.abs(date1 - date2);
      var days = Math.abs(difference / oneDay);

      while (meeting <= maxEnd) {
            var endDate = new Date();
            endDate.setDate(meeting.getDate() + days);
            events.push({
                id: 2,
                title: "Monday Meeting",
                start: new Date(meeting.valueOf()),
                end: endDate,
                allDay: false
            });

            // increase by one week
            meeting.setDate(meeting.getDate() + 7);
        }

      callback(events);
    }
    $('#calendar').fullCalendar({
          header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,basicWeek,basicDay'
          },
          events: MyEvents
        });
    });

Edit -- I see what is wrong why this. If I put an "alert(endDate);" before "meeting.setDate(meeting.getDate() + 7);", I do see that it is giving me the correct "end" Date. The problem here is that once it gets to September and incoming months, the month will always stay on "August" but the dates are the correct dates for. So for example once it gets to "September 10", this will again be "August 10", "September 17" will be "August 17". Dates changes but not month. Any idea people?

A: 

Update -- here you can see the update and what I did to make the repeat consistent throughout each month. Just click the preview. I hope this will help whoever's stuck on this issue as well.

hersh