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

getNextRunDate for isDue objects #4

Closed cedriclombardot closed 13 years ago

cedriclombardot commented 13 years ago

When i run this test :

    public function testNextWithZeroHour()
    {
        $cron = CronExpression::factory('@weekly');
        $nextRun = $cron->getNextRunDate("2008-11-09 08:00:00");
        $this->assertEquals($nextRun, new \DateTime("2008-11-16 00:00:00"));

        $nextRun = $cron->getNextRunDate("2008-11-09 00:00:00");
        $this->assertEquals($nextRun, new \DateTime("2008-11-16 00:00:00"));

    }

The first work but the second return the currentDate and not the real next execution.

How could we get the real next element ?

Thanks in advance Cédric

mtdowling commented 13 years ago

Thanks for your report. I added the ability to rule out the current date as the next run date of a cron expression. This should give you what you need.

https://github.com/mtdowling/cron-expression/commit/36ebc4121fbd1a0561e5e6cb5cfe2d496cfe16be

cedriclombardot commented 13 years ago

Thanks