1

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.

M. Christopher
  • 305
  • 3
  • 14
  • Show us what have you already tried. – dymanoid Sep 22 '17 at 14:34
  • @dymanoid I've not tried anything yet, mostly reading the library's source code, so far I've not really found my solution and was wondering if someone with a better knowledge would know an obvious solution. – M. Christopher Sep 22 '17 at 14:41
  • 1
    Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. You should also read [ask]. – Enigmativity Sep 22 '17 at 14:41

1 Answers1

2

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);
}
rianjs
  • 7,767
  • 5
  • 24
  • 40
  • 2
    I added this example to the ical.net wiki: https://github.com/rianjs/ical.net/wiki/Working-with-collections-of-calendar-events#extract-a-range-of-calendar-events-from-a-calendar – rianjs Sep 22 '17 at 14:55
  • Thank you very much @rianjs! I'll try this and let you know. – M. Christopher Sep 22 '17 at 14:59