Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeException: Impossible CRON expression at Date 2022-10-30 on Europe/Berlin Timezone #131

Closed
Apfelfrisch opened this issue Jan 5, 2022 · 10 comments

Comments

@Apfelfrisch
Copy link

Apfelfrisch commented Jan 5, 2022

At Version Version 3.2.2 I got a RuntimeException when the Date reaches the German time change.

The following Code works fine:

$cronExpression = new CronExpression('0 0 1 * *');
$date = new \DateTime('2022-10-30', new \DateTimeZone("UTC"));
$cronExpression->getNextRunDate($date)

but if I change the Timezone to Europe/Berlin:

$cronExpression = new CronExpression('0 0 1 * *');
$date = new \DateTime('2022-10-30', new \DateTimeZone("Europe/Berlin"));
$cronExpression->getNextRunDate($date)

I get a RuntimeException: Impossible CRON expression

Debugging from AbstractField::timezoneSafeModify:

    protected function timezoneSafeModify(DateTimeInterface $dt, string $modification): DateTimeInterface
    {
        $timezone = $dt->getTimezone();
        var_dump($dt);
        $dt = $dt->setTimezone(new \DateTimeZone("UTC"));
        var_dump($dt);
        $dt = $dt->modify($modification);
        $dt = $dt->setTimezone($timezone);
        die(var_dump($dt));
        return $dt;
    }

object(DateTime)[2430]
  public 'date' => string '2022-10-30 00:00:00.000000' (length=26)
  public 'timezone_type' => int 3
  public 'timezone' => string 'Europe/Berlin' (length=13)
/src/Cron/AbstractField.php:327:
object(DateTime)[2430]
  public 'date' => string '2022-10-29 22:00:00.000000' (length=26)
  public 'timezone_type' => int 3
  public 'timezone' => string 'UTC' (length=3)
/src/Cron/AbstractField.php:330:
object(DateTime)[2430]
  public 'date' => string '2022-10-30 23:00:00.000000' (length=26)
  public 'timezone_type' => int 3
  public 'timezone' => string 'Europe/Berlin' (length=13)

If needed, i can pr a failing Test by tomorrow.

@Apfelfrisch Apfelfrisch changed the title RuntimeException: Impossible CRON expression for 2022-10-30 on Europe/Berlin Timezone on v3.2.2 RuntimeException: Impossible CRON expression at Date 2022-10-30 on Europe/Berlin Timezone Jan 6, 2022
@dragonmantank
Copy link
Owner

Thanks for this. There is some weirdness going on when switching between UTC and the assigned timezones. I'm working on fixing this, as time zone shifts cause all sorts of issues.

@dragonmantank
Copy link
Owner

I just pushed v3.2.3 which should handle this better. I'll leave this open for a bit in case there are any other issues that crop up.

@Apfelfrisch
Copy link
Author

Apfelfrisch commented Jan 6, 2022

Sadly the Bug still exists with the above cron expression.

I saw you fix the issue in MinutesField.php and HoursField.php.

In my case though, the call comes from DayOfMonthField.php.

Hope that helps.

@dragonmantank
Copy link
Owner

Gotcha. Give dev-master a shot if you can, I adjusted the DOM field to work like Hours. If needed I can also cut 3.2.4, just let me know.

@Apfelfrisch
Copy link
Author

Apfelfrisch commented Jan 6, 2022

Looks good - Master works fine here :)

@HorstSchwarzBerlin
Copy link

HorstSchwarzBerlin commented Jan 7, 2022

same issue with the weekday field: (* * * * 2)
getNextRunDate with that date: CarbonImmutable::createFromDate('2020-10-23 15:31:45');
TIMEZONE=Europe/Berlin

@lreinhard-tfb
Copy link

Same error, but not related to timezone; rather getPreviousRunDate() and a cron expression like '15 1 1 9,11 *'.

>>> (new Cron\CronExpression('15 1 1 9,11 *'))->getNextRunDate();
=> DateTime @1662009300 {#3911
     date: 2022-09-01 01:15:00.0 America/New_York (-04:00),
   }
>>> (new Cron\CronExpression('15 1 1 9,11 *'))->getPreviousRunDate();
RuntimeException with message 'Impossible CRON expression'

Expected: 2021-11-01 01:15:00.0 America/New_York (-04:00)

This first occurs in v3.2.1, works properly in v3.2.0.

@dragonmantank
Copy link
Owner

@HorstSchwarzBerlin I changed this and now seems to be working as of v3.2.4. Thanks!

@lreinhard-tfb This looks like it was resolved as of at least v3.2.3. I added a regression test for it that is part of v3.2.4 so you should be good now.

@lreinhard-tfb
Copy link

@lreinhard-tfb This looks like it was resolved as of at least v3.2.3. I added a regression test for it that is part of v3.2.4 so you should be good now.

Can confirm that my case still fails in v3.2.3 but is fixed in v3.2.4. Thanks for the quick release!

@dragonmantank
Copy link
Owner

Closing this for now. Thanks for all the examples, and if it crops up again let me know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants