difference($start2); $form_values = array(); // Create the default case more frequently than case 1 or 2. $which = mt_rand(0, 10); $max_items = 10; $intervals = array_keys(INTERVAL_options()); unset($intervals[0]); $interval = $intervals[mt_rand(1, 3)]; switch ($which) { case 1: $mo = mt_rand(1, 28); $options = array('YEARLY', 'MONTHLY'); $freq = date_content_generate_key($options); $freq = $options[$freq]; $form_values['FREQ'] = $freq; // Make sure we'll find a match in our range. if ($freq == 'YEARLY') { $interval = 1; } $form_values['BYMONTHDAY'] = array($mo); break; case 2: $mo = mt_rand(1, 12); $options = array('YEARLY', 'MONTHLY'); $freq = date_content_generate_key($options); $freq = $options[$freq]; $form_values['FREQ'] = $freq; // Make sure we'll find a match in our range. if ($freq == 'YEARLY') { $interval = 1; } $form_values['BYMONTH'] = array($mo); break; default: $dows = array_keys(date_content_repeat_dow_options()); $day = date_content_generate_key($dows); $dow = $dows[$day]; $options = array('MONTHLY', 'DAILY', 'WEEKLY'); $freq = date_content_generate_key($options); $freq = $options[$freq]; $form_values['FREQ'] = $freq; $form_values['BYDAY'] = array($dow); break; } $form_values['INTERVAL'] = $interval; switch ($freq) { case 'YEARLY': $period = 'year'; break; case 'MONTHLY': $period = 'month'; break; case 'WEEKLY': $period = 'week'; break; default: $period = 'day'; break; } date_modify($start2, '+' . max(1, $forward) . ' years'); date_increment_round($start2, $increment); $until = date_format($start2, 'Y-m-d H:i:s'); $form_values['UNTIL'] = array('datetime' => $until, 'tz' => 'UTC'); $form_values['COUNT'] = $max_items; $rrule = date_api_ical_build_rrule($form_values); $values = date_repeat_build_dates($rrule, $form_values, $field, $entity_field); $start = $entity_field; $entity_field = array(0 => $start); $entity_field[0]['rrule'] = $rrule; $entity_field += $values; } return $entity_field; } function date_content_generate_key($array) { $keys = array_keys($array); $min = array_shift($keys); $max = array_pop($keys); return mt_rand($min, $max); } /** * Helper function for BYDAY options. * * Creates options like -1SU and 2TU * Omit options that won't find many matches, like 5th Sunday. */ function date_content_repeat_dow_options() { $options = array(); foreach (date_repeat_dow_count_options() as $count_key => $count_value) { foreach (date_repeat_dow_day_options() as $dow_key => $dow_value) { if ($count_key != 5 && $count_key != -5) { $options[$count_key . $dow_key] = $count_value . ' ' . $dow_value; } } } return $options; }