From 9545dea2a1d92b60c8b3d06f02025c83e999bde0 Mon Sep 17 00:00:00 2001 From: Chris Tankersley Date: Wed, 12 Jan 2022 23:09:37 -0500 Subject: [PATCH] Fix for DOW DST changes, and updated README --- CHANGELOG.md | 11 +++++++++++ src/Cron/DayOfWeekField.php | 4 ++-- tests/Cron/CronExpressionTest.php | 8 ++++---- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba51e503..9c736bb8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # Change Log +## [3.2.4] - 2022-01-12 + +### Added +- N/A + +### Changed +- Changed how Day of Week increment/decrement to help with DST changes (#131) + +### Fixed +- N/A + ## [3.2.3] - 2022-01-05 ### Added diff --git a/src/Cron/DayOfWeekField.php b/src/Cron/DayOfWeekField.php index 40db9af1..ef2a609d 100644 --- a/src/Cron/DayOfWeekField.php +++ b/src/Cron/DayOfWeekField.php @@ -151,10 +151,10 @@ public function isSatisfiedBy(DateTimeInterface $date, $value, bool $invert): bo public function increment(DateTimeInterface &$date, $invert = false, $parts = null): FieldInterface { if (! $invert) { - $date = $this->timezoneSafeModify($date, '+1 day'); + $date = $date->add(new \DateInterval('P1D')); $date = $date->setTime(0, 0); } else { - $date = $this->timezoneSafeModify($date, '-1 day'); + $date = $date->sub(new \DateInterval('P1D')); $date = $date->setTime(23, 59); } diff --git a/tests/Cron/CronExpressionTest.php b/tests/Cron/CronExpressionTest.php index 1e32df67..84b953be 100644 --- a/tests/Cron/CronExpressionTest.php +++ b/tests/Cron/CronExpressionTest.php @@ -687,12 +687,12 @@ public function testBerlinShouldAdvanceProperlyOverDST() public function testIssue131() { $e = new CronExpression('* * * * 2'); - $expected = new \DateTime('2020-10-27 00:00:00'); - $next = $e->getNextRunDate(new DateTime('2020-10-23 15:31:45')); + $expected = new \DateTime('2020-10-27 00:00:00', new \DateTimeZone('Europe/Berlin')); + $next = $e->getNextRunDate(new DateTime('2020-10-23 15:31:45', new \DateTimeZone('Europe/Berlin'))); $this->assertEquals($expected, $next); - $expected = new \DateTime('2020-10-20 23:59:00'); - $prev = $e->getPreviousRunDate(new DateTime('2020-10-23 15:31:45')); + $expected = new \DateTime('2020-10-20 23:59:00', new \DateTimeZone('Europe/Berlin')); + $prev = $e->getPreviousRunDate(new DateTime('2020-10-23 15:31:45', new \DateTimeZone('Europe/Berlin'))); $this->assertEquals($expected, $prev); $e = new CronExpression('15 1 1 9,11 *');