/// <summary> /// Evaluates this event to determine the dates and times for which the event occurs. /// This method only evaluates events which occur between <paramref name="FromDate"/> /// and <paramref name="ToDate"/>; therefore, if you require a list of events which /// occur outside of this range, you must specify a <paramref name="FromDate"/> and /// <paramref name="ToDate"/> which encapsulate the date(s) of interest. /// <note type="caution"> /// For events with very complex recurrence rules, this method may be a bottleneck /// during processing time, especially when this method in called for a large number /// of events, in sequence, or for a very large time span. /// </summary> /// <param name="FromDate">The beginning date of the range to evaluate.</param> /// <param name="ToDate">The end date of the range to evaluate.</param> /// <returns></returns> public override ArrayList Evaluate(Date_Time FromDate, Date_Time ToDate) { // Add the event itself, before recurrence rules are evaluated DateTimes.Add(DTStart.Copy()); Periods.Add(new Period(DTStart, Duration)); // Evaluate recurrences normally base.Evaluate(FromDate, ToDate); // Remove DateTimes that already have a Period for (int i = DateTimes.Count - 1; i >= 0; i--) { foreach (Period p in Periods) { if (p.StartTime == DateTimes[i]) { DateTimes.RemoveAt(i); } } } // Convert each calculated Date_Time into a Period. foreach (Date_Time dt in DateTimes) { Period p = new Period(dt, Duration); if (!Periods.Contains(p)) { Periods.Add(p); } } Periods.Sort(); return(Periods); }
private void DetermineStartingRecurrence(Recur recur, ref Date_Time dt) { if (recur.Count != int.MinValue) { dt = DTStart.Copy(); } else { recur.IncrementDate(ref dt, -recur.Interval); } }
/// <summary> /// Evaluates this event to determine the dates and times for which the event occurs. /// This method only evaluates events which occur between <paramref name="FromDate"/> /// and <paramref name="ToDate"/>; therefore, if you require a list of events which /// occur outside of this range, you must specify a <paramref name="FromDate"/> and /// <paramref name="ToDate"/> which encapsulate the date(s) of interest. /// <note type="caution"> /// For events with very complex recurrence rules, this method may be a bottleneck /// during processing time, especially when this method in called for a large number /// of events, in sequence, or for a very large time span. /// </summary> /// <param name="FromDate">The beginning date of the range to evaluate.</param> /// <param name="ToDate">The end date of the range to evaluate.</param> /// <returns></returns> public override List <Period> Evaluate(Date_Time FromDate, Date_Time ToDate) { // Make sure Duration is not null by now if (Duration == null) { // If a DTEnd was not provided, set one! if (DTEnd == null) { DTEnd = DTStart.Copy(); } Duration = DTEnd - DTStart; } // Add the event itself, before recurrence rules are evaluated // NOTE: this fixes a bug where (if evaluated multiple times) // a period can be added to the Periods collection multiple times. Period period = new Period(DTStart, Duration); if (!Periods.Contains(period)) { Periods.Add(period); } // Evaluate recurrences normally base.Evaluate(FromDate, ToDate); // Ensure each period has a duration foreach (Period p in Periods) { if (p.EndTime == null) { p.Duration = Duration; p.EndTime = p.StartTime + Duration; } // Ensure the Kind of time is consistent with DTStart else if (p.EndTime.Kind != DTStart.Kind) { p.EndTime.Value = new DateTime(p.EndTime.Year, p.EndTime.Month, p.EndTime.Day, p.EndTime.Hour, p.EndTime.Minute, p.EndTime.Second, DTStart.Kind); } } return(Periods); }