deste
deste

Reputation: 550

Fullcalendar jquery plugin recurring event day/week number in month

I'm trying to display the menu of a refectory by the plugin FullCalendar. The menu should be something like that:

etc..

I need to recurring event in this way.. But I don't know if it's possible and how implement it.. I'm so confused.

At the moment my code will look something like that:

var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();

$('#calendar').fullCalendar({
    events: [
        { start: new Date(y, m, 1), title: 'Pasta all\'olio e parmigiano' },
        { start: new Date(y, m, 2), title: 'Pasta all\'olio e parmigiano' },
        ...

Is there a way to set the correct date and recurring in Fullcalendar as I need, using javascript date() function, or by mixing with another technologies (PHP/MySQL..)?

Thanks in advance.

Upvotes: 0

Views: 3188

Answers (1)

Jan
Jan

Reputation: 1414

I think there are two options:

  1. Create a Google Calendar, which supports this kind of recurring events, and add it to fullcalendar as shown here:

    <script type='text/javascript' src='fullcalendar/gcal.js'></script>
    <script type='text/javascript'>
        $(document).ready(function() {
            $('#calendar').fullCalendar({
                events: 'http://www.google.com/your_feed_url/'
            });
        });
    </script>
    
  2. Calculate the event on dates your own, as fullcalendar doesn't support recurring events. You can use the datejs library as a little help:

    <script type='text/javascript' src='date.js'></script>
    <script type='text/javascript'>
        function getRecurrences(date, count) {
            var nthOccurence = Math.ceil((date.getDate() - date.getDay()) / 7),
                dates = [date];
    
            for(var i = 0; i < count; i++) {
                var nextDate = dates[dates.length - 1].clone().addMonths(1);
                nextDate.moveToNthOccurrence(date.getDay(), nthOccurence);
                dates.push(nextDate);
            }
    
            return dates;
        }
    
        var date = new Date(2013, 8, 18); // 3rd Wednesday
        var nextThreeOccurences = getRecurrences(date, 3);
    </script>
    

Upvotes: 1

Related Questions