Skip to content
Merged
Show file tree
Hide file tree
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
18 changes: 18 additions & 0 deletions Ical.Net.Tests/RecurrenceTests_From_Issues.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Linq;
using Ical.Net.CalendarComponents;
using Ical.Net.DataTypes;
using Ical.Net.Evaluation;
using NUnit.Framework;

namespace Ical.Net.Tests;
Expand Down Expand Up @@ -513,4 +514,21 @@ public void Except_Tuesday_Thursday_Saturday_Sunday()
}
});
}

[Test]
public void Weekly_ByDay_ByMonth()
{
// Bug #879

var rp = new RecurrencePattern("FREQ=WEEKLY;BYDAY=SU,MO,TU,WE,TH,FR;BYMONTH=5,6,7,8,9");
var rpe = new RecurrencePatternEvaluator(rp);

var referenceDate = new CalDateTime(2025, 11, 07, 0, 0, 0, "Central Standard Time");
var recurringPeriods = rpe.Evaluate(referenceDate, null, null);

var result = recurringPeriods.FirstOrDefault()?.StartTime;

var expected = new CalDateTime(2026, 05, 01, 0, 0, 0, "Central Standard Time");
Assert.That(result, Is.EqualTo(expected));
}
}
13 changes: 12 additions & 1 deletion Ical.Net/Evaluation/RecurrencePatternEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,18 @@ private static IEnumerable<CalDateTime> GetMonthVariants(IEnumerable<CalDateTime
}

// Limit behavior
return dates.Where(date => pattern.ByMonth.Contains(date.Month));
if (pattern.Frequency == FrequencyType.Weekly)
{
// The dates here represent weeks, with each date being the
// start of a week except for the initial reference date.
// Return weeks that have any day within BYMONTH.
return dates.Where(date => pattern.ByMonth.Contains(date.Month)
|| pattern.ByMonth.Contains(date.AddDays(6).Month));
}
else
{
return dates.Where(date => pattern.ByMonth.Contains(date.Month));
}
}

/// <summary>
Expand Down
Loading