Date slip with getNext() (again)
Closed this issue · 4 comments
Thank you for the v3.0.0. I don't know if it is linked to #9 and #11 but I still encounter a similar issue :
$c = new \Cron('0 3 * * *', new \DateTimeZone('Europe/Paris'));
echo $c->getNext();
When run at 1649548801 //2022-04-10 02:00:01
Expected:
1649552400 //2022-04-10 03:00:00
Actual:
1649552400 //2022-04-10 03:00:00
OK
When run at 1649549102 //2022-04-10 02:05:02
Expected:
1649552400 //2022-04-10 03:00:00
Actual:
1649638800 //2022-04-11 03:00:00
ERROR
I would like to help but I have difficulties to clearly understand your code. I guess that the issue may be in adjust() or forward().
I admit that there is still something fishy. The basic idea was: the timestamp (both the parameter and the return value of getNext) is always UTC/GMT while the timezone specified in the constructor parameter is the timezone the cron expression refers to.
Oh, I think the calculation routine has indeed a problem.
Very nice find, please try v3.0.1 or v2.4.3. I also added unit tests for your cases.
$expr = new CronExpression('0 3 * * *', new DateTimeZone('Europe/Paris'));
$ts = 1649549102;
echo date('c', $ts) . "\n";
echo date('c', $expr->getNext($ts)) . "\n";
Output:
2022-04-10T02:05:02+02:00
2022-04-10T03:00:00+02:00