CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviEvent (Moderator: Yashodha Chaku) »
  • CiviEvent / Google Calendar integration: timezone issue workaround
Pages: [1]

Author Topic: CiviEvent / Google Calendar integration: timezone issue workaround  (Read 2204 times)

zbgc

  • I’m new here
  • *
  • Posts: 18
  • Karma: 0
  • CiviCRM version: 3.4.5
  • CMS version: Drupal 6.22
  • MySQL version: 5.0.91
  • PHP version: 5.2.17
CiviEvent / Google Calendar integration: timezone issue workaround
July 12, 2011, 06:57:16 pm
Here's what I've done to work around the Google Calendar timezone issue (as described at e.g. forum.civicrm.org/index.php/topic,19613.msg81606.html):

1. Create a Smarty function plugin which can adjust dates+times fed to it:

<?php
/*
 * Smarty plugin
 * -------------------------------------------------------------
 * File:     function.myAdjustDate.php
 * Type:     function
 * Name:     myAdjustDate
 * Purpose:  modifies a date+time for a different timezone
 * -------------------------------------------------------------
 */
   
function smarty_function_myAdjustDate($params, $template)
{
    $str = $params['date'];
    $dateTime = new DateTime($str, new DateTimeZone('Australia/Melbourne'));
    $dateTime->setTimeZone(new DateTimeZone('GMT'));
    $date = $dateTime->format('Ymd');
    $date = $date . 'T';
    $date = $date . $dateTime->format('His');
    return $date;
}
?>


.... modifying the 'Australia/Melbourne' timezone string to your local timezone as appropriate.

2. Save the above in a file called function.myAdjustDate.php and upload it to the drupal/sites/all/modules/civicrm/CRM/Core/Smarty/plugins directory.

3. Modify the file drupal/sites/all/modules/civicrm/templates/CRM/Core/Calendar/ICal.tpl such that it contains the following:

{if $event.start_date}
DTSTAMP;VALUE=DATE-TIME:{myAdjustDate date=$event.start_date}
DTSTART;VALUE=DATE-TIME:{myAdjustDate date=$event.start_date}
{else}
DTSTAMP;VALUE=DATE-TIME:{myAdjustDate date=$smarty.now}
{/if}
{if $event.end_date}
DTEND;VALUE=DATE-TIME:{myAdjustDate date=$event.end_date}
{else}
DTEND;VALUE=DATE-TIME:{myAdjustDate date=$event.start_date}
{/if}


4. Use Google Calendar to the iCalendar feed using the URL:

  your.site.com/drupal/civicrm/event/ical?reset=1

(For some reason Google Calendar doesn't like the URL 'your.site.com/drupal/civicrm/event/ical?reset=1&page=1'.)

All these shenanigans are necessary because Google Calendar doesn't seem to honour ISO8601 timezone information (e.g. '20110713T190000+10') nor the X-WR-TIMEZONE iCalendar extension (at least, not in my testing). Instead it assumes iCalendar data has a GMT context and thus adjusts the date+time information according to one's Google Calendar timezone setting. (Changing one's Google Calendar timezone setting to GMT is not an option when one's calendar is subscribed to several other Google calendars which correctly specify their timezone; doing so then incorrectly modifies dates+times from those other calendars.)

I should also note here that (I'm guessing) Google appears to cache subscribed calendar information for a certain period, such that changes made to CiviEvent events may not be immediately reflected in Google Calendar. In my testing, 10 hours is an outer bound for the caching period.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using CiviEvent (Moderator: Yashodha Chaku) »
  • CiviEvent / Google Calendar integration: timezone issue workaround

This forum was archived on 2017-11-26.