From: Tim Otten Date: Tue, 19 Dec 2023 00:44:16 +0000 (-0800) Subject: CiviEvent - Re-fix iCal. Preserve compatibility. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=4c488f3d87804de8aeb3f46f7a41c851f6fa6961;p=civicrm-core.git CiviEvent - Re-fix iCal. Preserve compatibility. The recently merged commit for `CRM_Utils_ICalendar` fixed one bug and did some code-cleanup... but it changed a contract in a way that breaks `eventics` extension. This restores the original contract and a more conservative fix. --- diff --git a/CRM/Utils/ICalendar.php b/CRM/Utils/ICalendar.php index 01db70f0a5..6cafb774e5 100644 --- a/CRM/Utils/ICalendar.php +++ b/CRM/Utils/ICalendar.php @@ -160,41 +160,49 @@ class CRM_Utils_ICalendar { } /** + * @param array $timezones - Timezone strings * @param $date_min * @param $date_max * * @return array */ - public static function generate_timezones($date_min, $date_max) { - $tzstr = date_default_timezone_get(); - $timezone = new DateTimeZone($tzstr); + public static function generate_timezones(array $timezones, $date_min, $date_max) { + if (empty($timezones)) { + return []; + } - $transitions = $timezone->getTransitions($date_min, $date_max); + $tz_items = []; - if (count($transitions) === 1) { - $transitions[] = array_values($transitions)[0]; - } + foreach ($timezones as $tzstr) { + $timezone = new DateTimeZone($tzstr); - $item = [ - 'id' => $timezone->getName(), - 'transitions' => [], - ]; + $transitions = $timezone->getTransitions($date_min, $date_max); - $last_transition = array_shift($transitions); + if (count($transitions) === 1) { + $transitions[] = array_values($transitions)[0]; + } - foreach ($transitions as $transition) { - $item['transitions'][] = [ - 'type' => $transition['isdst'] ? 'DAYLIGHT' : 'STANDARD', - 'offset_from' => self::format_tz_offset($last_transition['offset']), - 'offset_to' => self::format_tz_offset($transition['offset']), - 'abbr' => $transition['abbr'], - 'dtstart' => date_create($transition['time'], $timezone)->format("Ymd\THis"), + $item = [ + 'id' => $timezone->getName(), + 'transitions' => [], ]; - $last_transition = $transition; - } + $last_transition = array_shift($transitions); - $tz_items[] = $item; + foreach ($transitions as $transition) { + $item['transitions'][] = [ + 'type' => $transition['isdst'] ? 'DAYLIGHT' : 'STANDARD', + 'offset_from' => self::format_tz_offset($last_transition['offset']), + 'offset_to' => self::format_tz_offset($transition['offset']), + 'abbr' => $transition['abbr'], + 'dtstart' => date_create($transition['time'], $timezone)->format("Ymd\THis"), + ]; + + $last_transition = $transition; + } + + $tz_items[] = $item; + } return $tz_items; } @@ -237,7 +245,7 @@ class CRM_Utils_ICalendar { return strtotime($event['end_date'] ?? $event['start_date']); }, $info) ); - $template->assign('timezones', CRM_Utils_ICalendar::generate_timezones($date_min, $date_max)); + $template->assign('timezones', CRM_Utils_ICalendar::generate_timezones([date_default_timezone_get()], $date_min, $date_max)); } else { $template->assign('timezones', NULL);