Beispiel #1
0
function bfox_plan_scheduler_for_post($post_id)
{
    $scheduler = new BfoxPlanScheduler();
    $scheduler->setStartDate(bfox_plan_meta('start_date', $post_id));
    if ($scheduler->startTime()) {
        $scheduler->setFrequency(bfox_plan_meta('frequency', $post_id));
        $scheduler->setReadingsPerDate(bfox_plan_meta('per_day', $post_id));
        $scheduler->setExcludedDates(bfox_plan_meta('excluded_days', $post_id));
    }
    return $scheduler;
}
assertArrays($ans, $scheduler->dates());
assertLatest($scheduler, '2011-08-20', '2011-08-20', 'The first date of the month');
assertLatest($scheduler, '2011-09-19', '2011-08-20', 'The last date of the month should still have the old reading from the beginning of the month');
assertLatest($scheduler, '2011-09-20', '2011-09-20', 'The first date of the new month');
$scheduler->setFrequency('weekly');
$scheduler->pushNumDates(4);
$ans = array_merge($ans, array('2011-12-20', '2011-12-27', '2012-01-03', '2012-01-10'));
assertArrays($ans, $scheduler->dates());
$scheduler->setFrequency('daily');
$scheduler->setDaysOfWeek(array('Sunday', 'Tuesday', 'Fri'));
$scheduler->pushNumDates(4);
$ans = array_merge($ans, array('2012-01-17', '2012-01-20', '2012-01-22', '2012-01-24'));
assertArrays($ans, $scheduler->dates());
assertLatest($scheduler, '2012-01-19', '2012-01-17', 'An excluded day of the week');
assertLatest($scheduler, '2012-01-23', '2012-01-22', 'Another excluded day of the week');
$scheduler->setDaysOfWeek(array('Monday', 'Wednesday'));
$scheduler->pushNumDates(3);
$ans = array_merge($ans, array('2012-01-25', '2012-01-30', '2012-02-01'));
assertArrays($ans, $scheduler->dates());
// New Scheduler for dates around current time
$scheduler = new BfoxPlanScheduler();
$scheduler->setStartDate('yesterday');
$scheduler->pushNumDates(4);
if (1 != $scheduler->latestDateIndex()) {
    echo "Error: LatestDateIndex for today is wrong\n";
} else {
    if ($showSuccess) {
        echo "Success: LatestDateIndex for today\n";
    }
}
echo "Tests Complete\n";