1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/**
* Class ActionScheduler_CronSchedule
*/
class ActionScheduler_CronSchedule implements ActionScheduler_Schedule {
/** @var DateTime */
private $start = NULL;
private $start_timestamp = 0;
/** @var CronExpression */
private $cron = NULL;
public function __construct( DateTime $start, CronExpression $cron ) {
$this->start = $start;
$this->cron = $cron;
}
/**
* @param DateTime $after
* @return DateTime|null
*/
public function next( DateTime $after = NULL ) {
$after = empty($after) ? clone $this->start : clone $after;
return $this->cron->getNextRunDate($after, 0, false);
}
/**
* @return bool
*/
public function is_recurring() {
return true;
}
/**
* @return string
*/
public function get_recurrence() {
return strval($this->cron);
}
/**
* For PHP 5.2 compat, since DateTime objects can't be serialized
* @return array
*/
public function __sleep() {
$this->start_timestamp = $this->start->getTimestamp();
return array(
'start_timestamp',
'cron'
);
}
public function __wakeup() {
$this->start = as_get_datetime_object($this->start_timestamp);
}
}