1
0
mirror of https://github.com/rlanvin/php-rrule.git synced 2025-02-26 15:54:14 +01:00

Fix #120 Reset time to midnight to fix timezone offsets.

This commit is contained in:
Joel Stein 2023-01-06 04:01:00 -06:00 committed by GitHub
parent 15646f89da
commit fa13bf3f6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 4 deletions

View File

@ -1510,8 +1510,8 @@ class RRule implements RRuleInterface
$tmp = $year.':'.$yearday.':'.$time[0].':'.$time[1].':'.$time[2]; $tmp = $year.':'.$yearday.':'.$time[0].':'.$time[1].':'.$time[2];
if (! isset($filtered_set[$tmp])) { if (! isset($filtered_set[$tmp])) {
$occurrence = \DateTime::createFromFormat( $occurrence = \DateTime::createFromFormat(
'Y z', 'Y z H:i:s',
"$year $yearday", "$year $yearday 00:00:00",
$this->dtstart->getTimezone() $this->dtstart->getTimezone()
); );
$occurrence->setTime($time[0], $time[1], $time[2]); $occurrence->setTime($time[0], $time[1], $time[2]);
@ -1553,8 +1553,8 @@ class RRule implements RRuleInterface
// normal loop, without BYSETPOS // normal loop, without BYSETPOS
foreach ($dayset as $yearday) { foreach ($dayset as $yearday) {
$occurrence = \DateTime::createFromFormat( $occurrence = \DateTime::createFromFormat(
'Y z', 'Y z H:i:s',
"$year $yearday", "$year $yearday 00:00:00",
$this->dtstart->getTimezone() $this->dtstart->getTimezone()
); );

View File

@ -1815,6 +1815,19 @@ class RRuleTest extends TestCase
$this->assertEquals($count, $rrule->count()); $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 // GetOccurrences