Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle timezones with no transitions properly #6478

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
Copy link
Member

@st3iny st3iny Nov 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels a bit weird to use 1970-01-01 here.

Using $trans['time'] would also work but it can stay as is. It will be equivalent to the requested start date (one year back).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I know it looks odd, but this is how all the other software I have tested handles this, so I thought it would be best stay with the follow. The start year an date does not really matter for static time zones.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense!

$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
Loading