Skip to content

Commit

Permalink
Per RFC 5545, includes VTIMEZONE data in iCal exports
Browse files Browse the repository at this point in the history
Signed-off-by: Jon Stovell <[email protected]>
  • Loading branch information
Sesquipedalian committed Dec 1, 2024
1 parent d883db9 commit 8356422
Show file tree
Hide file tree
Showing 357 changed files with 58,020 additions and 9 deletions.
28 changes: 28 additions & 0 deletions Sources/Actions/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use SMF\Calendar\Event;
use SMF\Calendar\EventOccurrence;
use SMF\Calendar\Holiday;
use SMF\Calendar\VTimeZone;
use SMF\Config;
use SMF\Db\DatabaseApi as Db;
use SMF\ErrorHandler;
Expand Down Expand Up @@ -626,8 +627,10 @@ public function export(): void
&& ($occurrence = $event->getOccurrence($_REQUEST['recurrenceid'])) !== false
) {
$file['content'][] = $occurrence->export();
$file['content'][] = VTimeZone::load($occurrence->tzid)->export($occurrence->start, $occurrence->end);
} else {
$file['content'][] = $event->export();
$file['content'][] = VTimeZone::load($event->tzid)->export($event->start, $event->end);
}

$file['filename'] = $event->title . '.ics';
Expand Down Expand Up @@ -656,6 +659,7 @@ public function export(): void
$high_date = (clone $low_date)->add($duration);

$full_event_uids = [];
$tzids = [];

foreach (Event::getOccurrencesInRange($low_date->format('Y-m-d'), $high_date->format('Y-m-d'), true) as $occurrence) {
$event = $occurrence->getParentEvent();
Expand All @@ -674,17 +678,41 @@ public function export(): void
&& $event->getRecurrenceEnd() <= $high_date
)
) {
if (!isset($tzids[$event->tzid])) {
$tzids[$event->tzid] = [
'min' => $event->start,
'max' => $event->end,
];
}

$tzids[$event->tzid]['min'] = $tzids[$event->tzid]['min'] > $event->start ? $event->start : $tzids[$event->tzid]['min'];
$tzids[$event->tzid]['max'] = $tzids[$event->tzid]['max'] < $event->end ? $event->end : $tzids[$event->tzid]['max'];

$file['content'][] = $event->export();
$full_event_ids[] = $event->uid;
}
// Otherwise, export just this occurrence.
else {
if (!isset($tzids[$occurrence->tzid])) {
$tzids[$occurrence->tzid] = [
'min' => $occurrence->start,
'max' => $occurrence->end,
];
}

$tzids[$occurrence->tzid]['min'] = $tzids[$occurrence->tzid]['min'] > $occurrence->start ? $occurrence->start : $tzids[$occurrence->tzid]['min'];
$tzids[$occurrence->tzid]['max'] = $tzids[$occurrence->tzid]['max'] < $occurrence->end ? $occurrence->end : $tzids[$occurrence->tzid]['max'];

$file['content'][] = $occurrence->export();
}

$file['mtime'] = max($file['mtime'], $event->modified_time);
}

foreach ($tzids as $tzid => $range) {
$file['content'][] = VTimeZone::load($tzid)->export($range['min'], $range['max']);
}

$file['filename'] = implode(' ', [Utils::$context['forum_name'], Lang::$txt['events'], $low_date->format('Y-m-d'), $high_date->format('Y-m-d')]) . '.ics';
}

Expand Down
Loading

0 comments on commit 8356422

Please sign in to comment.