Skip to content

Commit

Permalink
F
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonmantank committed Apr 16, 2024
1 parent 450fc54 commit bf264cb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/Cron/AbstractField.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 2 additions & 18 deletions src/Cron/HoursField.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Cron;

use DateTimeInterface;
use DateTimeZone;

/**
* Hours field. Allows: * , / -.
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -169,55 +166,42 @@ 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"));
}

$originalHour = (int)$date->format('H');
}

$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"));
}

$originalHour = (int)$date->format('H');
}

$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;
}
}

0 comments on commit bf264cb

Please sign in to comment.