Skip to content

Commit

Permalink
Fix #120 Reset time to midnight to fix timezone offsets.
Browse files Browse the repository at this point in the history
  • Loading branch information
joelstein authored Jan 6, 2023
1 parent 15646f8 commit fa13bf3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/RRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -1510,8 +1510,8 @@ public function getIterator()
$tmp = $year.':'.$yearday.':'.$time[0].':'.$time[1].':'.$time[2];
if (! isset($filtered_set[$tmp])) {
$occurrence = \DateTime::createFromFormat(
'Y z',
"$year $yearday",
'Y z H:i:s',
"$year $yearday 00:00:00",
$this->dtstart->getTimezone()
);
$occurrence->setTime($time[0], $time[1], $time[2]);
Expand Down Expand Up @@ -1553,8 +1553,8 @@ public function getIterator()
// normal loop, without BYSETPOS
foreach ($dayset as $yearday) {
$occurrence = \DateTime::createFromFormat(
'Y z',
"$year $yearday",
'Y z H:i:s',
"$year $yearday 00:00:00",
$this->dtstart->getTimezone()
);

Expand Down
13 changes: 13 additions & 0 deletions tests/RRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1815,6 +1815,19 @@ public function testMaxCyclesDoesntKickInIfTheRuleProduceOccurrences($frequency,
$this->assertEquals($count, $rrule->count());
}

/**
* Tests timezone transition in Daylight Savings Time switch.
*/
public function testDST()
{
$rrule = new RRule([
'FREQ' => 'WEEKLY',
'DTSTART' => new \DateTime('2022-10-30T01:00', new \DateTimeZone('America/Chicago')),
'COUNT' => 2,
]);
$this->assertSame('2022-11-06T01:00:00-05:00 CDT 1667714400', $rrule[1]->format('c T U'));
}

///////////////////////////////////////////////////////////////////////////////
// GetOccurrences

Expand Down

0 comments on commit fa13bf3

Please sign in to comment.