-
-
Notifications
You must be signed in to change notification settings - Fork 125
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
DST and getNextRunDate skips day #154
Comments
Probably related to #133 Encountered similar behaviour.
When a weekday is indicated in the CRON expression, for example Sunday (day 7), not a day is skipped, but a week: public function testIssueEnteringDateTimeAmsterdamOnSunday(): void
{
$expression = "* 12 * * 7";
$cron = new CronExpression($expression);
$tz = new \DateTimeZone("Europe/Amsterdam");
$dtExpected = $this->createDateTimeExactly("2023-03-26 12:00+02:00", $tz);
$dtCurrent = \DateTimeImmutable::createFromFormat("!Y-m-d H:i:s", "2023-03-26 00:00:00", $tz);
$dtActual = $cron->getNextRunDate($dtCurrent, 0, true, $tz->getName());
$this->assertEquals($dtExpected, $dtActual);
} results in:
When a range of hours like public function testIssueEnteringDateTimeRangeAmsterdam(): void
{
$expression = "* 12-15 * * *";
$cron = new CronExpression($expression);
$tz = new \DateTimeZone("Europe/Amsterdam");
$dtExpected = $this->createDateTimeExactly("2023-03-26 12:00+02:00", $tz);
$dtCurrent = \DateTimeImmutable::createFromFormat("!Y-m-d H:i:s", "2023-03-26 00:00:00", $tz);
$dtActual = $cron->getNextRunDate($dtCurrent, 0, true, $tz->getName());
$this->assertEquals($dtExpected, $dtActual);
} results in:
|
I tested package Tried to test php 8.1 with different package versions.
So I guess the problem is somewhere here: v3.2.0...dragonmantank:cron-expression:v3.2.1 |
Indeed, I suspect this function cron-expression/src/Cron/HoursField.php Lines 123 to 129 in 782ca59
Apparently UTC does not use/apply/consider DST: https://www.worldtimeserver.com/learn/does-utc-observe-daylight-saving-time
This "feature" seems to be used here, but might have unexpected side-effects? |
@dragonmantank Would be it possible to get a fix for the next daylight saving time schedule which would be around October/November ? |
3.2.1 did introduce a change to DST handling, as there were instances were it was skipping (particularly in +1 timezones and the London timezone). There was also a change in how DST is handled in PHP ~8.0 sometime, which broke how it was handled in prior versions. I'll see what I can do since this is coming up, but part of the fix might be just dropping older PHP support to simplify DST handling. |
Hello, is this issue resolved in 3.3.3 ? |
Don't believe so we just hit it. |
Yeah, unfortunately I was working on it last week but you fix one time change bug, and it affects something else. |
Thanks for the updates. :) |
If we are only using this in North American time zones, would downgrading to 3.2.0 be a good way to prevent the issue until you find a long-term fix? Just looking for options to make sure we don't get impacted on the next DST change. Thanks for your help! |
We downgraded to that and I tested out a few different scenarios using timecop and it worked for us! |
I believe I have a fix for this, it is due to how time math was being handled. Before I release a fix, could I get your thoughts on #181 as it will impact the overall solution? |
We had this happen last October for @dragonmantank, thank you for this library and your work in maintaining it ❤️. If you had to drop 7.4 to simplify the internals, I'd be fine with that, and I say this as an engineer that still maintains some legacy 7.4 systems. |
America/New_York
time zone changed to daylight saving time at 2:00 AM on Sunday, Mar 12, 2023.Expected date:
2023-03-12 07:30:00.0 America/New_York (-04:00)
Returned date:
2023-03-13 07:30:00.0 America/New_York (-04:00)
It works fine for other days, for example, if check would happen every day at 08:00 starting from 8th march:
The text was updated successfully, but these errors were encountered: