function setEventDate($start_date, $recurrence){ $timestamp = strtotime($start_date); $day = date('w', $timestamp); //If the 'start date' is one of the set days if(in_array(($day+1), explode(',',$recurrence))){ return $start_date; } //else: (we need to change start date to first occurrence of one of the set days) $new_date = getTheNextAppointment($start_date, $recurrence); return $new_date; }
/** * __increment() * returns the next valid date for an event based on the * current day,month,year,freq and type * @private * @returns string YYYY-MM-DD */ function &__increment($d, $m, $y, $f, $t) { if ($t == REPEAT_EVERY_DAY) { return date('Y-m-d', mktime(0, 0, 0, $m, $d + $f, $y)); } elseif ($t == REPEAT_EVERY_WORK_DAY) { // a workday is defined as Mon,Tue,Wed,Thu,Fri // repeating on every or Nth work day means to not include // weekends (Sat/Sun) in the increment... tricky // ugh, a day-by-day loop seems necessary here, something where // we can check to see if the day is a Sat/Sun and increment // the frequency count so as to ignore the weekend. hmmmm.... $orig_freq = $f; for ($daycount = 1; $daycount <= $orig_freq; $daycount++) { $nextWorkDOW = date('w', mktime(0, 0, 0, $m, $d + $daycount, $y)); if (is_weekend_day($nextWorkDOW)) { $f++; } } // and finally make sure we haven't landed on a end week days // adjust as necessary $nextWorkDOW = date('w', mktime(0, 0, 0, $m, $d + $f, $y)); if (count($GLOBALS['weekend_days']) === 2) { if ($nextWorkDOW == $GLOBALS['weekend_days'][0]) { $f += 2; } elseif ($nextWorkDOW == $GLOBALS['weekend_days'][1]) { $f++; } } elseif (count($GLOBALS['weekend_days']) === 1 && $nextWorkDOW === $GLOBALS['weekend_days'][0]) { $f++; } return date('Y-m-d', mktime(0, 0, 0, $m, $d + $f, $y)); } elseif ($t == REPEAT_EVERY_WEEK) { return date('Y-m-d', mktime(0, 0, 0, $m, $d + 7 * $f, $y)); } elseif ($t == REPEAT_EVERY_MONTH) { return date('Y-m-d', mktime(0, 0, 0, $m + $f, $d, $y)); } elseif ($t == REPEAT_EVERY_YEAR) { return date('Y-m-d', mktime(0, 0, 0, $m, $d, $y + $f)); } elseif ($t == REPEAT_DAYS_EVERY_WEEK) { $old_appointment_date = date('Y-m-d', mktime(0, 0, 0, $m, $d, $y)); $next_appointment_date = getTheNextAppointment($old_appointment_date, $f); return $next_appointment_date; } }