I've been having a problem where the module would fetch events from Google that ended yesterday, even if I set the agenda start to "now". It also was not successfully filtering out the too-old events in the actual block display; though it did discard them on the debug page. I found that the fetching problem was fixed by supplying a full Atom format timestamp to the start-min parameter of the feed query, instead of just a datestamp. All I had to do was replace

function _agenda_feed_url($address, $key, $block) {

  $url = sprintf(AGENDA_SOURCEPATTERN,
    urlencode(check_plain($address)),
    urlencode(check_plain($key)),
    date('Y-m-d', strtotime($block->start)),
    date('Y-m-d', strtotime($block->end)),
    $block->maxevents,
    $block->timezone);

  return $url;
}

in agenda.module with

function _agenda_feed_url($address, $key, $block) {

  $url = sprintf(AGENDA_SOURCEPATTERN,
    urlencode(check_plain($address)),
    urlencode(check_plain($key)),
    date(DATE_ATOM, strtotime($block->start)),
    date(DATE_ATOM, strtotime($block->end)),
    $block->maxevents,
    $block->timezone);

  return $url;
}

I hope this is of some help to anyone experiencing the same issue! I never figured out a fix for the filtering aspect of the problem, but it doesn't really matter now that the fetching is fixed.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

aidanlis’s picture

Status: Active » Closed (duplicate)

Duplicate of #1016336: Events are displaying in the wrong date -- a day earlier (D7), your fix just happens to work but it is not correct.

Zidewinder’s picture

I don't think this is the same issue... That issue is about the events being displayed incorrectly. This is about the wrong events being fetched from Google.

Zidewinder’s picture

Issue summary: View changes

forgot to specify what file the change was made to

JerryDV’s picture

Issue summary: View changes
Status: Closed (duplicate) » Active

I re-opened this issue because I've run into this issue and it continues to be a problem with the latest release 7x.1.4.
I've done a lot of testing on this and have read the other issues. This is not a duplicate of the other issues also though they may involve some of the same problems. I am using 7x.1.4 and php 5.3 on a new drupal 7 install to test. I have the date/time module installed
I've discovered there are a number of factors involved.
1. While the debug script in agenda-admin.php filters out fetched events that begin before the start time, the agenda.module script does not and so they are displayed on the web page agenda block. This is a separate issue and I will open a new issue page for this. I will also suggest a fix for that issue.
2. The module as written uses only the Year, month, day part of the interpreted start time parameter. That means that when "now" is entered as a start time, the module will fetch all the events for today, including those before the start time. Similar problems occur with other start time settings. Those should be filtered out somewhere in the module. Even if they were, the problem with this approach is that the number of events actually displayed in a block can be far less than the number fetched.
Sending Google calendar a more precise start time timestamp would decrease difference between the number of items fetched and the number to be displayed . Sidewinder suggested replacing the 'Y-m-d' format with DATE_ATOM (see his entry in opening the issue). I suggest using 'c' instead. This sends Google a full date/time timestamp that includes the hour and minutes. This is what Google is expecting: https://developers.google.com/google-apps/calendar/v2/reference. With a couple of exceptions (see below) this fetches/returns only those events that start after the start time. I suggest others test this and if it works out. I would submit it as a patch, but I haven't learned how to do that yet. I've tested this fix on the drupal 6 version as well.
3. Exceptions to above fix: Here's the problem: Google calendar also returns those events started earlier than the start time, but last/continue past the start time. With the "today" start time setting an event that started at 11pm yesterday and lasted until 2 am today, will be fetched/returned. With the now setting an event that started at 3pm and continues until 5pm will fetched/returned at 4 pm. The also happens with whole day events. The "now" setting will always fetch any whole day event for the current day. The -1 day setting goes back 24 hours before the current time, but will display any whole day events for yesterday.
Now as I understand it, the module is designed to show only those events that start after the start time even though they are continuing at the start time. I deduce that from the debug script which filters out such events. (right?). I doubt whether anything can be done about this anomaly, but it need to be kept in mind, while testing the module. The fix I will suggest in the display issue I will open will deal with these exceptions.

JerryDV’s picture

Status: Active » Needs review
JerryDV’s picture

Here's a patch that incorporates the suggestion I made in #3.
This is my first time trying a patch so I hope I've got it right.
Nope, I didn't get it right. See next comment and attached file for another try.

JerryDV’s picture

FileSize
521 bytes

Here's the right patch I think.