Skip to content

Commit 38dfb0d

Browse files
Per RFC 5545, includes VTIMEZONE data in iCal exports
Signed-off-by: Jon Stovell <jonstovell@gmail.com>
1 parent d883db9 commit 38dfb0d

File tree

357 files changed

+56997
-9
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

357 files changed

+56997
-9
lines changed

Sources/Actions/Calendar.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use SMF\Calendar\Event;
2525
use SMF\Calendar\EventOccurrence;
2626
use SMF\Calendar\Holiday;
27+
use SMF\Calendar\VTimeZone;
2728
use SMF\Config;
2829
use SMF\Db\DatabaseApi as Db;
2930
use SMF\ErrorHandler;
@@ -626,8 +627,10 @@ public function export(): void
626627
&& ($occurrence = $event->getOccurrence($_REQUEST['recurrenceid'])) !== false
627628
) {
628629
$file['content'][] = $occurrence->export();
630+
$file['content'][] = VTimeZone::load($occurrence->tzid)->export($occurrence->start, $occurrence->end);
629631
} else {
630632
$file['content'][] = $event->export();
633+
$file['content'][] = VTimeZone::load($event->tzid)->export($event->start, $event->end);
631634
}
632635

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

658661
$full_event_uids = [];
662+
$tzids = [];
659663

660664
foreach (Event::getOccurrencesInRange($low_date->format('Y-m-d'), $high_date->format('Y-m-d'), true) as $occurrence) {
661665
$event = $occurrence->getParentEvent();
@@ -674,17 +678,41 @@ public function export(): void
674678
&& $event->getRecurrenceEnd() <= $high_date
675679
)
676680
) {
681+
if (!isset($tzids[$event->tzid])) {
682+
$tzids[$event->tzid] = [
683+
'min' => $event->start,
684+
'max' => $event->end,
685+
];
686+
}
687+
688+
$tzids[$event->tzid]['min'] = $tzids[$event->tzid]['min'] > $event->start ? $event->start : $tzids[$event->tzid]['min'];
689+
$tzids[$event->tzid]['max'] = $tzids[$event->tzid]['max'] < $event->end ? $event->end : $tzids[$event->tzid]['max'];
690+
677691
$file['content'][] = $event->export();
678692
$full_event_ids[] = $event->uid;
679693
}
680694
// Otherwise, export just this occurrence.
681695
else {
696+
if (!isset($tzids[$occurrence->tzid])) {
697+
$tzids[$occurrence->tzid] = [
698+
'min' => $occurrence->start,
699+
'max' => $occurrence->end,
700+
];
701+
}
702+
703+
$tzids[$occurrence->tzid]['min'] = $tzids[$occurrence->tzid]['min'] > $occurrence->start ? $occurrence->start : $tzids[$occurrence->tzid]['min'];
704+
$tzids[$occurrence->tzid]['max'] = $tzids[$occurrence->tzid]['max'] < $occurrence->end ? $occurrence->end : $tzids[$occurrence->tzid]['max'];
705+
682706
$file['content'][] = $occurrence->export();
683707
}
684708

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

712+
foreach ($tzids as $tzid => $range) {
713+
$file['content'][] = VTimeZone::load($tzid)->export($range['min'], $range['max']);
714+
}
715+
688716
$file['filename'] = implode(' ', [Utils::$context['forum_name'], Lang::$txt['events'], $low_date->format('Y-m-d'), $high_date->format('Y-m-d')]) . '.ics';
689717
}
690718

0 commit comments

Comments
 (0)