WordPress.org

Support

Support » Plugins and Hacks » Simple Google Calendar Widget » [Resolved] Times and dates showing up incorrectly

[Resolved] Times and dates showing up incorrectly

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi allentownpublictheatre,

    One of the sites that I manage uses this plugin, and they had the same problem. Ultimately, it boils down to the plugin not correctly handling timezones. Thankfully, the information that Google provides in their web service helps to automatically determine the timezone of your calendar.

    Since the plugin developer hasn’t responded to your request in the last four months, I will explain how I fixed this on the site I manage. Below are instructions on what to do to fix this issue. Please be advised that modifying the source of a plugin like I am suggesting carries some risks with it, and should only be done if you are both comfortable with editing PHP code and also in control of the update-schedule for your website.

    Fix instructions:

    1. Log in to your site
    2. Click on “Plugins” in the main admin menu
    3. Under “Simple Google Calendar Widget“, click on “Edit
    4. In the list of Plugin Files (on the right side), make sure that “simple-google-calendar-widget/simple_gcal.php” is selected
    5. Lines 93-96 of the code should currently be this:
      $out[$i]->title = (string)$e->title;
      $out[$i]->from = strtotime((string)$when->startTime);
      $out[$i]->to = strtotime((string)$when->endTime);
      $out[$i]->where = (string)$where->valueString;
    6. REPLACE those lines of code with the following:
      $out[$i]->title = (string)$e->title;
      
      $resetTZ = date_default_timezone_get();
      date_default_timezone_set('GMT');
      preg_match('/^(.*?)(-\d+:\d+)?$/', (string)$when->startTime, $modifiedStartTime);
      $out[$i]->from = strtotime($modifiedStartTime[1]);
      preg_match('/^(.*?)(-\d+:\d+)?$/', (string)$when->endTime, $modifiedEndTime);
      $out[$i]->to = strtotime($modifiedEndTime[1]);
      date_default_timezone_set($resetTZ);
      
      $out[$i]->where = (string)$where->valueString;
    7. The portion that was changed is in between the extra line breaks; the first and last lines remain unchanged, and I included them just to provide context
    8. Click the “Update File” button at the bottom of the page
    9. Now, your calendar’s events on your website should match the timezone configured for that specific calendar

    Caveat: For each instance of the widget on your site, there is a “cache” limit specified (the setting is labeled “Cache expiration time in minutes:“). You will NOT see the changes that you just made take effect in any given widget instance until that cache limit has expired.

    P.S. To the plugin developer: it would be really nice if you integrated this fix into your plugin, so that your customers would not have to do the fix themselves and risk missing later updates from you.

    Plugin Author nboehr

    @nboehr

    Hi,

    I think you are right here. The plugin does not handle time zones correctly.

    However, I will not be accepting your fix because I think the plugin should respect the time zone set in wordpress and not the time zone set for the calendar.

    In the new version that should be available within the next hours, the plugin will now respect the time zone setting in your wordpress instance.

    In order to have the plugin display the same times/dates as google calendar, make sure that both are set to the same time zone.

    I am marking this as resolved now.

    I’m sorry that I am so slow to respond to your bug reports here.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] Times and dates showing up incorrectly’ is closed to new replies.
Skip to toolbar