ActionScheduler_CronSchedule::__construct()publicWC 1.0

Wrapper for parent constructor to accept a cron expression string and map it to a CronExpression for this objects $recurrence property.

Method of the class: ActionScheduler_CronSchedule{}

No Hooks.


null. Nothing (null).


$ActionScheduler_CronSchedule = new ActionScheduler_CronSchedule();
$ActionScheduler_CronSchedule->__construct( $start, $recurrence, $first );
$start(DateTime) (required)
The date & time to run the action at or after. If $start aligns with the CronSchedule passed via $recurrence, it will be used. If it does not align, the first matching date after it will be used.
$recurrence(CronExpression|string) (required)
The CronExpression used to calculate the schedule's next instance.
(Optional) The date & time the first instance of this interval schedule ran.
Default: null, meaning this is the first instance

ActionScheduler_CronSchedule::__construct() code WC 9.0.1

public function __construct( DateTime $start, $recurrence, DateTime $first = null ) {
	if ( ! is_a( $recurrence, 'CronExpression' ) ) {
		$recurrence = CronExpression::factory( $recurrence );

	// For backward compatibility, we need to make sure the date is set to the first matching cron date, not whatever date is passed in. Importantly, by passing true as the 3rd param, if $start matches the cron expression, then it will be used. This was previously handled in the now deprecated next() method.
	$date = $recurrence->getNextRunDate( $start, 0, true );

	// parent::__construct() will set this to $date by default, but that may be different to $start now.
	$first = empty( $first ) ? $start : $first;

	parent::__construct( $date, $recurrence, $first );