I'm building a sort of a calendar application in Laravel, PHP, Jquery. The user can set recurring events.
On daily events it's ok, they can choose the day of the week they want the event to happen. On Monthly events, also ok, they can choose the months that the event will reocurr.
On Weekly events, there is a problem: Since we don't really track weeks in the calendar, I can't really figure out how to make it recurr.
My first thought was to figure out the week of the month, and then let them choose which ones they want it to happen. Won't work because months have different number of weeks - some happen in 4 weeks, some in 5 and some (like this one) in 6 weeks. The code for getting the week of the month I'm using:
Date.prototype.getMonthWeek = function(){
var firstDay = new Date(this.getFullYear(), this.getMonth(), 1).getDay();
return Math.ceil((this.getDate() + firstDay)/7);
}
$("#result").html("Today is week " + new Date().getMonthWeek() );
Then my idea was to get even or odd weeks, from a specific date. This would limit me to set events to recurr every week or every two weeks but would work ok, until i figured the user can't really tell which week is even or odd aside from creating an event, testing if it reocurrs.
Then, getting the week of the year. Even weeks vs. odd weeks. But if the year has an odd number of weeks, it would happen twice in january.
I'm looking for the simplest way to make it happen and I'm really out of brainpower on this, any possible solutions?