diff --git a/Ical.Net.Tests/RecurrenceTests.cs b/Ical.Net.Tests/RecurrenceTests.cs index b654fbe4..9dc7fc98 100644 --- a/Ical.Net.Tests/RecurrenceTests.cs +++ b/Ical.Net.Tests/RecurrenceTests.cs @@ -2892,9 +2892,6 @@ public void GetOccurrences1() evt.RecurrenceRules[0].ByHour.Add(9); evt.RecurrenceRules[0].ByHour.Add(12); - // Clear the evaluation so we can calculate recurrences again. - evt.ClearEvaluation(); - occurrences = evt.GetOccurrences(previousDateAndTime, end); Assert.That(occurrences, Has.Count.EqualTo(10)); diff --git a/Ical.Net/Calendar.cs b/Ical.Net/Calendar.cs index f91781fe..70ec1b31 100644 --- a/Ical.Net/Calendar.cs +++ b/Ical.Net/Calendar.cs @@ -198,17 +198,6 @@ public VTimeZone AddTimeZone(VTimeZone tz) } - /// - /// Clears recurrence evaluations for recurring components. - /// - public void ClearEvaluation() - { - foreach (var recurrable in RecurringItems) - { - recurrable.ClearEvaluation(); - } - } - /// /// Returns a list of occurrences of each recurring component /// for the date provided (). @@ -405,4 +394,4 @@ public VTimeZone AddLocalTimeZone(DateTime earliestDateTimeToSupport, bool inclu this.AddChild(tz); return tz; } -} \ No newline at end of file +} diff --git a/Ical.Net/CalendarCollection.cs b/Ical.Net/CalendarCollection.cs index 77db0559..b89bfaa4 100644 --- a/Ical.Net/CalendarCollection.cs +++ b/Ical.Net/CalendarCollection.cs @@ -39,14 +39,6 @@ public static CalendarCollection Load(TextReader tr) return collection; } - public void ClearEvaluation() - { - foreach (var iCal in this) - { - iCal.ClearEvaluation(); - } - } - public HashSet GetOccurrences(IDateTime dt) { var occurrences = new HashSet(); @@ -158,4 +150,4 @@ public override bool Equals(object obj) if (ReferenceEquals(this, obj)) return true; return obj.GetType() == GetType() && Equals((CalendarEvent) obj); } -} \ No newline at end of file +} diff --git a/Ical.Net/CalendarComponents/Alarm.cs b/Ical.Net/CalendarComponents/Alarm.cs index af83a049..445ade67 100644 --- a/Ical.Net/CalendarComponents/Alarm.cs +++ b/Ical.Net/CalendarComponents/Alarm.cs @@ -63,12 +63,9 @@ public virtual Trigger Trigger set => Properties.Set(TriggerRelation.Key, value); } - protected virtual IList Occurrences { get; set; } - public Alarm() { Name = Components.Alarm; - Occurrences = new List(); } /// @@ -77,13 +74,13 @@ public Alarm() /// public virtual IList GetOccurrences(IRecurringComponent rc, IDateTime fromDate, IDateTime toDate) { - Occurrences.Clear(); - if (Trigger == null) { - return Occurrences; + return []; } + var occurrences = new List(); + // If the trigger is relative, it can recur right along with // the recurring items, otherwise, it happens once and // only once (at a precise time). @@ -121,21 +118,21 @@ public virtual IList GetOccurrences(IRecurringComponent rc, IDa } } - Occurrences.Add(new AlarmOccurrence(this, dt.Add(Trigger.Duration.Value), rc)); + occurrences.Add(new AlarmOccurrence(this, dt.Add(Trigger.Duration.Value), rc)); } } else { var dt = Trigger.DateTime.Copy(); dt.AssociatedObject = this; - Occurrences.Add(new AlarmOccurrence(this, dt, rc)); + occurrences.Add(new AlarmOccurrence(this, dt, rc)); } // If a REPEAT and DURATION value were specified, // then handle those repetitions here. - AddRepeatedItems(); + AddRepeatedItems(occurrences); - return Occurrences; + return occurrences; } /// @@ -165,19 +162,19 @@ public virtual IList Poll(IDateTime start, IDateTime end) /// DURATION properties. Each recurrence of the alarm will /// have its own set of generated repetitions. /// - protected virtual void AddRepeatedItems() + private void AddRepeatedItems(List occurrences) { - var len = Occurrences.Count; + var len = occurrences.Count; for (var i = 0; i < len; i++) { - var ao = Occurrences[i]; + var ao = occurrences[i]; var alarmTime = ao.DateTime.Copy(); for (var j = 0; j < Repeat; j++) { alarmTime = alarmTime.Add(Duration); - Occurrences.Add(new AlarmOccurrence(this, alarmTime.Copy(), ao.Component)); + occurrences.Add(new AlarmOccurrence(this, alarmTime.Copy(), ao.Component)); } } } -} \ No newline at end of file +} diff --git a/Ical.Net/CalendarComponents/CalendarEvent.cs b/Ical.Net/CalendarComponents/CalendarEvent.cs index 5df9f4f5..48d45f8c 100644 --- a/Ical.Net/CalendarComponents/CalendarEvent.cs +++ b/Ical.Net/CalendarComponents/CalendarEvent.cs @@ -224,8 +224,6 @@ public string Transparency set => Properties.Set(TransparencyType.Key, value); } - private EventEvaluator _mEvaluator; - /// /// Constructs an Event object, with an iCalObject /// (usually an iCalendar object) as its parent. @@ -239,36 +237,9 @@ private void Initialize() { Name = EventStatus.Name; - _mEvaluator = new EventEvaluator(this); - SetService(_mEvaluator); + SetService(new EventEvaluator(this)); } - /// - /// Use this method to determine if an event occurs on a given date. - /// - /// This event should be called only after the Evaluate - /// method has calculated the dates for which this event occurs. - /// - /// - /// The date to test. - /// True if the event occurs on the provided, False otherwise. - public virtual bool OccursOn(IDateTime dateTime) - { - return _mEvaluator.Periods.Any(p => p.StartTime.Date == dateTime.Date || // It's the start date OR - (p.StartTime.Date <= dateTime.Date && // It's after the start date AND - (p.EndTime.HasTime && p.EndTime.Date >= dateTime.Date || // an end time was specified, and it's after the test date - (!p.EndTime.HasTime && p.EndTime.Date > dateTime.Date)))); - } - - /// - /// Use this method to determine if an event begins at a given date and time. - /// - /// The date and time to test. - /// True if the event begins at the given date and time - public virtual bool OccursAt(IDateTime dateTime) - { - return _mEvaluator.Periods.Any(p => p.StartTime.Equals(dateTime)); - } /// /// Determines whether or not the is actively displayed diff --git a/Ical.Net/CalendarComponents/RecurringComponent.cs b/Ical.Net/CalendarComponents/RecurringComponent.cs index b9e004d5..f77bfc33 100644 --- a/Ical.Net/CalendarComponents/RecurringComponent.cs +++ b/Ical.Net/CalendarComponents/RecurringComponent.cs @@ -178,8 +178,6 @@ protected override void OnDeserializing(StreamingContext context) Initialize(); } - public virtual void ClearEvaluation() => RecurrenceUtil.ClearEvaluation(this); - public virtual HashSet GetOccurrences(IDateTime dt) => RecurrenceUtil.GetOccurrences(this, dt, EvaluationIncludesReferenceDate); public virtual HashSet GetOccurrences(DateTime dt) @@ -243,4 +241,4 @@ public override int GetHashCode() return hashCode; } } -} \ No newline at end of file +} diff --git a/Ical.Net/CalendarComponents/Todo.cs b/Ical.Net/CalendarComponents/Todo.cs index 6d8544f3..8679b2fa 100644 --- a/Ical.Net/CalendarComponents/Todo.cs +++ b/Ical.Net/CalendarComponents/Todo.cs @@ -160,9 +160,9 @@ public virtual bool IsCompleted(IDateTime currDt) } // Evaluate to the previous occurrence. - _mEvaluator.EvaluateToPreviousOccurrence(Completed, currDt); + var periods = _mEvaluator.EvaluateToPreviousOccurrence(Completed, currDt); - return _mEvaluator.Periods.Cast().All(p => !p.StartTime.GreaterThan(Completed) || !currDt.GreaterThanOrEqual(p.StartTime)); + return periods.Cast().All(p => !p.StartTime.GreaterThan(Completed) || !currDt.GreaterThanOrEqual(p.StartTime)); } return false; } @@ -212,4 +212,4 @@ private void ExtrapolateTimes(int source) DtStart = Due.Subtract(Duration); } } -} \ No newline at end of file +} diff --git a/Ical.Net/Evaluation/Evaluator.cs b/Ical.Net/Evaluation/Evaluator.cs index 073251c3..a1a63e16 100644 --- a/Ical.Net/Evaluation/Evaluator.cs +++ b/Ical.Net/Evaluation/Evaluator.cs @@ -13,37 +13,16 @@ namespace Ical.Net.Evaluation; public abstract class Evaluator : IEvaluator { - private DateTime _mEvaluationStartBounds = DateTime.MaxValue; - private DateTime _mEvaluationEndBounds = DateTime.MinValue; - private ICalendarObject _mAssociatedObject; - private readonly ICalendarDataType _mAssociatedDataType; - - protected HashSet MPeriods; protected Evaluator() { Initialize(); } - protected Evaluator(ICalendarObject associatedObject) - { - _mAssociatedObject = associatedObject; - - Initialize(); - } - - protected Evaluator(ICalendarDataType dataType) - { - _mAssociatedDataType = dataType; - - Initialize(); - } - private void Initialize() { Calendar = CultureInfo.CurrentCulture.Calendar; - MPeriods = new HashSet(); } protected IDateTime ConvertToIDateTime(DateTime dt, IDateTime referenceDate) @@ -93,32 +72,11 @@ protected void IncrementDate(ref DateTime dt, RecurrencePattern pattern, int int public System.Globalization.Calendar Calendar { get; private set; } - public virtual DateTime EvaluationStartBounds - { - get => _mEvaluationStartBounds; - set => _mEvaluationStartBounds = value; - } - - public virtual DateTime EvaluationEndBounds - { - get => _mEvaluationEndBounds; - set => _mEvaluationEndBounds = value; - } - public virtual ICalendarObject AssociatedObject { - get => _mAssociatedObject ?? _mAssociatedDataType?.AssociatedObject; + get => _mAssociatedObject; protected set => _mAssociatedObject = value; } - public virtual HashSet Periods => MPeriods; - - public virtual void Clear() - { - _mEvaluationStartBounds = DateTime.MaxValue; - _mEvaluationEndBounds = DateTime.MinValue; - MPeriods.Clear(); - } - public abstract HashSet Evaluate(IDateTime referenceDate, DateTime periodStart, DateTime periodEnd, bool includeReferenceDateInResults); -} \ No newline at end of file +} diff --git a/Ical.Net/Evaluation/EventEvaluator.cs b/Ical.Net/Evaluation/EventEvaluator.cs index 35050210..159fe6e2 100644 --- a/Ical.Net/Evaluation/EventEvaluator.cs +++ b/Ical.Net/Evaluation/EventEvaluator.cs @@ -41,9 +41,9 @@ public EventEvaluator(CalendarEvent evt) : base(evt) { } public override HashSet Evaluate(IDateTime referenceTime, DateTime periodStart, DateTime periodEnd, bool includeReferenceDateInResults) { // Evaluate recurrences normally - base.Evaluate(referenceTime, periodStart, periodEnd, includeReferenceDateInResults); + var periods = base.Evaluate(referenceTime, periodStart, periodEnd, includeReferenceDateInResults); - foreach (var period in Periods) + foreach (var period in periods) { period.Duration = CalendarEvent.GetFirstDuration(); period.EndTime = period.Duration == default @@ -52,7 +52,7 @@ public override HashSet Evaluate(IDateTime referenceTime, DateTime perio } // Ensure each period has a duration - foreach (var period in Periods.Where(p => p.EndTime == null)) + foreach (var period in periods.Where(p => p.EndTime == null)) { period.Duration = CalendarEvent.GetFirstDuration(); period.EndTime = period.Duration == default @@ -60,6 +60,6 @@ public override HashSet Evaluate(IDateTime referenceTime, DateTime perio : period.StartTime.Add(CalendarEvent.GetFirstDuration()); } - return Periods; + return periods; } -} \ No newline at end of file +} diff --git a/Ical.Net/Evaluation/IEvaluator.cs b/Ical.Net/Evaluation/IEvaluator.cs index 9f151935..29cbb56e 100644 --- a/Ical.Net/Evaluation/IEvaluator.cs +++ b/Ical.Net/Evaluation/IEvaluator.cs @@ -16,40 +16,11 @@ public interface IEvaluator /// System.Globalization.Calendar Calendar { get; } - /// - /// The start bounds of the evaluation. This gives - /// the first date/time that is covered by the evaluation. - /// This together with EvaluationEndBounds determines - /// what time frames have already been evaluated, so - /// duplicate evaluation doesn't occur. - /// - DateTime EvaluationStartBounds { get; } - - /// - /// The end bounds of the evaluation. - /// See for more info. - /// - DateTime EvaluationEndBounds { get; } - - /// - /// Gets a list of periods collected so far during - /// the evaluation process. - /// - HashSet Periods { get; } - /// /// Gets the object associated with this evaluator. /// ICalendarObject AssociatedObject { get; } - /// - /// Clears the evaluation, eliminating all data that has - /// been collected up to this point. Since this data is cached - /// as needed, this method can be useful to gather information - /// that is guaranteed to not be out-of-date. - /// - void Clear(); - /// /// Evaluates this item to determine the dates and times for which it occurs/recurs. /// This method only evaluates items which occur/recur between @@ -74,4 +45,4 @@ public interface IEvaluator /// each date/time when this item occurs/recurs. /// HashSet Evaluate(IDateTime referenceDate, DateTime periodStart, DateTime periodEnd, bool includeReferenceDateInResults); -} \ No newline at end of file +} diff --git a/Ical.Net/Evaluation/RecurrencePatternEvaluator.cs b/Ical.Net/Evaluation/RecurrencePatternEvaluator.cs index 37633246..73b8d52b 100644 --- a/Ical.Net/Evaluation/RecurrencePatternEvaluator.cs +++ b/Ical.Net/Evaluation/RecurrencePatternEvaluator.cs @@ -950,14 +950,11 @@ public override HashSet Evaluate(IDateTime referenceDate, DateTime perio // Enforce evaluation restrictions on the pattern. EnforceEvaluationRestrictions(pattern); - Periods.Clear(); var periodQuery = GetDates(referenceDate, periodStart, periodEnd, -1, pattern, includeReferenceDateInResults) .Select(dt => CreatePeriod(dt, referenceDate)); - Periods.UnionWith(periodQuery); - - return Periods; + return new HashSet(periodQuery); } private static IDateTime MatchTimeZone(IDateTime dt1, IDateTime dt2) diff --git a/Ical.Net/Evaluation/RecurrenceUtil.cs b/Ical.Net/Evaluation/RecurrenceUtil.cs index 9fb3fc17..3062d337 100644 --- a/Ical.Net/Evaluation/RecurrenceUtil.cs +++ b/Ical.Net/Evaluation/RecurrenceUtil.cs @@ -13,12 +13,6 @@ namespace Ical.Net.Evaluation; internal class RecurrenceUtil { - public static void ClearEvaluation(IRecurrable recurrable) - { - var evaluator = recurrable.GetService(typeof(IEvaluator)) as IEvaluator; - evaluator?.Clear(); - } - public static HashSet GetOccurrences(IRecurrable recurrable, IDateTime dt, bool includeReferenceDateInResults) => GetOccurrences(recurrable, new CalDateTime(dt.Date), new CalDateTime(dt.Date.AddDays(1).AddSeconds(-1)), includeReferenceDateInResults); @@ -99,4 +93,4 @@ public static HashSet GetOccurrences(IRecurrable recurrable, IDateTi return new bool?[] { false, null, false, false, false, false, false, false, false }; } } -} \ No newline at end of file +} diff --git a/Ical.Net/Evaluation/RecurringEvaluator.cs b/Ical.Net/Evaluation/RecurringEvaluator.cs index ce2b8827..4151d1d9 100644 --- a/Ical.Net/Evaluation/RecurringEvaluator.cs +++ b/Ical.Net/Evaluation/RecurringEvaluator.cs @@ -34,7 +34,7 @@ public RecurringEvaluator(IRecurrable obj) } /// - /// Evaluates the RRule component, and adds each specified Period to the Periods collection. + /// Evaluates the RRule component. /// /// /// The beginning date of the range to evaluate. @@ -67,7 +67,7 @@ protected HashSet EvaluateRRule(IDateTime referenceDate, DateTime period return periods; } - /// Evaluates the RDate component, and adds each specified DateTime or Period to the Periods collection. + /// Evaluates the RDate component. protected HashSet EvaluateRDate(IDateTime referenceDate, DateTime periodStart, DateTime periodEnd) { if (Recurrable.RecurrenceDates == null || !Recurrable.RecurrenceDates.Any()) @@ -80,7 +80,7 @@ protected HashSet EvaluateRDate(IDateTime referenceDate, DateTime period } /// - /// Evaluates the ExRule component, and excludes each specified DateTime from the Periods collection. + /// Evaluates the ExRule component. /// /// /// The beginning date of the range to evaluate. @@ -107,7 +107,7 @@ protected HashSet EvaluateExRule(IDateTime referenceDate, DateTime perio } /// - /// Evaluates the ExDate component, and excludes each specified DateTime or Period from the Periods collection. + /// Evaluates the ExDate component. /// /// /// The beginning date of the range to evaluate. @@ -125,7 +125,7 @@ protected HashSet EvaluateExDate(IDateTime referenceDate, DateTime perio public override HashSet Evaluate(IDateTime referenceDate, DateTime periodStart, DateTime periodEnd, bool includeReferenceDateInResults) { - Periods.Clear(); + var periods = new HashSet(); var rruleOccurrences = EvaluateRRule(referenceDate, periodStart, periodEnd, includeReferenceDateInResults); //Only add referenceDate if there are no RecurrenceRules defined @@ -140,30 +140,21 @@ public override HashSet Evaluate(IDateTime referenceDate, DateTime perio var exDateExclusions = EvaluateExDate(referenceDate, periodStart, periodEnd); //Exclusions trump inclusions - Periods.UnionWith(rruleOccurrences); - Periods.UnionWith(rdateOccurrences); - Periods.ExceptWith(exRuleExclusions); - Periods.ExceptWith(exDateExclusions); + periods.UnionWith(rruleOccurrences); + periods.UnionWith(rdateOccurrences); + periods.ExceptWith(exRuleExclusions); + periods.ExceptWith(exDateExclusions); - var dateOverlaps = FindDateOverlaps(exDateExclusions); - Periods.ExceptWith(dateOverlaps); + var dateOverlaps = FindDateOverlaps(periods, exDateExclusions); + periods.ExceptWith(dateOverlaps); - if (EvaluationStartBounds == DateTime.MaxValue || EvaluationStartBounds > periodStart) - { - EvaluationStartBounds = periodStart; - } - if (EvaluationEndBounds == DateTime.MinValue || EvaluationEndBounds < periodEnd) - { - EvaluationEndBounds = periodEnd; - } - - return Periods; + return periods; } - private HashSet FindDateOverlaps(HashSet dates) + private static HashSet FindDateOverlaps(HashSet periods, HashSet dates) { var datesWithoutTimes = new HashSet(dates.Where(d => !d.StartTime.HasTime).Select(d => d.StartTime.Value)); - var overlaps = new HashSet(Periods.Where(p => datesWithoutTimes.Contains(p.StartTime.Value.Date))); + var overlaps = new HashSet(periods.Where(p => datesWithoutTimes.Contains(p.StartTime.Value.Date))); return overlaps; } } diff --git a/Ical.Net/Evaluation/TimeZoneEvaluator.cs b/Ical.Net/Evaluation/TimeZoneEvaluator.cs deleted file mode 100644 index bf117039..00000000 --- a/Ical.Net/Evaluation/TimeZoneEvaluator.cs +++ /dev/null @@ -1,140 +0,0 @@ -// -// Copyright ical.net project maintainers and contributors. -// Licensed under the MIT license. -// - -using System; -using System.Collections.Generic; -using System.Diagnostics; -using Ical.Net.CalendarComponents; -using Ical.Net.DataTypes; - -namespace Ical.Net.Evaluation; - -public class TimeZoneEvaluator : Evaluator -{ - protected VTimeZone TimeZone { get; set; } - - private List _occurrences; - public virtual List Occurrences - { - get => _occurrences; - set => _occurrences = value; - } - - public TimeZoneEvaluator(VTimeZone tz) - { - TimeZone = tz; - _occurrences = new List(); - } - - private void ProcessOccurrences(IDateTime referenceDate) - { - // Sort the occurrences by start time - _occurrences.Sort( - delegate (Occurrence o1, Occurrence o2) { - if (o1.Period?.StartTime == null) - { - return -1; - } - return o2.Period?.StartTime == null - ? 1 - : o1.Period.StartTime.CompareTo(o2.Period.StartTime); - } - ); - - for (var i = 0; i < _occurrences.Count; i++) - { - var curr = _occurrences[i]; - var next = i < _occurrences.Count - 1 ? _occurrences[i + 1] : null; - - // Determine end times for our periods, overwriting previously calculated end times. - // This is important because we don't want to overcalculate our time zone information, - // but simply calculate enough to be accurate. When date/time ranges that are out of - // normal working bounds are encountered, then occurrences are processed again, and - // new end times are determined. - curr.Period.EndTime = next != null - ? next.Period.StartTime.AddTicks(-1) - : ConvertToIDateTime(EvaluationEndBounds, referenceDate); - } - } - - public override void Clear() - { - base.Clear(); - _occurrences.Clear(); - } - - public override HashSet Evaluate(IDateTime referenceDate, DateTime periodStart, DateTime periodEnd, bool includeReferenceDateInResults) - { - // Ensure the reference date is associated with the time zone - if (referenceDate.AssociatedObject == null) - referenceDate.AssociatedObject = TimeZone; - - var infos = new List(TimeZone.TimeZoneInfos); - - // Evaluate extra time periods, without re-evaluating ones that were already evaluated - if ((EvaluationStartBounds == DateTime.MaxValue && EvaluationEndBounds == DateTime.MinValue) - || periodEnd.Equals(EvaluationStartBounds) - || periodStart.Equals(EvaluationEndBounds)) - { - foreach (var curr in infos) - { - var evaluator = curr.GetService(typeof(IEvaluator)) as IEvaluator; - Debug.Assert(curr.Start != null, "TimeZoneInfo.Start must not be null."); - Debug.Assert(curr.Start.TzId == null, "TimeZoneInfo.Start must not have a time zone reference."); - Debug.Assert(evaluator != null, "TimeZoneInfo.GetService(typeof(IEvaluator)) must not be null."); - - // Time zones must include an effective start date/time - // and must provide an evaluator. - if (evaluator == null) - { - continue; - } - - // Set the start bounds - if (EvaluationStartBounds > periodStart) - { - EvaluationStartBounds = periodStart; - } - - // FIXME: 5 years is an arbitrary number, to eliminate the need - // to recalculate time zone information as much as possible. - var offsetEnd = periodEnd.AddYears(5); - - // Determine the UTC occurrences of the Time Zone observances - var periods = evaluator.Evaluate( - referenceDate, - periodStart, - offsetEnd, - includeReferenceDateInResults); - - foreach (var period in periods) - { - Periods.Add(period); - var o = new Occurrence(curr, period); - if (!_occurrences.Contains(o)) - { - _occurrences.Add(o); - } - } - - if (EvaluationEndBounds == DateTime.MinValue || EvaluationEndBounds < offsetEnd) - { - EvaluationEndBounds = offsetEnd; - } - } - - ProcessOccurrences(referenceDate); - } - else - { - if (EvaluationEndBounds != DateTime.MinValue && periodEnd > EvaluationEndBounds) - { - Evaluate(referenceDate, EvaluationEndBounds, periodEnd, includeReferenceDateInResults); - } - } - - return Periods; - } -} \ No newline at end of file diff --git a/Ical.Net/Evaluation/TodoEvaluator.cs b/Ical.Net/Evaluation/TodoEvaluator.cs index db63d2a8..adc593cb 100644 --- a/Ical.Net/Evaluation/TodoEvaluator.cs +++ b/Ical.Net/Evaluation/TodoEvaluator.cs @@ -18,7 +18,7 @@ public class TodoEvaluator : RecurringEvaluator public TodoEvaluator(Todo todo) : base(todo) { } - public void EvaluateToPreviousOccurrence(IDateTime completedDate, IDateTime currDt) + internal HashSet EvaluateToPreviousOccurrence(IDateTime completedDate, IDateTime currDt) { var beginningDate = completedDate.Copy(); @@ -51,21 +51,19 @@ public void EvaluateToPreviousOccurrence(IDateTime completedDate, IDateTime curr } } - Evaluate(Todo.Start, DateUtil.GetSimpleDateTimeData(beginningDate), DateUtil.GetSimpleDateTimeData(currDt).AddTicks(1), true); + return Evaluate(Todo.Start, DateUtil.GetSimpleDateTimeData(beginningDate), DateUtil.GetSimpleDateTimeData(currDt).AddTicks(1), true); } - public void DetermineStartingRecurrence(PeriodList rdate, ref IDateTime referenceDateTime) + private void DetermineStartingRecurrence(PeriodList rdate, ref IDateTime referenceDateTime) { - var evaluator = rdate.GetService(); - var dt2 = referenceDateTime; - foreach (var p in evaluator.Periods.Where(p => p.StartTime.LessThan(dt2))) + foreach (var p in rdate.Where(p => p.StartTime.LessThan(dt2))) { referenceDateTime = p.StartTime; } } - public void DetermineStartingRecurrence(RecurrencePattern recur, ref IDateTime referenceDateTime) + private void DetermineStartingRecurrence(RecurrencePattern recur, ref IDateTime referenceDateTime) { if (recur.Count != int.MinValue) { @@ -87,10 +85,10 @@ public override HashSet Evaluate(IDateTime referenceDate, DateTime perio return new HashSet(); } - base.Evaluate(referenceDate, periodStart, periodEnd, includeReferenceDateInResults); + var periods = base.Evaluate(referenceDate, periodStart, periodEnd, includeReferenceDateInResults); // Ensure each period has a duration - foreach (var period in Periods.Where(period => period.EndTime == null)) + foreach (var period in periods.Where(period => period.EndTime == null)) { period.Duration = Todo.Duration; if (period.Duration != default) @@ -102,6 +100,6 @@ public override HashSet Evaluate(IDateTime referenceDate, DateTime perio period.Duration = Todo.Duration; } } - return Periods; + return periods; } -} \ No newline at end of file +} diff --git a/Ical.Net/IGetOccurrences.cs b/Ical.Net/IGetOccurrences.cs index 9207612f..836ba45f 100644 --- a/Ical.Net/IGetOccurrences.cs +++ b/Ical.Net/IGetOccurrences.cs @@ -12,13 +12,6 @@ namespace Ical.Net; public interface IGetOccurrences { - /// - /// Clears a previous evaluation, usually because one of the - /// key elements used for evaluation has changed - /// (Start, End, Duration, recurrence rules, exceptions, etc.). - /// - void ClearEvaluation(); - /// /// Returns all occurrences of this component that start on the date provided. /// All components starting between 12:00:00AM and 11:59:59 PM will be @@ -74,4 +67,4 @@ public interface IGetOccurrencesTyped : IGetOccurrences HashSet GetOccurrences(IDateTime startTime, IDateTime endTime) where T : IRecurringComponent; HashSet GetOccurrences(DateTime startTime, DateTime endTime) where T : IRecurringComponent; -} \ No newline at end of file +} diff --git a/Ical.Net/VTimeZoneInfo.cs b/Ical.Net/VTimeZoneInfo.cs index 789615b0..545a9631 100644 --- a/Ical.Net/VTimeZoneInfo.cs +++ b/Ical.Net/VTimeZoneInfo.cs @@ -159,11 +159,6 @@ public virtual IDateTime RecurrenceId set => Properties.Set("RECURRENCE-ID", value); } - public virtual void ClearEvaluation() - { - RecurrenceUtil.ClearEvaluation(this); - } - public virtual HashSet GetOccurrences(IDateTime dt) => RecurrenceUtil.GetOccurrences(this, dt, true); @@ -175,4 +170,4 @@ public virtual HashSet GetOccurrences(IDateTime startTime, IDateTime public virtual HashSet GetOccurrences(DateTime startTime, DateTime endTime) => RecurrenceUtil.GetOccurrences(this, new CalDateTime(startTime), new CalDateTime(endTime), true); -} \ No newline at end of file +}