Skip to content

Commit 124cb51

Browse files
committed
RecurrencePatternEvaluator: Simplify inner inverval loop complexity.
1 parent 8eedb91 commit 124cb51

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

Ical.Net/Evaluation/RecurrencePatternEvaluator.cs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ private IEnumerable<DateTime> GetDates(CalDateTime seed, CalDateTime? periodStar
141141
return EnumerateDates(originalDate, seedCopy, periodStartDt, periodEndDt, maxCount, pattern);
142142
}
143143

144-
private IEnumerable<DateTime> EnumerateDates(DateTime originalDate, DateTime seedCopy, DateTime? periodStart, DateTime? periodEnd, int maxCount, RecurrencePattern pattern)
144+
private IEnumerable<DateTime> EnumerateDates(DateTime originalDate, DateTime intervalRefTime, DateTime? periodStart, DateTime? periodEnd, int maxCount, RecurrencePattern pattern)
145145
{
146146
var expandBehavior = RecurrenceUtil.GetExpandBehaviorList(pattern);
147147

@@ -153,16 +153,10 @@ private IEnumerable<DateTime> EnumerateDates(DateTime originalDate, DateTime see
153153
var coarseUntil = pattern.Until?.Value.AddDays(1);
154154

155155
var noCandidateIncrementCount = 0;
156-
DateTime? candidate = null;
157156
var dateCount = 0;
158157
while (maxCount < 0 || dateCount < maxCount)
159158
{
160-
if (seedCopy > coarseUntil)
161-
{
162-
break;
163-
}
164-
165-
if (candidate > periodEnd)
159+
if (intervalRefTime > coarseUntil)
166160
{
167161
break;
168162
}
@@ -173,19 +167,19 @@ private IEnumerable<DateTime> EnumerateDates(DateTime originalDate, DateTime see
173167
}
174168

175169
//No need to continue if the seed is after the periodEnd
176-
if (seedCopy > periodEnd)
170+
if (intervalRefTime > periodEnd)
177171
{
178172
break;
179173
}
180174

181-
var candidates = GetCandidates(seedCopy, pattern, expandBehavior);
175+
var candidates = GetCandidates(intervalRefTime, pattern, expandBehavior);
182176
if (candidates.Count > 0)
183177
{
184178
noCandidateIncrementCount = 0;
185179

186180
foreach (var t in candidates.Where(t => t >= originalDate))
187181
{
188-
candidate = t;
182+
var candidate = t;
189183

190184
// candidates MAY occur before periodStart
191185
// For example, FREQ=YEARLY;BYWEEKNO=1 could return dates
@@ -204,7 +198,7 @@ private IEnumerable<DateTime> EnumerateDates(DateTime originalDate, DateTime see
204198

205199
// UNTIL is applied outside of this method, after TZ conversion has been applied.
206200

207-
yield return candidate.Value;
201+
yield return candidate;
208202
dateCount++;
209203
}
210204
}
@@ -217,7 +211,7 @@ private IEnumerable<DateTime> EnumerateDates(DateTime originalDate, DateTime see
217211
}
218212
}
219213

220-
IncrementDate(ref seedCopy, pattern, pattern.Interval);
214+
IncrementDate(ref intervalRefTime, pattern, pattern.Interval);
221215
}
222216
}
223217

0 commit comments

Comments
 (0)