Hi,
Sorry, I failed to subscribe to the thread so didn't see your reply until someone pointed it out to me.
The changes I made were in the expand_ranges() function of CronParser.class.php As far as I can recall looking at the code today I added the extra loops to look for and expand step ranges of the form 1-9/n and */n
I was pretty new to cron codes when I wrote this so it may not be ideal but I recall that it worked OK on my test strings.
If there are any bugs please let me know and I'll do my best to fix them.
Bob
| Code: |
/**
* Assumes that value is not *, and creates an array of valid numbers that
* the string represents. Returns an array.
*/
function expand_ranges($str, $unit){
//$this->debug("Expanding $str");
// $this->debug("Expand Ranges: String: $str Unit: $unit");
if (strstr($str, ",")){
$tmp1 = explode(",", $str);
$count = count($tmp1);
for ( $i = 0; $i < $count; $i++ ) {
//Loop through each comma-separated value
if (strstr($tmp1[$i], "-")){
//If there's a range in this place, expand that too
if ( strstr($tmp1[$i], "/") ) {
$tmp3 = strtok($tmp1[$i], '/');
$tmp2 = explode("-", $tmp3);
$step = strtok("/");
} else {
$tmp2 = explode("-", $tmp1[$i]);
$step = 1;
}
// $this->debug("tmp2: ".print_r($tmp2, true)." step: $step");
for ( $j = $tmp2[0]; $j <= $tmp2[1]; $j = $j+$step ){
$ret[] = $j;
}
} else {//Otherwise, just add the value
$ret[] = $tmp1[$i];
}
}
} else if (strstr($str, "-")){
if ( strstr($str, "/") ) {
$tmp = strtok($str, "/");
$range = explode("-", $tmp);
$step = strtok("/");
} else {
$range = explode("-", $str);
$step = 1;
}
// $this->debug("range: ".print_r($range, true)." step: $step");
//There might only be a range, no comma sep values at all. Just loop these
for ( $i = $range[0]; $i <= $range[1]; $i = $i+$step ) {
$ret[] = $i;
}
} elseif ( strstr($str, "/") ) {
// No range so this must be a */n value
// we need to know the units range here:
$step = substr(strrchr($str, "/"), 1);
switch ($unit) {
case 0 :
// minutes
$end = 59;
break;
case 1 :
// hours
$end = 23;
break;
default :
// invalid entry
$end = false;
break;
}
if ( $end ) {
for ( $i = 0; $i <= $end; $i = $i+$step ) {
$ret[] = $i;
}
}
} else {
//Otherwise, it's a single value
$ret[] = $str;
}
// $this->debug("return: ".print_r($ret, true));
return $ret;
}
|