Migrating to iCal.net Period - Matches Date Only

573 views Asked by At

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?

1

There are 1 answers

0
Truc On

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);