1

I'm trying to simulate the MatchesDateOnly for my recurrence rule "ExcludeDates" which I'm storing as date only values. I want my RRULE to ignore certain date only periods.

Previously in DDay we could specify:

if (!recurrenceOptions.ExcludeDates.IsNullOrEmpty ())
{
    var periodList = new PeriodList ();

    recurrenceOptions.ExcludeDates.ForEach (d =>
    {
        var period = new Period (new iCalDateTime (d), TimeSpan.FromDays (1)) { MatchesDateOnly = true };
        periodList.Add (period);
    });

    iCalEvent.ExceptionDates.Add (periodList);
}

var occurences = iCalEvent.GetOccurrences (range.StartDate, range.EndDate);

How can I mimic this functionality in iCal.net?

Graeme
  • 773
  • 1
  • 8
  • 18
  • Looks like I removed that in this commit, because it appeared to be unused. Maybe I should put it back? Do you have a more complete code example that I could turn into a unit test? https://github.com/rianjs/ical.net/commit/b7faeea4c0d256bcddd15719bb0727d99d1916f9 – rianjs Sep 21 '17 at 01:37
  • @rianjs Would love to have this, it's the only thing currently missing for my use case. I've added a bit more context to the sample. Just wondering, could this be added to the 2.3.x version? If not, possibly someway I can extend the Period type? I tried but it doesn't seem to use the Period::Equals() method in my testing. – Graeme Sep 21 '17 at 02:09
  • Yeah, I'm still maintaining 2.x in addition to 3.0. (In my day job, we use 2.x exclusively and extensively.) Can you open an issue on the project itself? You can just copy and paste this. – rianjs Sep 21 '17 at 14:57

1 Answers1

0

You can try with RecurrencePatternEvaluator

var vEvent = new Event {
 DtStart = new CalDateTime(newDateTime(2017, 3, 1, 9, 0, 0)),
 DtEnd = new CalDateTime(newDateTime(2017, 3, 1, 10, 0, 0))
};
var recurrenceRule = new RecurrencePattern(FrequencyDayType.Weekly, 1) {
 ByDay = new IList<IWeekday> { new WeekDay(DayOfWeek.Thursday) }
};
var recurrenceEvaluator = new RecurrencePatternEvaluator(recurrenceRule);
var searchStart = new DateTime(2017, 3, 1, 0, 0, 0);
var searchEnd = new DateTime(2017, 3, 17, 0, 0, 0);
var correctOccurrences = recurrenceEvaluator.Evaluate(vEvent.DtStart, searchStart, searchEnd, false);
Truc
  • 386
  • 4
  • 12