Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ordering of week numbers should not matter #513

Merged
merged 1 commit into from
Apr 10, 2021
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
17 changes: 17 additions & 0 deletions net-core/Ical.Net.CoreUnitTests/RecurrenceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,23 @@ public void YearlyByDay1()
);
}

/// <summary>
/// Ordering of byweekno should not matter
/// </summary>
[Test, Category("Recurrence")]
public void WeekNoOrderingShouldNotMatter()
{
var start = new DateTime(2019, 1, 1);
var end = new DateTime(2019, 12, 31);
var rpe1 = new RecurrencePatternEvaluator(new RecurrencePattern("FREQ=YEARLY;WKST=MO;BYDAY=MO;BYWEEKNO=1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53"));
var rpe2 = new RecurrencePatternEvaluator(new RecurrencePattern("FREQ=YEARLY;WKST=MO;BYDAY=MO;BYWEEKNO=53,51,49,47,45,43,41,39,37,35,33,31,29,27,25,23,21,19,17,15,13,11,9,7,5,3,1"));

var recurringPeriods1 = rpe1.Evaluate(new CalDateTime(start), start, end, false);
var recurringPeriods2 = rpe2.Evaluate(new CalDateTime(start), start, end, false);

Assert.AreEqual(recurringPeriods1.Count, recurringPeriods2.Count);
}

/// <summary>
/// See Page 123 of RFC 2445 - RRULE:FREQ=YEARLY;BYWEEKNO=20;BYDAY=MO
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion net-core/Ical.Net/Evaluation/RecurrencePatternEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,9 @@ private List<DateTime> GetWeekNoVariants(List<DateTime> dates, RecurrencePattern
var weekNoDates = new List<DateTime>();
foreach (var t in dates)
{
var date = t;
foreach (var weekNo in pattern.ByWeekNo)
{
var date = t;
// Determine our current week number
var currWeekNo = Calendar.GetWeekOfYear(date, CalendarWeekRule.FirstFourDayWeek, pattern.FirstDayOfWeek);
while (currWeekNo > weekNo)
Expand Down