I'm trying to figure out the best way to do the following:
If a user chooses a certain day, say June 21, 2010 we will repeat an event every 3rd monday of every month, but if they choose June 28, 2010 the event will repeat every last monday of every month. This is how google calendar does it, and I'm trying to repeat that functionality.
So basically I see it working something like this: Given a date, get the week it exists in, and the day it is on. (1st week, 2nd week, 3rd week, 4th week, and last week.) Obviously sometimes 4th week will be the last week, and if that is the case I'd like to default to last week.
so in psuedocode:
$repeatweek = getweeknumber($date);
$repeatday = date('l', strtotime($date));
$todaysweek = getweeknumber($todaysdate);
$todayday = date('l', strtotime($todaysdate));
if($todayday == $repeatday && $repeatweek == $todaysweek){
echo "This is the day";
}
So the trick I guess is to properly define the getweeknumber() function, which I'm having a heck of time with. Especially determining first and last weeks.