Reputation: 321
Using iCal.Net.
What I'm trying to achieve, is to shrink a calendar to send it over the internet, so I don't have to send the whole calendar, which would be wasteful (considering it can get big) if I'm asked what happens in a single day.
We should only send what occurs in the given period.
Calendar.GetOccurrences(IDateTime startTime, IDateTime endTime)
Seems to be a good start, I'm not sure how to get the actual CalendarObject then, nor if it's the good approach.
Upvotes: 1
Views: 69
Reputation: 7954
That's a use case I haven't encountered before, but it shouldn't be too difficult. I think I'd do something like this:
var relevantEvents = bigCalendar.GetOccurrences(start, end)
.Select(o => o.Source) // The parent IRecurrable
.Cast<Event>() // Which is an Event/CalendarEvent
.Distinct()
.ToList();
var smallerCalendar = new Calendar();
// I should add an extension method to UniqueComponentList for AddRange()
foreach (var relevantEvent in relevantEvents)
{
smallerCalendar.Events.Add(relevantEvent);
}
Upvotes: 2