Skip to content

Commit

Permalink
Merge pull request #6487 from nextcloud/backport/6478/stable5.0
Browse files Browse the repository at this point in the history
[stable5.0] fix: handle timezones with no transitions properly
  • Loading branch information
st3iny authored Nov 11, 2024
2 parents 55d5957 + e352ef0 commit cd52e88
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
20 changes: 9 additions & 11 deletions lib/Service/Appointments/TimezoneGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,6 @@ public function generateVtimezone(string $timezone, int $from, int $to): ?VTimeZ
$standard = $daylightStart = null;
foreach ($transitions as $i => $trans) {
$component = null;

// skip the first entry...
if ($i === 0) {
// ... but remember the offset for the next TZOFFSETFROM value
$tzfrom = $trans['offset'] / 3600;
continue;
}

// daylight saving time definition
if ($trans['isdst']) {
$daylightDefinition = $trans['ts'];
Expand All @@ -69,9 +61,15 @@ public function generateVtimezone(string $timezone, int $from, int $to): ?VTimeZ
}

if ($component) {
$date = new \DateTime($trans['time']);
$offset = $trans['offset'] / 3600;

if ($i === 0) {
$date = new \DateTime('19700101T000000');
$tzfrom = $trans['offset'] / 3600;
$offset = $tzfrom;
} else {
$date = new \DateTime($trans['time']);
$offset = $trans['offset'] / 3600;
}

$component->DTSTART = $date->format('Ymd\THis');
$component->TZOFFSETFROM = sprintf('%s%02d%02d', $tzfrom >= 0 ? '+' : '-', abs(floor($tzfrom)), ($tzfrom - floor($tzfrom)) * 60);
$component->TZOFFSETTO = sprintf('%s%02d%02d', $offset >= 0 ? '+' : '-', abs(floor($offset)), ($offset - floor($offset)) * 60);
Expand Down
12 changes: 6 additions & 6 deletions tests/php/unit/Service/Appointments/TimezoneGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function testNoDaylightSaving($timezone, $daytime, $standard, $msTimezone

$this->assertEquals($timezone, $generated->TZID->getValue());
$this->assertNull($generated->DAYLIGHT);
$this->assertNull($generated->STANDARD);
$this->assertNotNull($generated->STANDARD);
$this->assertEquals($generated->{'X-MICROSOFT-CDO-TZID'}->getValue(), $msTimezoneId);
}

Expand All @@ -57,17 +57,17 @@ public function testInvalid(): void {
public function providerDaylightSaving(): array {
$microsoftExchangeMap = array_flip(TimeZoneUtil::$microsoftExchangeMap);
return [
['Europe/Berlin', 3, 3, $microsoftExchangeMap['Europe/Berlin']],
['Europe/London', 3, 3, $microsoftExchangeMap['Europe/London']],
['Australia/Adelaide', 3, 3, $microsoftExchangeMap['Australia/Adelaide']],
['Europe/Berlin', 3, 4, $microsoftExchangeMap['Europe/Berlin']],
['Europe/London', 3, 4, $microsoftExchangeMap['Europe/London']],
['Australia/Adelaide', 4, 3, $microsoftExchangeMap['Australia/Adelaide']],
];
}

public function providerNoDaylightSaving(): array {
$microsoftExchangeMap = array_flip(TimeZoneUtil::$microsoftExchangeMap);
return [
['Pacific/Midway', null, null, $microsoftExchangeMap['Pacific/Midway']],
['Asia/Singapore', null, null, $microsoftExchangeMap['Asia/Singapore']],
['Pacific/Midway', null, 1, $microsoftExchangeMap['Pacific/Midway']],
['Asia/Singapore', null, 1, $microsoftExchangeMap['Asia/Singapore']],
];
}

Expand Down

0 comments on commit cd52e88

Please sign in to comment.