Skip to content
Draft
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
15 changes: 15 additions & 0 deletions lib/private/Calendar/CalendarEventBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,21 @@ public function toIcs(): string {
foreach ($this->attendees as $attendee) {
self::addAttendeeToVEvent($vevent, 'ATTENDEE', $attendee);
}

// Prefix TZID values with '/' to reference globally-defined IANA timezone identifiers
// (RFC 5545 §3.2.19). This avoids the need for a VTIMEZONE component: without it,
// iTIP invite emails carry TZID=Europe/Berlin with no accompanying VTIMEZONE block,
// and some clients (e.g. Grommunio) misinterpret the time.
foreach (['DTSTART', 'DTEND'] as $propName) {
$prop = $vevent->$propName;
if ($prop !== null && isset($prop['TZID'])) {
$tzid = (string)$prop['TZID'];
if ($tzid !== '' && !str_starts_with($tzid, '/')) {
$prop['TZID'] = '/' . $tzid;
}
}
}

return $vcalendar->serialize();
}

Expand Down
18 changes: 18 additions & 0 deletions tests/data/ics/event-builder-with-timezone.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Sabre//Sabre VObject 4.5.6//EN
CALSCALE:GREGORIAN
BEGIN:VEVENT
UID:event-uid-123
DTSTAMP:20250105T000000Z
SUMMARY:My event
DTSTART;TZID=/Europe/Berlin:20260511T110000
DTEND;TZID=/Europe/Berlin:20260511T120000
STATUS:CONFIRMED
DESCRIPTION:Foo bar baz
ORGANIZER;CN=Organizer;ROLE=CHAIR;PARTSTAT=ACCEPTED:mailto:organizer@domain
.tld
ATTENDEE;CN=Attendee;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION:mailto:atte
ndee@domain.tld
END:VEVENT
END:VCALENDAR
2 changes: 2 additions & 0 deletions tests/data/ics/event-builder-with-timezone.ics.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
SPDX-License-Identifier: AGPL-3.0-or-later
36 changes: 36 additions & 0 deletions tests/lib/Calendar/CalendarEventBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,42 @@ public function testCreateInCalendar(): void {
$this->assertEquals('event-uid-123.ics', $actual);
}

public function testToIcsWithTimezone(): void {
$tz = new \DateTimeZone('Europe/Berlin');
$this->calendarEventBuilder->setStartDate(new DateTimeImmutable('2026-05-11T11:00:00', $tz));
$this->calendarEventBuilder->setEndDate(new DateTimeImmutable('2026-05-11T12:00:00', $tz));
$this->calendarEventBuilder->setStatus(CalendarEventStatus::CONFIRMED);
$this->calendarEventBuilder->setSummary('My event');
$this->calendarEventBuilder->setDescription('Foo bar baz');
$this->calendarEventBuilder->setOrganizer('organizer@domain.tld', 'Organizer');
$this->calendarEventBuilder->addAttendee('attendee@domain.tld', 'Attendee');

$actual = $this->calendarEventBuilder->toIcs();

// TZID must use the globally-defined form (RFC 5545 §3.2.19) so no VTIMEZONE is needed
$this->assertStringContainsString('DTSTART;TZID=/Europe/Berlin:', $actual);
$this->assertStringContainsString('DTEND;TZID=/Europe/Berlin:', $actual);
$this->assertStringNotContainsString('BEGIN:VTIMEZONE', $actual);

$expected = file_get_contents(\OC::$SERVERROOT . '/tests/data/ics/event-builder-with-timezone.ics');
$this->assertEquals($expected, $actual);
}

public function testToIcsWithUtcIsUnchanged(): void {
// UTC datetimes must stay as-is (Z suffix, no TZID parameter)
$this->calendarEventBuilder->setStartDate(new DateTimeImmutable('2026-05-11T09:00:00Z'));
$this->calendarEventBuilder->setEndDate(new DateTimeImmutable('2026-05-11T10:00:00Z'));
$this->calendarEventBuilder->setStatus(CalendarEventStatus::CONFIRMED);
$this->calendarEventBuilder->setSummary('My event');

$actual = $this->calendarEventBuilder->toIcs();

$this->assertStringContainsString('DTSTART:20260511T090000Z', $actual);
$this->assertStringContainsString('DTEND:20260511T100000Z', $actual);
$this->assertStringNotContainsString('TZID', $actual);
$this->assertStringNotContainsString('BEGIN:VTIMEZONE', $actual);
}

public function testToIcsWithoutStartDate(): void {
$this->calendarEventBuilder->setEndDate(new DateTimeImmutable('2025-01-05T17:19:58Z'));
$this->calendarEventBuilder->setSummary('My event');
Expand Down
Loading