PHP Classes

Bug at midnight

Recommend this page to a friend!

      tdCron  >  All threads  >  Bug at midnight  >  (Un) Subscribe thread alerts  
Subject:Bug at midnight
Summary:Wrong nextrun() when current time is midnight
Messages:3
Author:Eric
Date:2013-02-13 17:33:36
Update:2013-11-20 09:12:57
 

  1. Bug at midnight   Reply   Report abuse  
Picture of Eric Eric - 2013-02-13 17:33:36
The getNextOccurrence() method returns the wrong value when the timestamp is midnight and the crontab expression is "* * * * *".

For example, if the current timestamp is '2013-02-13 00:00:00', getNextOccurrence() will return '2013-02-14 00:00:00' (midnight the *next* day). It should return '2013-02-13 00:01:00' (one minute past midnight on the current day).


Add this entry to the test.data.php file to show the problem:

$tests[] = array(
'desc' => 'Just a simple at midnight -> * * * * *',
'expression' => '* * * * *',
'reftime' => mktime(0,0,0,2,1,2010),
'expected_l' => '01.02.2010, 00:00:00',
'expected_n' => '01.02.2010, 00:01:00'
);


  2. Re: Bug at midnight   Reply   Report abuse  
Picture of Sulyok Gábor Sulyok Gábor - 2013-07-09 17:29:52 - In reply to message 1 from Eric
I had the same problem, and I looked around a bit in the code.
In class.tdcron.php & calculateDateTime() method has wrong condition in if statement. The findValue() method return false in some cases, and the following conditions do not examine properly, because (!$nhour) is true, when $nhour = false and true, when $nhour = 0 too.
So the solution to the problem is to simply replace the condition to ($nhour === false).

  3. Re: Bug at midnight   Reply   Report abuse  
Picture of Lorenz Meyer Lorenz Meyer - 2013-11-20 09:12:57 - In reply to message 2 from Sulyok Gábor
It is in class.tdcron.php on line 163 that you must replace

if (!$nhour) {
by
if ($nhour === false) {