Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetOccurences doesn't return correct items when used with RECURRENCE-ID #188

Closed
ostruk opened this issue Nov 2, 2016 · 2 comments
Closed

Comments

@ostruk
Copy link

ostruk commented Nov 2, 2016

Related to #148. I fixed the crash by adding ToList() to the internal selector, but then I found that function is returning incorrect recurrences. Consider an ical of this form:

BEGIN:VCALENDAR
PRODID:-//Google Inc//Google Calendar 70.9054//EN
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:PUBLISH
X-WR-CALNAME:xxxxx
X-WR-TIMEZONE:America/New_York
BEGIN:VTIMEZONE
TZID:America/New_York
X-LIC-LOCATION:America/New_York
BEGIN:DAYLIGHT
TZOFFSETFROM:-0500
TZOFFSETTO:-0400
TZNAME:EDT
DTSTART:19700308T020000
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:-0400
TZOFFSETTO:-0500
TZNAME:EST
DTSTART:19701101T020000
RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU
END:STANDARD
END:VTIMEZONE

BEGIN:VEVENT
DTSTART;TZID=America/New_York:20160914T170000
DTEND;TZID=America/New_York:20160914T180000
RRULE:FREQ=WEEKLY;COUNT=12;BYDAY=WE
DTSTAMP:20161101T174111Z
UID:tnjve0etvt1qii2m9hqvcq8q10@google.com
CREATED:20160830T144912Z
DESCRIPTION:
LAST-MODIFIED:20160830T144912Z
LOCATION:Location A
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:Summary A
TRANSP:OPAQUE
END:VEVENT

BEGIN:VEVENT
DTSTART;TZID=America/New_York:20161012T170000
DTEND;TZID=America/New_York:20161012T180000
DTSTAMP:20161101T174111Z
UID:tnjve0etvt1qii2m9hqvcq8q10@google.com
RECURRENCE-ID;TZID=America/New_York:20161012T170000
CREATED:20160830T144912Z
DESCRIPTION:
LAST-MODIFIED:20160928T142729Z
LOCATION:Location A
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:Summary B
TRANSP:OPAQUE
END:VEVENT

END:VCALENDAR

GetOccurences function runs this code:

occurrences.ExceptWith(
occurrences.Where(o => o.Source is IUniqueComponent)
.Where(o => o.Source.RecurrenceId != null)
.Where(o => o.Source.RecurrenceId.Equals(o.Period.StartTime)).ToList());

Because the time of recurrence did not change, but summary did, function removes the overridden recurrence and returns the original event, which is incorrect (summary should be "Summary B", but it is "Summary A"). We have replaced this bit of code with the following:

foreach (var baseRecurringItem in occurences.Where(o => o.Source is UniqueComponent)
	.GroupBy(o => ((UniqueComponent)o.Source).Uid)
	.SelectMany(@group => @group.Where(o => o.Source.RecurrenceId != null)
	.SelectMany(occurrence => @group.Where(o => o.Source.RecurrenceId == null && occurrence.Source.RecurrenceId.Date.Equals(o.Period.StartTime.Date)))))
{
	occurences.Remove(baseRecurringItem);
} 

It removes the original item while leaving the override in place. Been using this since dday days when it would just return occurrences without attempting to filter them and haven't had any problems with it.

Thanks.

@ghentsch
Copy link

ghentsch commented Nov 3, 2016

Will you be building a new version of ical.net which incorporates this change or should we just work around it using your sample?

@rianjs
Copy link
Collaborator

rianjs commented Dec 15, 2016

@ghentsch and @ostruk - I just committed the workaround and published 2.2.25 which incorporates it. I added unit tests, too.

5c766b5

@rianjs rianjs closed this as completed Dec 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants