CIVICRM-1756 Update Event ICalendar & List output to use timezone
authorFrancis Whittle <francis@agileware.com.au>
Fri, 7 May 2021 00:52:08 +0000 (10:52 +1000)
committerFrancis Whittle <francis@agileware.com.au>
Tue, 25 Jan 2022 06:07:09 +0000 (06:07 +0000)
CRM/Event/BAO/Event.php
CRM/Event/ICalendar.php
CRM/Event/Page/List.php
templates/CRM/Core/Calendar/ICal.tpl
templates/CRM/Event/Page/List.tpl

index 1047dd8b420bab2c9a1730cd5893e1585f366136..0f0ae0c6199a9b6f0287a11d259305dac7af4af9 100644 (file)
@@ -780,6 +780,7 @@ SELECT
   civicrm_email.email as email,
   civicrm_event.title as title,
   civicrm_event.summary as summary,
+  civicrm_event.event_tz as event_tz,
   civicrm_event.start_date as start,
   civicrm_event.end_date as end,
   civicrm_event.description as description,
@@ -851,6 +852,7 @@ WHERE civicrm_event.is_active = 1
         $info['event_id'] = $dao->event_id;
         $info['summary'] = $dao->summary;
         $info['description'] = $dao->description;
+        $info['tz'] = $dao->event_tz ?? CRM_Core_Config::singleton()->userSystem->getTimeZoneString();
         $info['start_date'] = $dao->start;
         $info['end_date'] = $dao->end;
         $info['contact_email'] = $dao->email;
index 7b30c95439911da6364a06c2ec2eaa2590d8dad5..c3e1b45aa58cd668986258228da67e70183b871e 100644 (file)
@@ -47,8 +47,16 @@ class CRM_Event_ICalendar {
     $config = CRM_Core_Config::singleton();
 
     $info = CRM_Event_BAO_Event::getCompleteInfo($start, $type, $id, $end);
+
+    foreach ($info as &$event) {
+      $event['start_date'] = CRM_Utils_Date::convertTimeZone($event['start_date'], $event['tz']);
+      $event['end_date'] = !empty($event['end_date']) ? CRM_Utils_date::convertTimeZone($event['end_date'], $event['tz']) : NULL;
+      $event['registration_start_date'] = !empty($event['registration_start_date']) ? CRM_Utils_date::convertTimeZone($event['registration_start_date'], $event['tz']) : NULL;
+      $event['registration_end_date'] = !empty($event['registration_end_date']) ? CRM_Utils_date::convertTimeZone($event['registration_end_date'], $event['tz']) : NULL;
+    }
+
     $template->assign('events', $info);
-    $template->assign('timezone', @date_default_timezone_get());
+    $template->assign('timezone', CRM_Core_Config::singleton()->userSystem->getTimeZoneString());
 
     // Send data to the correct template for formatting (iCal vs. gData)
     if ($rss) {
index ffeae8ba922a164e48399784ba0b87aede1fb4e6..ca4fae057b2e9792793a724ed905bdcfe7c7a781 100644 (file)
@@ -21,6 +21,21 @@ class CRM_Event_Page_List extends CRM_Core_Page {
     $end = CRM_Utils_Request::retrieveValue('end', 'Positive', 0);
 
     $info = CRM_Event_BAO_Event::getCompleteInfo($start, $type, $id, $end);
+
+    foreach ($info as &$event) {
+      $event['start_date_utc'] = CRM_Utils_Date::convertTimeZone($event['start_date'], 'UTC');
+      $event['start_date'] = CRM_Utils_Date::convertTimeZone($event['start_date'], $event['tz']);
+
+      $event['end_date_utc'] = !empty($event['end_date']) ? CRM_Utils_Date::convertTimeZone($event['end_date'], 'UTC') : NULL;
+      $event['end_date'] = !empty($event['end_date']) ? CRM_Utils_date::convertTimeZone($event['end_date'], $event['tz']) : NULL;
+
+      $event['registration_start_date_utc'] = !empty($event['registration_start_date']) ? CRM_Utils_Date::convertTimeZone($event['registration_start_date'], 'UTC') : NULL;
+      $event['registration_start_date'] = !empty($event['registration_start_date']) ? CRM_Utils_date::convertTimeZone($event['registration_start_date'], $event['tz']) : NULL;
+
+      $event['registration_end_date_utc'] = !empty($event['registration_end_date']) ? CRM_Utils_Date::convertTimeZone($event['registration_end_date'], 'UTC') : NULL;
+      $event['registration_end_date'] = !empty($event['registration_end_date']) ? CRM_Utils_date::convertTimeZone($event['registration_end_date'], $event['tz']) : NULL;
+    }
+
     $this->assign('events', $info);
 
     // @todo Move this to eventcart extension
index f38502d5adf5f9c895a6dfdb22b8260b61dd0ef0..ab15f5e1c07ed46e0aefaf195644f8fdfa2b0646 100644 (file)
@@ -24,15 +24,15 @@ CATEGORIES:{$event.event_type|crmICalText}
 {/if}
 CALSCALE:GREGORIAN
 {if $event.start_date}
-DTSTAMP;TZID={$timezone}:{$event.start_date|crmICalDate}
-DTSTART;TZID={$timezone}:{$event.start_date|crmICalDate}
+DTSTAMP;TZID={$event.tz|default:$timezone}:{$event.start_date|crmICalDate}
+DTSTART;TZID={$event.tz|default:$timezone}:{$event.start_date|crmICalDate}
 {else}
 DTSTAMP;TZID={$timezone}:{$smarty.now|date_format:'%Y-%m-%d %H:%M:%S'|crmICalDate}
 {/if}
 {if $event.end_date}
-DTEND;TZID={$timezone}:{$event.end_date|crmICalDate}
+DTEND;TZID={$event.tz|default:$timezone}:{$event.end_date|crmICalDate}
 {else}
-DTEND;TZID={$timezone}:{$event.start_date|crmICalDate}
+DTEND;TZID={$event.tz|default:$timezone}:{$event.start_date|crmICalDate}
 {/if}
 {if $event.is_show_location EQ 1 && $event.location}
 LOCATION:{$event.location|crmICalText}
index 50da60fd8b6d9caf50469bf443b98ad9379cbd1a..5db5103dbbfeda53c1360233bcbdc66a48d8d26a 100644 (file)
         <td><a href="{crmURL p='civicrm/event/info' q="reset=1&id=`$event.event_id`"}" title="{ts}read more{/ts}"><strong>{$event.title}</strong></a></td>
         <td>{if $event.summary}{$event.summary|purify} (<a href="{crmURL p='civicrm/event/info' q="reset=1&id=`$event.event_id`"}" title="{ts}details...{/ts}">{ts}read more{/ts}...</a>){else}&nbsp;{/if}</td>
         <td class="nowrap" data-order="{$event.start_date|crmDate:'%Y-%m-%d'}">
-          {if $event.start_date}{$event.start_date|crmDate}{if $event.end_date}<br /><em>{ts}through{/ts}</em><br />{strip}
+          {if $event.start_date}<time datetime="{$event.start_date_utc|date_format:"%Y-%m-%dT%H:%M:%S"}Z">{$event.start_date|crmDate}{if !$event.end_date}<span class="timezone"> {$event.tz}</span>{/if}</time>{if $event.end_date}<br /><em>{ts}through{/ts}</em><br /><time datetime="{$event.end_date_utc|date_format:"%Y-%m-%dT%H:%M:%S"}Z">{strip}
             {* Only show end time if end date = start date *}
             {if $event.end_date|date_format:"%Y%m%d" == $event.start_date|date_format:"%Y%m%d"}
-              {$event.end_date|crmDate:0:1}
+                {$event.end_date|crmDate:0:1}
             {else}
-              {$event.end_date|crmDate}
-            {/if}{/strip}{/if}
+                {$event.end_date|crmDate}
+            {/if}
+          {/strip}<span class="timezone"> {$event.tz}</span></time>
+{/if}
           {else}{ts}(not available){/ts}{/if}
         </td>
         <td>{if $event.is_show_location EQ 1 AND $event.location}{$event.location}{else}{ts}(not available){/ts}{/if}</td>