[Freeassociation-devel] [patch] Problem using icalcomponent_foreach_recurrence() with time filters
Terry Wilson
terry at logivox.net
Mon Jan 28 18:36:06 PST 2008
Ok, I've spent a while tracking this down and think I have a suitable
fix for it.
Situation:
I need to parse a calendar for whether or not someone is busy over a
particular timeframe. As an example:
...
calendar = icalparser_parse_string(calendar_text);
utc_zone = icaltimezone_get_utc_timezone();
start = icaltime_current_time_with_zone(utc_zone);
end = icaltime_current_time_with_zone(utc_zone);
end.hour += 1;
icaltime_normalize(end);
for(iter = icalcomponent_get_first_component(calendar,
ICAL_VEVENT_COMPONENT); iter; iter =
icalcomponent_get_next_component(calendar, ICAL_VEVENT_COMPONENT)) {
icalcomponent_foreach_recurrence(iter, start, end, callback,
NULL);
}
There are two problems. The first is that the VEVENT does not have
VTIMEZONEs locally, but they are in the parent so matching the TZID
with a VTIMEZONE fails. There are two copies of
icalcomponent_get_datetime in the source. One is commented out with a
TODO trying to figure out which one to use. The one that is
currently uncommented checks for the VTIMEZONE in the component.
Since this is being called from the _get_dtstart function, it will
almost always fail to find the VTIMEZONE, so dtstart will be returned
without a timezone. The one that is commented out, searches parents
until it finds the VTIMEZONE to compare against. This seems to be the
correct way to go about things.
The second problem is that the dtstart is not being converted to UTC
in this situation because icalcomponent_foreach_recurrence() calls
icaltime_span_new(dtstart, dtend, 1) which in turn calls
icaltime_as_timet_with_zone(dtstart,
icaltimezone_get_utc_timezone()). Now, dtstart in my case is GMT -6.
If you look in icaltimezone_convert_time, you will see that it returns
early because this means that we would be trying to convert from UTC
to UTC--completely ignoring the actual timezone of the dtstart.
Attatched is a patch that changes which icalcomponent_get_datetime to
use, as well as fixes icaltime_span_new to call
icaltime_as_timet_with_zone with the correct zone of the start/end of
the span if it exists. I also have sample data and sample code
exploiting the bug if it is helpful.
Terry Wilson
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: fix_timezone_issue.patch.txt
URL: <http://lists.infradead.org/pipermail/libical-devel/attachments/20080128/28ac367f/attachment.txt>
More information about the libical-devel
mailing list