I've written some code for entering recurring events. The trickiest part is a user can create an event and have it repeat on selected days of the week ever x weeks.
For example, the user can select Mon,Wed,Fri and have it repeat every 3 weeks.
Easy to do if every week- I can do something like this:
$start = new DateTime( '2013-10-01' );
$end = new DateTime( '2014-01-01 23:59:59' );
$interval = new DateInterval('P1D');
$period = new DatePeriod($start, $interval, $end);
foreach ($period as $date) {
$dayOfWeek = $date->format('l');
if ($dayOfWeek == 'Monday' || $dayOfWeek == 'Wednesday' || $dayOfWeek == 'Wednesday') {
// do something
}
}
For the above code, how would I modify it to include Mon/Wed/Fri every 3 weeks? Is there a better way to achieve this without looping through every day?
I'm thinking I can use $date->format('w'); which would give me the numeric week of the year. I could then have a counter and reset it.