WordPress.org

Forums

Simple Google Calendar Widget
[resolved] Times and dates showing up incorrectly (3 posts)

  1. allentownpublictheatre
    Member
    Posted 1 year ago #

    Hi,

    The dates on my calendar widget are showing up incorrectly. They are being shown as one date but when clicked on the previous day is shown in the calendar. Any way to fix this? The website is http://www.allentownpublictheatre.com/. Our calendar can be seen HERE

    The last support post I saw about this was from a year ago and it seems the issue was resolved. Could this be something with the widget or is it my calendar or widget settings? I have the number of items to display set to 7 and cache refresh at 60 min.

    Thank you

    http://wordpress.org/plugins/simple-google-calendar-widget/

  2. denver.root
    Member
    Posted 1 year ago #

    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.

  3. nboehr
    Member
    Plugin Author

    Posted 8 months ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Simple Google Calendar Widget
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic