Reputation: 21
I'm using FullCalendar and Date.js to set up a weekly agenda. I'm also using the answer from fullCalendar jQuery, repeat every monday? for recurring events - but I'm struggling to convert these events to a specific time, rather than all day.
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
$('#calendar').fullCalendar({
defaultView: 'agendaWeek'
});
// adding a every monday and wednesday events:
$('#calendar').fullCalendar( 'addEventSource',
function(start, end, callback) {
// When requested, dynamically generate virtual
// events for every monday and wednesday.
var events = [];
for (loop = start.getTime();
loop <= end.getTime();
loop = loop + (24 * 60 * 60 * 1000)) {
var test_date = new Date(loop);
if (test_date.is().monday()) {
events.push({
title: 'Meeting',
start: test_date
});
}
} // for loop
// return events generated
callback( events );
}
);
I've tried changing the "if" to check for time as well with no luck and I've tried setting the time of the test_date variable, without success.
I appreciate the help.
Upvotes: 1
Views: 1078
Reputation: 21
Thanks, sulaiman, that was helpful. I also had to toss out date.js - it's no longer in development and many features are broken. Here's the full solution I reached.
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
$('#calendar').fullCalendar({
defaultView: 'agendaWeek',
defaultEventMinutes: 45,
editable: false
});
$('#calendar').fullCalendar( 'addEventSource',
function(start, end, callback) {
// When requested, dynamically generate virtual events for every monday and wednesday.
var events = [];
// checks every 30 minutes, rather than 24 hours
for (loop = start.getTime(); loop <= end.getTime(); loop = loop + (30 * 60 * 1000)) {
var test_date = new Date(loop);
if (test_date.getDay() === 1 && test_date.getHours() === 11 && test_date.getMinutes() === 30){
events.push({
title: 'Meeting',
start: test_date
allDay: false
});
}
} // for loop
// return events generated
callback( events );
}
);
Upvotes: 1
Reputation: 1845
You have to add allDay: false
if (test_date.is().monday()) {
events.push({
title: 'Meeting',
start: test_date,
allDay: false
});
}
Upvotes: 0