diff --git a/Ical.Net.Tests/TodoTest.cs b/Ical.Net.Tests/TodoTest.cs index 1e5a5f03c..239b98cf8 100644 --- a/Ical.Net.Tests/TodoTest.cs +++ b/Ical.Net.Tests/TodoTest.cs @@ -3,9 +3,11 @@ // Licensed under the MIT license. // +using System; using System.Collections; using System.Collections.Generic; using System.Linq; +using Ical.Net.CalendarComponents; using Ical.Net.DataTypes; using NUnit.Framework; @@ -218,4 +220,24 @@ public void Todo7_1() occurrences, Has.Count.EqualTo(items.Count)); } + + [Test, Category("Todo")] + public void Todo_WithFutureStart_AndNoDuration_ShouldSucceed() + { + var today = CalDateTime.Today; + + var todo = new Todo + { + Start = today, + RecurrenceRules = [new RecurrencePattern("FREQ=DAILY")] + }; + + // periodStart is in the future, so filtering the first occurrence will also require + // looking at the todo's duration, which is unset/null. It must therefore be ignored. + var firstOccurrence = todo.GetOccurrences(today.AddDays(2)).FirstOrDefault(); + + Assert.That(firstOccurrence, Is.Not.Null); + Assert.That(firstOccurrence.Period.StartTime, Is.Not.Null); + Assert.That(firstOccurrence.Period.Duration, Is.Null); + } } diff --git a/Ical.Net/Evaluation/RecurrenceUtil.cs b/Ical.Net/Evaluation/RecurrenceUtil.cs index e5e9c01fd..deb6ad3cc 100644 --- a/Ical.Net/Evaluation/RecurrenceUtil.cs +++ b/Ical.Net/Evaluation/RecurrenceUtil.cs @@ -39,7 +39,7 @@ from p in periods let effectiveEndTime = p.EffectiveEndTime where p.StartTime.GreaterThanOrEqual(periodStart) - || effectiveEndTime.GreaterThan(periodStart) + || ((effectiveEndTime != null) && effectiveEndTime.GreaterThan(periodStart)) select p; }