mtdowling / cron-expression

CRON for PHP: Calculate the next or previous run date and determine if a CRON expression is due
http://mtdowling.com/blog/2012/06/03/cron-expressions-in-php/
MIT License
4.9k stars 335 forks source link

"Impossible cron expression" thrown when number of run dates > 16 #99

Closed majkelo closed 8 years ago

majkelo commented 8 years ago

Even if I set $which<30 I only get 16 results (instead of 30)before I get an error. Sample code:

<?php
include( './vendor/autoload.php');

    $cron = Cron\CronExpression::factory('0 10-20/2 * * 1-5 *');
    $eventDates = array();
    for ($which = 0; $which<30; $which++) {
        try{
            $nextDateOfEvent = $cron->getRunDate('now', $which)->format('Y-m-d H:i:s');
        }
        catch (RuntimeException $e) {
            //var_dump($e);
            break;
        }
        array_push($eventDates, $nextDateOfEvent);
    }
    var_dump($eventDates);
    exit();

?>
majkelo commented 8 years ago

Moreover if I change CronExpression to '49 10-20/2 * * 1-5 *' I've got only 15 results.

If I change CronExpression to '* 10-20/2 * * 1-5 *' it works fine!

dragonmantank commented 8 years ago

Can you test this using v1.1.0, and changing getRunDate() to getNextRunDate()? I just tested this locally and was able to get as many runs as whatever $which< was set to.

dragonmantank commented 8 years ago

Closing since I haven't heard anything, and the new 1.1.0 release seems to have fixed it locally.