You are here

function CronRule::getIntervals in Ultimate Cron 7

Same name and namespace in other branches
  1. 8 CronRule.class.php \CronRule::getIntervals()
  2. 6 CronRule.class.php \CronRule::getIntervals()
  3. 7.2 CronRule.class.php \CronRule::getIntervals()

Generate regex rules

Parameters

$rule: (string) cronrule, e.g: 1,2,3,4-43/5 * * * 2,5

Return value

(array) date and time regular expression for mathing rule

2 calls to CronRule::getIntervals()
CronRule::getLastRan in ./CronRule.class.php
Get last execution time of rule in unix timestamp format
CronRule::parseRule in ./CronRule.class.php
Parse rule. Run through parser expanding expression, and recombine into crontab syntax.

File

./CronRule.class.php, line 121
This class parses cron rules and determines last execution time using least case integer comparison.

Class

CronRule
@file

Code

function getIntervals($rule = NULL) {
  $parts = preg_split('/\\s+/', isset($rule) ? $rule : $this->rule);
  if ($this->allow_shorthand) {
    $parts += array(
      '*',
      '*',
      '*',
      '*',
      '*',
    );
  }

  // Allow short rules by appending wildcards?
  if (count($parts) != 5) {
    return FALSE;
  }
  $this
    ->preProcessRule($parts);
  $intervals = array();
  $intervals['minutes'] = $this
    ->expandRange($parts[0], 'minutes');
  if (empty($intervals['minutes'])) {
    return FALSE;
  }
  $intervals['hours'] = $this
    ->expandRange($parts[1], 'hours');
  if (empty($intervals['hours'])) {
    return FALSE;
  }
  $intervals['days'] = $this
    ->expandRange($parts[2], 'days');
  if (empty($intervals['days'])) {
    return FALSE;
  }
  $intervals['months'] = $this
    ->expandRange($parts[3], 'months');
  if (empty($intervals['months'])) {
    return FALSE;
  }
  $intervals['weekdays'] = $this
    ->expandRange($parts[4], 'weekdays');
  if (empty($intervals['weekdays'])) {
    return FALSE;
  }
  $intervals['weekdays'] = array_flip($intervals['weekdays']);
  $this
    ->postProcessRule($intervals);
  return $intervals;
}