From bf264cb22448016350bc43fe7767c30c01825f75 Mon Sep 17 00:00:00 2001 From: Chris Tankersley Date: Mon, 15 Apr 2024 23:38:33 -0400 Subject: [PATCH] F --- src/Cron/AbstractField.php | 4 ++-- src/Cron/HoursField.php | 20 ++------------------ 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/src/Cron/AbstractField.php b/src/Cron/AbstractField.php index 977ed54..e0b1d1c 100644 --- a/src/Cron/AbstractField.php +++ b/src/Cron/AbstractField.php @@ -327,9 +327,9 @@ protected function setTimeHour(DateTimeInterface $date, bool $invert, int $origi // setTime caused the offset to change, moving time in the wrong direction $actualTimestamp = $date->format('U'); if ((! $invert) && ($actualTimestamp <= $originalTimestamp)) { - $date = $date->modify("+1 hour"); + $date = $date->add(new \DateInterval('PT1H')); } elseif ($invert && ($actualTimestamp >= $originalTimestamp)) { - $date = $date->modify("-1 hour"); + $date = $date->sub(new \DateInterval('PT1H')); } return $date; diff --git a/src/Cron/HoursField.php b/src/Cron/HoursField.php index 2a76d90..3b5d7f3 100644 --- a/src/Cron/HoursField.php +++ b/src/Cron/HoursField.php @@ -5,7 +5,6 @@ namespace Cron; use DateTimeInterface; -use DateTimeZone; /** * Hours field. Allows: * , / -. @@ -53,11 +52,9 @@ public function isSatisfiedBy(DateTimeInterface $date, $value, bool $invert): bo if (($lastTransition !== null) && ($lastTransition["ts"] > ((int) $date->format('U') - 3600))) { $dtLastOffset = clone $date; $dtLastOffset->modify("-1 hour"); - // $this->timezoneSafeModify($dtLastOffset, "-1 hour"); $lastOffset = $dtLastOffset->getOffset(); $dtNextOffset = clone $date; - // $this->timezoneSafeModify($dtNextOffset, "+1 hour"); $dtNextOffset->modify("1 hour"); $nextOffset = $dtNextOffset->getOffset(); @@ -86,9 +83,9 @@ public function getPastTransition(DateTimeInterface $date): ?array // We start a day before current time so we can differentiate between the first transition entry // and a change that happens now $dtLimitStart = clone $date; - $dtLimitStart = $dtLimitStart->modify("-12 months"); + $dtLimitStart = $dtLimitStart->sub(new \DateInterval('P12M')); $dtLimitEnd = clone $date; - $dtLimitEnd = $dtLimitEnd->modify('+12 months'); + $dtLimitStart = $dtLimitStart->add(new \DateInterval('P12M')); $this->transitions = $date->getTimezone()->getTransitions( $dtLimitStart->getTimestamp(), @@ -169,14 +166,12 @@ public function increment(DateTimeInterface &$date, $invert = false, $parts = nu if (! $invert) { if ($originalHour >= $target) { $distance = 24 - $originalHour; - // $date = $this->timezoneSafeModify($date, "+{$distance} hours"); $date = $date->add(new \DateInterval("PT{$distance}H")); $actualDay = (int)$date->format('d'); $actualHour = (int)$date->format('H'); if (($actualDay !== ($originalDay + 1)) && ($actualHour !== 0)) { $offsetChange = ($previousOffset - $date->getOffset()); - // $date = $this->timezoneSafeModify($date, "+{$offsetChange} seconds"); $date = $date->add(new \DateInterval("PT{$distance}S")); } @@ -184,19 +179,16 @@ public function increment(DateTimeInterface &$date, $invert = false, $parts = nu } $distance = $target - $originalHour; - // $date = $this->timezoneSafeModify($date, "+{$distance} hours"); $date = $date->add(new \DateInterval("PT{$distance}H")); } else { if ($originalHour <= $target) { $distance = ($originalHour + 1); - // $date = $this->timezoneSafeModify($date, "-" . $distance . " hours"); $date = $date->sub(new \DateInterval("PT{$distance}H")); $actualDay = (int)$date->format('d'); $actualHour = (int)$date->format('H'); if (($actualDay !== ($originalDay - 1)) && ($actualHour !== 23)) { $offsetChange = ($previousOffset - $date->getOffset()); - // $date = $this->timezoneSafeModify($date, "+{$offsetChange} seconds"); $date = $date->add(new \DateInterval("PT{$offsetChange}H")); } @@ -204,20 +196,12 @@ public function increment(DateTimeInterface &$date, $invert = false, $parts = nu } $distance = $originalHour - $target; - // $date = $this->timezoneSafeModify($date, "-{$distance} hours"); - // $date = $date->modify("-{$distance} hours and -{$previousOffset} seconds"); $interval = new \DateInterval("PT{$distance}H"); $date = $date->sub($interval); } $date = $this->setTimeHour($date, $invert, $originalTimestamp); - $actualHour = (int)$date->format('H'); - if ($invert && ($actualHour === ($target - 1) || (($actualHour === 23) && ($target === 0)))) { - // $date = $this->timezoneSafeModify($date, "+1 hour"); - // $date = $date->add(new \DateInterval("PT1H")); - } - return $this; } }