Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions Ical.Net/Evaluation/RecurrencePatternEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -729,12 +729,12 @@ private static IEnumerable<CalDateTime> GetAbsWeekDaysMonthly(CalDateTime date,

for (var i = 0; i < occurrenceCount; i++)
{
if (byWeekNoNormalized == null || byWeekNoNormalized.Contains(Calendar.GetIso8601WeekOfYear(date, pattern.FirstDayOfWeek)))
var matchesWeekNo = byWeekNoNormalized == null || byWeekNoNormalized.Contains(Calendar.GetIso8601WeekOfYear(date, pattern.FirstDayOfWeek));
var matchesMonth = pattern.ByMonth.Count == 0 || pattern.ByMonth.Contains(date.Month);

if (matchesWeekNo && matchesMonth)
Comment on lines +732 to +735
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The refactoring eliminates the short-circuit behavior of the original nested if statements. Both conditions are now evaluated unconditionally on every iteration, even when the first condition fails. This means Calendar.GetIso8601WeekOfYear is called even when byWeekNoNormalized is null, and pattern.ByMonth.Contains is checked even when matchesWeekNo is false. Consider keeping the nested structure or using a single combined if condition without intermediate variables to preserve the original short-circuit evaluation and avoid unnecessary computations in the loop.

Suggested change
var matchesWeekNo = byWeekNoNormalized == null || byWeekNoNormalized.Contains(Calendar.GetIso8601WeekOfYear(date, pattern.FirstDayOfWeek));
var matchesMonth = pattern.ByMonth.Count == 0 || pattern.ByMonth.Contains(date.Month);
if (matchesWeekNo && matchesMonth)
if ((byWeekNoNormalized == null || byWeekNoNormalized.Contains(Calendar.GetIso8601WeekOfYear(date, pattern.FirstDayOfWeek)))
&& (pattern.ByMonth.Count == 0 || pattern.ByMonth.Contains(date.Month)))

Copilot uses AI. Check for mistakes.
{
if (pattern.ByMonth.Count == 0 || pattern.ByMonth.Contains(date.Month))
{
yield return date;
}
yield return date;
}

date = date.AddDays(7);
Expand Down Expand Up @@ -765,12 +765,12 @@ private static IEnumerable<CalDateTime> GetAbsWeekDaysWeekly(CalDateTime date, R
// It's the 53rd week of the year, but all others are 1st week number.
while (currentWeekNo == weekNo || (nextWeekNo < weekNo && currentWeekNo == nextWeekNo && pattern.Frequency == FrequencyType.Weekly))
{
if (byWeekNoNormalized == null || byWeekNoNormalized.Contains(currentWeekNo))
var matchesWeekNo = byWeekNoNormalized == null || byWeekNoNormalized.Contains(currentWeekNo);
var matchesMonth = pattern.ByMonth.Count == 0 || pattern.ByMonth.Contains(date.Month);

if (matchesWeekNo && matchesMonth)
{
if (pattern.ByMonth.Count == 0 || pattern.ByMonth.Contains(date.Month))
{
yield return date;
}
yield return date;
}

date = date.AddDays(7);
Expand Down
Loading