poliander / cron

Parse and validate crontab expressions in PHP
https://github.com/poliander/cron
GNU General Public License v3.0
63 stars 10 forks source link

getNext() errors #13

Closed ThomasPerraudin closed 2 years ago

ThomasPerraudin commented 2 years ago

Thank you for the v3.0.1. It works better. But I think that I found 2 new errors.

$tests = [
  [
    "expression" => '0 10 * * *',
    "timezone" => 'Europe/Paris',
    "now" => "2022-04-11T10:00:00+02:00", //1649664000
    "expected" => "2022-04-12T10:00:00+02:00" //1649750400
  ],
  [
    "expression" => '0 10 * * *',
    "timezone" => 'Europe/Paris',
    "now" => "2022-04-11T10:02:00+02:00", //1649664120
    "expected" => "2022-04-12T10:00:00+02:00" //1649750400
  ],
];

foreach($tests as $test){
  $expr = new CronExpression($test['expression'], new DateTimeZone($timezone));
  $now = strtotime($test['now']);
  $test['getNext'] = $expr->getNext($now);
  $test['getNext_c'] = date('c', $test['getNext']);
  $test['result'] = ($test['getNext_c']==$test['expected']?"ok":"** ERROR **");
  print_r($test);
}

Output:

Array
(
    [expression] => 0 10 * * *
    [timezone] => Europe/Paris
    [now] => 2022-04-11T10:00:00+02:00
    [expected] => 2022-04-12T10:00:00+02:00
    [getNext] => 1649714400
    [getNext_c] => 2022-04-12T00:00:00+02:00
    [result] => ** ERROR **
)
Array
(
    [expression] => 0 10 * * *
    [timezone] => Europe/Paris
    [now] => 2022-04-11T10:02:00+02:00
    [expected] => 2022-04-12T10:00:00+02:00
    [getNext] => 1649714400
    [getNext_c] => 2022-04-12T00:00:00+02:00
    [result] => ** ERROR **
)
poliander commented 2 years ago

Yes, I introduced these yesterday... (sigh)

poliander commented 2 years ago

I noticed my mistake early in the morning when I looked at the changes I made yesterday. I fixed this one in v3.0.2 and v2.4.4 and added your cases to the unit tests.

Again, thank you very much for reporting and giving such good test cases.

ThomasPerraudin commented 2 years ago

Thank you !

ThomasPerraudin commented 2 years ago

I can confirm that it works great on our projects. Thank you for this very useful code.

poliander commented 2 years ago

@ThomasPerraudin

Glad to hear that! Thank you very much for your positive feedback.