function simplenews_scheduler_calculate_edition_time in Simplenews Scheduler 6.2
Same name and namespace in other branches
- 8 simplenews_scheduler.module \simplenews_scheduler_calculate_edition_time()
- 7 simplenews_scheduler.module \simplenews_scheduler_calculate_edition_time()
- 2.0.x simplenews_scheduler.module \simplenews_scheduler_calculate_edition_time()
Calculates time for the current edition about to be created.
Because cron may run after the scheduled timestamp, one or more scheduled edition times may have been skipped. This calculates the most recent possible time for an edition.
Parameters
$newsletter_parent_data: A row of data from {simplenews_scheduler}, as returned by simplenews_scheduler_get_newsletters_due().
$now_time: The time of the operation.
Return value
The calculated creation time of the newsletter edition.
4 calls to simplenews_scheduler_calculate_edition_time()
- SimpleNewsSchedulerDaylightSavingSwitchTest::testDSTMonthly in tests/
simplenews_scheduler.test - Test edition time after DST changes for a monthly newsletter.
- SimpleNewsSchedulerEditionDueTest::testEditionsDue in tests/
simplenews_scheduler.test - Test simplenews_scheduler_get_newsletters_due().
- SimpleNewsSchedulerEditionTimeTest::testEditionTimeOneMonth in tests/
simplenews_scheduler.test - Test a frequency of 1 month.
- simplenews_scheduler_cron in ./
simplenews_scheduler.module - Implementation of hook_cron().
File
- ./
simplenews_scheduler.module, line 381 - Simplenews Scheduler module allows a schedule to be set for sending (and resending) a Simplenews item.
Code
function simplenews_scheduler_calculate_edition_time($newsletter_parent_data, $now_time) {
// Make an offset string of the format '+1 month'.
$offset_string = _simplenews_scheduler_make_time_offset($newsletter_parent_data->send_interval, 1);
// Take the last run time and add as many intervals as possible without going
// past 'now'.
// Create a date object to act as a pointer we'll advance and increment.
if ($newsletter_parent_data->last_run) {
// Generate a date string to initialize a DateTime() object, otherwise the
// timezone is ignored.
$start_date = date('Y-m-d H:i:s', $newsletter_parent_data->last_run);
}
else {
$start_date = date('Y-m-d H:i:s', $newsletter_parent_data->start_date);
}
// Initialize the DateTime object using the configured ste timezone.
$pointer_date = new DateTime($start_date);
while ($pointer_date
->getTimestamp() <= $now_time) {
// Get the last iteration's timestamp before we change the pointer.
$timestamp_old = $pointer_date
->getTimestamp();
// Add interval to the pointer time.
$pointer_date
->modify($offset_string);
// Check if the pointer is now in the future.
if ($pointer_date
->getTimestamp() > $now_time) {
// If so, return the last iteration timestamp as the edition time.
return $timestamp_old;
}
}
}