简体   繁体   中英

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:

  • 1st monday of month: pizza
  • 2nd monday of month: pasta
  • 3rd monday of month: hamburger
  • 4th monday of month: beef
  • 5th monday of month: soup
  • 1st tuesday of month: fish and chips
  • 2nd tuesday of month: potatos
  • 3rd tuesday of month: ...

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.

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> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM