CronExpression::isDue
Determine if the cron is due to run based on the current date or a specific date. This method assumes that the current number of seconds are irrelevant, and should be called once per minute.
Method of the class: CronExpression{}
No Hooks.
Returns
true|false. Returns TRUE if the cron is due to run or FALSE if not
Usage
$CronExpression = new CronExpression(); $CronExpression->isDue( $currentTime );
- $currentTime(string|DateTime)
- (optional) Relative calculation date.
Default: 'now'
CronExpression::isDue() CronExpression::isDue code WC 10.3.6
public function isDue($currentTime = 'now')
{
if ('now' === $currentTime) {
$currentDate = date('Y-m-d H:i');
$currentTime = strtotime($currentDate);
} elseif ($currentTime instanceof DateTime) {
$currentDate = $currentTime->format('Y-m-d H:i');
$currentTime = strtotime($currentDate);
} else {
$currentTime = new DateTime($currentTime);
$currentTime->setTime($currentTime->format('H'), $currentTime->format('i'), 0);
$currentDate = $currentTime->format('Y-m-d H:i');
$currentTime = (int)($currentTime->getTimestamp());
}
return $this->getNextRunDate($currentDate, 0, true)->getTimestamp() == $currentTime;
}