Hi,
Can someone point me in the direction of information about what the frequency codes in recurring event attributes mean (DED, DWE, DWD, DWE2, WEW, MRN etc).
I want to be able to set these via the Javascript API but have no idea what they map to.
TIA
Does this help?
[codebox] switch ($freq_type) {
case 'DED':
$periods_so_far = ceil(days_between_isos($after, $start) / $interval);
$result = add_days_to_iso($start, $interval * $periods_so_far);
break;
case 'DWD':
$periods_so_far = ceil(days_between_isos($after, $start) / $interval);
$result = add_days_to_iso($start, $interval * $periods_so_far);
while (in_array(date('D', iso8601_ts($result)), Array('Sat', 'Sun'))) {
$result = add_days_to_iso($result, 1);
}
break;
case 'DWE':
$periods_so_far = ceil(days_between_isos($after, $start) / $interval);
$result = add_days_to_iso($start, $interval * $periods_so_far);
while (!in_array(date('D', iso8601_ts($result)), Array('Sat', 'Sun'))) {
$result = add_days_to_iso($result, 1);
}
break;
case 'WEW':
$periods_so_far = ceil(days_between_isos($after, $start) / ($interval*7));
$result = add_days_to_iso($start, $interval * 7 * $periods_so_far);
break;
// Every 'x' months on the 'y'th day of the month
case 'MFN':
if (($month_diff % $interval) != 0) {
increment_month($res_month, $res_year, ($interval - ($month_diff % $interval)));
} else if ($res_day > $start_day) {
increment_month($res_month, $res_year, $interval);
}
while ($start_day > days_in_month($res_month, $res_year)) {
increment_month($res_month, $res_year, $interval);
}
$result = sprintf('%04d-%02d-%02d',$res_year,$res_month,$start_day);
break;
// Every 'x' months on the 'y'th weekday of the month (eg. 2nd Thursday)
case 'MFW':
$target_week_of_month = (int)(($start_day - 1) / 7);
$target_day_of_week = date('w', iso8601_ts($start));
$res_day = ($target_week_of_month * 7) + 1;
if (($month_diff % $interval) != 0) {
// go to the next valid month
increment_month($res_month, $res_year, $interval - ($month_diff % $interval));
} else if ((int)($after_day / 7) > $target_week_of_month) {
// we're in a valid month, but too late in it, so go to next valid month
increment_month($res_month, $res_year, $interval);
} else if ((int)($after_day / 7) == $target_week_of_month) {
$res_day = max($res_day, $after_day);
}
$month_length = days_in_month($res_month, $res_year);
$result = sprintf('%04d-%02d-%02d',$res_year,$res_month,$res_day);
while (date('w', iso8601_ts($result)) != $target_day_of_week) {
$res_day += (7 + $target_day_of_week - date('w', iso8601_ts($result)) - 1) % 7 + 1;
$result = sprintf('%04d-%02d-%02d',$res_year,$res_month,$res_day);
if (($res_day > $month_length) || ($res_day > (($target_week_of_month+1) * 7))) {
// run out of days, so we'll have to start again in the next valid month
increment_month($res_month, $res_year, $interval);
$month_length = days_in_month($res_month, $res_year);
$res_day = ($target_week_of_month * 7)+1;
}
$result = sprintf('%04d-%02d-%02d',$res_year,$res_month,$res_day);
}
break;
// Every 'x' months on the 'y'th last day of the month
case 'MRN':
$target_days_from_end = days_in_month($start_month, $start_year) - $start_day;
if (($month_diff % $interval) != 0) {
increment_month($res_month, $res_year, $interval - ($month_diff % $interval));
} else if ((days_in_month($res_month, $res_year) - $after_day) < $target_days_from_end) {
increment_month($res_month, $res_year, $interval);
}
$result = sprintf('%04d-%02d-%02d',$res_year,$res_month,days_in_month($res_month, $res_year) - $target_days_from_end);
while ((days_in_month($res_month, $res_year) - $target_days_from_end) < 0) {
increment_month($res_month, $res_year, $interval);
$result = sprintf('%04d-%02d-%02d',$res_year,$res_month,days_in_month($res_month, $res_year) - $target_days_from_end);
}
break;
// Every 'x' months on the 'y'th last weekday of the month
case 'MRW':
$min_day = 1;
$target_weeks_from_end = (int)((days_in_month($start_month, $start_year) - $start_day) / 7);
$target_day_of_week = (date('w', iso8601_ts($start)));
if (($month_diff % $interval) != 0) {
// go to the next valid month
increment_month($res_month, $res_year, $interval - ($month_diff % $interval));
} else if ((int)((days_in_month($after_month, $after_year) - $after_day) / 7) < $target_weeks_from_end) {
// we're too far into this month, so go to the next valid month
increment_month($res_month, $res_year, $interval);
} else if ((int)((days_in_month($after_month, $after_year) - $after_day) / 7) == $target_weeks_from_end) {
// we're in the right week so start from 'now', not the begining of the week,
}
$min_day = $after_day;
$res_day = days_in_month($res_month, $res_year) - ($target_weeks_from_end * 7);
$result = sprintf('%04d-%02d-%02d',$res_year,$res_month,$res_day);
while (date('w', iso8601_ts($result)) != $target_day_of_week) {
// if ($res_month - $start_month > 2) die;
$res_day -= (7 + date('w', iso8601_ts($result)) - $target_day_of_week) % 7;
if (($res_day < $min_day) || ($result < $after)) {
// can't get the nth-last xday in this month, either because
// it's already passed or because it doesn't exist, so goto next month
increment_month($res_month, $res_year, $interval);
$res_day = days_in_month($res_month, $res_year) - ($target_weeks_from_end * 7);
$min_day = 1;
}
$result = sprintf('%04d-%02d-%02d',$res_year,$res_month,$res_day);
}
break;
}//end switch[/codebox]
This might help as well:
name="<?php echo $prefix; ?>_frequency" id="<?php echo $prefix; ?>_frequency_daily" value="daily" onkeypress="this.click();" onclick="showFreqOptions('<?php echo $prefix; ?>', 'Daily'); checkBox('<?php echo $prefix?>_frequency_type_DED');" />
Daily
name="<?php echo $prefix; ?>_frequency" id="<?php echo $prefix; ?>_frequency_weekly" value="weekly" onkeypress="this.click();" onclick="showFreqOptions('<?php echo $prefix; ?>', 'Weekly'); checkBox('<?php echo $prefix?>_frequency_type_WEW');" />
Weekly
name="<?php echo $prefix; ?>_frequency" id="<?php echo $prefix; ?>_frequency_monthly" value="monthly" onkeypress="this.click();" onclick="showFreqOptions('<?php echo $prefix; ?>', 'Monthly'); checkBox('<?php echo $prefix?>_frequency_type_M');" />
Monthly
name="<?php echo $prefix; ?>_frequency_type" id="<?php echo $prefix; ?>_frequency_type_DED" value="DED" /><?php echo translate('cal_event_every_day'); ?>
<?php
// Every 'X' days textbox
ob_start(); ?>
<?php $x_days_tb = ob_get_contents();
ob_end_clean(); ?>
name="<?php echo $prefix; ?>_frequency_type" id="<?php echo $prefix; ?>_frequency_type_DEDx" value="DEDx" /><?php echo translate('cal_event_every_x_days', $x_days_tb); ?>
name="<?php echo $prefix; ?>_frequency_type" id="<?php echo $prefix; ?>_frequency_type_DWD" value="DWD" /><?php echo translate('cal_event_every_weekday'); ?>
name="<?php echo $prefix; ?>_frequency_type" id="<?php echo $prefix; ?>_frequency_type_DWE" value="DWE" /><?php echo translate('cal_event_every_weekend'); ?>
<?php
// link to weekday on Week links
ob_start(); ?>
<?php $week_link = ob_get_contents();
ob_end_clean();
// link to weekday on Every 'X' Weeks link
ob_start(); ?>
<?php $x_weeks_link = ob_get_contents();
ob_end_clean();
// Every 'X' weeks textbox
ob_start(); ?>
<?php $x_weeks_tb = ob_get_contents();
ob_end_clean(); ?>
name="<?php echo $prefix; ?>_frequency_type" id="<?php echo $prefix; ?>_frequency_type_WEW" value="WEW" /><?php echo translate('cal_event_every_week', $week_link); ?>
name="<?php echo $prefix; ?>_frequency_type" id="<?php echo $prefix; ?>_frequency_type_WEWx" value="WEWx" /><?php echo translate('cal_event_every_x_weeks', $x_weeks_tb, $x_weeks_link); ?>
<?php
// Every 'X' months textbox
ob_start(); ?>
<?php $x_months_tb = ob_get_contents();
ob_end_clean();
?>
name="<?php echo $prefix; ?>_frequency_type" id="<?php echo $prefix; ?>_frequency_type_M" value="M"><?php echo translate('cal_event_every_month'); ?>
name="<?php echo $prefix; ?>_frequency_type" id="<?php echo $prefix; ?>_frequency_type_Mx" value="Mx"><?php echo translate('cal_event_every_x_months', $x_months_tb); ?>
<?php
// link to day number on Every 'X' Months on Day link
ob_start(); ?>
<?php $mfn_month_link = ob_get_contents();
ob_end_clean(); ?>
name="<?php echo $prefix; ?>_monthly_type" value="MFN" /><?php echo translate('cal_event_month_on_day', $mfn_month_link) ?><?php echo translate('cal_event_when_it_exists') ?>
<?php
// link to day number on Every 'X' Months on Weekday link
ob_start(); ?>
<?php $mfw_month_link = ob_get_contents();
ob_end_clean();
// link to weekday on Every 'X' Months on Weekday link
ob_start(); ?>
<?php $mfw_day_link = ob_get_contents();
ob_end_clean(); ?>
name="<?php echo $prefix; ?>_monthly_type" value="MFW" /><?php echo translate('cal_event_month_on_weekday', $mfw_month_link, $mfw_day_link) ?> <?php echo translate('cal_event_when_it_exists') ?>
<?php
// link to day number on Every 'X' Months on Last Day link
ob_start(); ?>
<?php echo translate('last') ?>
Perfect. Thanks 