From 3bb3afdcab900cefecc45afb124c6e33165db893 Mon Sep 17 00:00:00 2001 From: Stephen Bourget Date: Tue, 6 Sep 2022 22:18:53 -0400 Subject: [PATCH] MDL-75627 Calendar: Fix calendar imports from Office 365 --- calendar/lib.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/calendar/lib.php b/calendar/lib.php index af819fd81f4..06bba2ba362 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -3072,11 +3072,21 @@ function calendar_import_events_from_ical(iCalendar $ical, int $subscriptionid = \core_php_time_limit::raise(300); } + // Start with a safe default timezone. + $timezone = 'UTC'; + // Grab the timezone from the iCalendar file to be used later. if (isset($ical->properties['X-WR-TIMEZONE'][0]->value)) { $timezone = $ical->properties['X-WR-TIMEZONE'][0]->value; - } else { - $timezone = 'UTC'; + + } else if (isset($ical->properties['PRODID'][0]->value)) { + // If the timezone was not found, check to se if this is MS exchange / Office 365 which uses Windows timezones. + if (strncmp($ical->properties['PRODID'][0]->value, 'Microsoft', 9) == 0) { + if (isset($ical->components['VTIMEZONE'][0]->properties['TZID'][0]->value)) { + $tzname = $ical->components['VTIMEZONE'][0]->properties['TZID'][0]->value; + $timezone = IntlTimeZone::getIDForWindowsID($tzname); + } + } } $icaluuids = [];