Skip to content

Commit

Permalink
fix: refactor advanceTheDate
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-davis committed May 17, 2024
1 parent a555817 commit a2e53c3
Showing 1 changed file with 7 additions and 20 deletions.
27 changes: 7 additions & 20 deletions lib/Recur/RRuleIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,29 +286,16 @@ public function fastForward(\DateTimeInterface $dt): void

/**
* Advances currentDate by the interval.
* Takes into account the case where summer time starts and
* the event time on that day may have had to be advanced,
* usually by 1 hour.
* The time is set from the original startDate.
* If the recurrence is on a day when summer time started, then the
* time on that day may have jumped forward, for example, from 0230 to 0330.
* Using the original time means that the next recurrence will be calculated
* based on the original start time and the day/month/year interval.
* So the start time of the next occurrence can correctly revert to 0230.
*/
protected function advanceTheDate(string $interval): void
{
$hourOfPreviousDate = (int) $this->currentDate->format('G');
$this->currentDate = $this->currentDate->modify($interval);
if (0 === $this->hourJump) {
// Remember if the clock time jumped forward on the next date.
// That happens if the next date is a day when summer time starts
// and the event time is in the non-existent hour of the day.
// For example, an event that normally starts at 02:30 will
// have to start at 03:30 on that day.
$hourOfNextDate = (int) $this->currentDate->format('G');
$this->hourJump = $hourOfNextDate - $hourOfPreviousDate;
} else {
// The hour "jumped" for the previous date, to avoid the non-existent time.
// currentDate got set ahead by (usually) 1 hour on that day.
// Adjust it back for this next occurrence.
$this->currentDate = $this->currentDate->sub(new \DateInterval('PT'.$this->hourJump.'H'));
$this->hourJump = 0;
}
$this->currentDate = $this->currentDate->modify($interval.' '.$this->startDate->format('H:i:s'));
}

/**
Expand Down

0 comments on commit a2e53c3

Please sign in to comment.