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
10 changes: 5 additions & 5 deletions Ical.Net/DataTypes/CalDateTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ private void CopyFrom(CalDateTime calDt)
_tzId = calDt._tzId;
}

public bool Equals(CalDateTime other) => this == other;
public bool Equals(CalDateTime? other) => this == other;

/// <inheritdoc/>
public override bool Equals(object? obj)
Expand Down Expand Up @@ -598,22 +598,22 @@ public CalDateTime AddDays(int days)
/// <summary>
/// Returns <see langword="true"/> if the current <see cref="CalDateTime"/> instance is less than <paramref name="dt"/>.
/// </summary>
public bool LessThan(CalDateTime dt) => this < dt;
public bool LessThan(CalDateTime? dt) => this < dt;

/// <summary>
/// Returns <see langword="true"/> if the current <see cref="CalDateTime"/> instance is greater than <paramref name="dt"/>.
/// </summary>
public bool GreaterThan(CalDateTime dt) => this > dt;
public bool GreaterThan(CalDateTime? dt) => this > dt;

/// <summary>
/// Returns <see langword="true"/> if the current <see cref="CalDateTime"/> instance is less than or equal to <paramref name="dt"/>.
/// </summary>
public bool LessThanOrEqual(CalDateTime dt) => this <= dt;
public bool LessThanOrEqual(CalDateTime? dt) => this <= dt;

/// <summary>
/// Returns <see langword="true"/> if the current <see cref="CalDateTime"/> instance is greater than or equal to <paramref name="dt"/>.
/// </summary>
public bool GreaterThanOrEqual(CalDateTime dt) => this >= dt;
public bool GreaterThanOrEqual(CalDateTime? dt) => this >= dt;

/// <summary>
/// Compares the current instance with another <see cref="CalDateTime"/> object and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other CalDateTime.
Expand Down
1 change: 1 addition & 0 deletions Ical.Net/Evaluation/EvaluationException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Licensed under the MIT license.
//

#nullable enable
using System;

namespace Ical.Net.Evaluation;
Expand Down
1 change: 1 addition & 0 deletions Ical.Net/Evaluation/EvaluationLimitExceededException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Licensed under the MIT license.
//

#nullable enable
namespace Ical.Net.Evaluation;

/// <summary>
Expand Down
4 changes: 3 additions & 1 deletion Ical.Net/Evaluation/EvaluationOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
// Licensed under the MIT license.
//

#nullable enable
namespace Ical.Net.Evaluation;

public class EvaluationOptions
{
/// <summary>
Expand All @@ -12,7 +14,7 @@ public class EvaluationOptions
/// </summary>
/// <remarks>
/// This option only applies to the evaluation of RecurrencePatterns.
///
/// <para/>
/// If the specified number of increments is exceeded without finding a recurrence, an
/// exception of type <see cref="Ical.Net.Evaluation.EvaluationLimitExceededException"/> will be thrown.
/// </remarks>
Expand Down
2 changes: 1 addition & 1 deletion Ical.Net/Evaluation/Evaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ protected void IncrementDate(ref CalDateTime dt, RecurrencePattern pattern, int
}
}

public abstract IEnumerable<Period> Evaluate(CalDateTime referenceDate, CalDateTime? periodStart, CalDateTime? periodEnd, EvaluationOptions options);
public abstract IEnumerable<Period> Evaluate(CalDateTime referenceDate, CalDateTime? periodStart, CalDateTime? periodEnd, EvaluationOptions? options);
}
2 changes: 1 addition & 1 deletion Ical.Net/Evaluation/IEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ public interface IEvaluator
/// A sequence of <see cref="Ical.Net.DataTypes.Period"/> objects for
/// each date/time when this item occurs/recurs.
/// </returns>
IEnumerable<Period> Evaluate(CalDateTime referenceDate, CalDateTime? periodStart, CalDateTime? periodEnd, EvaluationOptions options);
IEnumerable<Period> Evaluate(CalDateTime referenceDate, CalDateTime? periodStart, CalDateTime? periodEnd, EvaluationOptions? options);
}
25 changes: 13 additions & 12 deletions Ical.Net/Evaluation/RecurrenceUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,20 @@
// Licensed under the MIT license.
//

using System;
#nullable enable
using System.Collections.Generic;
using System.Linq;
using Ical.Net.CalendarComponents;
using Ical.Net.DataTypes;
using Ical.Net.Utility;

namespace Ical.Net.Evaluation;

internal class RecurrenceUtil
{
public static IEnumerable<Occurrence> GetOccurrences(IRecurrable recurrable, CalDateTime dt, EvaluationOptions options = default) => GetOccurrences(recurrable,
public static IEnumerable<Occurrence> GetOccurrences(IRecurrable recurrable, CalDateTime dt, EvaluationOptions? options = null) => GetOccurrences(recurrable,
new CalDateTime(dt.Date), new CalDateTime(dt.Date.AddDays(1)), options);

public static IEnumerable<Occurrence> GetOccurrences(IRecurrable recurrable, CalDateTime periodStart, CalDateTime periodEnd, EvaluationOptions options = default)
public static IEnumerable<Occurrence> GetOccurrences(IRecurrable recurrable, CalDateTime? periodStart, CalDateTime? periodEnd, EvaluationOptions? options = null)
{
var evaluator = recurrable.Evaluator;
if (evaluator == null || recurrable.Start == null)
Expand All @@ -43,7 +42,9 @@ from p in periods
let endTime = p.EndTime ?? p.StartTime
where
(((periodStart == null) || endTime.GreaterThan(periodStart)) && ((periodEnd == null) || p.StartTime.LessThan(periodEnd)) ||
(periodStart.Equals(periodEnd) && p.StartTime.LessThanOrEqual(periodStart) && endTime.GreaterThan(periodEnd))) || //A period that starts at the same time it ends
(periodStart != null && periodStart.Equals(periodEnd)
&& p.StartTime.LessThanOrEqual(periodStart)
&& endTime.GreaterThan(periodEnd))) || //A period that starts at the same time it ends
(p.StartTime.Equals(endTime) && p.StartTime.Equals(periodStart)) //An event that starts at the same time it ends
select new Occurrence(recurrable, p);

Expand All @@ -56,16 +57,16 @@ from p in periods
switch (p.Frequency)
{
case FrequencyType.Minutely:
return new bool?[] { false, null, false, false, false, false, false, true, false };
return [false, null, false, false, false, false, false, true, false];
case FrequencyType.Hourly:
return new bool?[] { false, null, false, false, false, false, true, true, false };
return [false, null, false, false, false, false, true, true, false];
case FrequencyType.Daily:
return new bool?[] { false, null, null, false, false, true, true, true, false };
return [false, null, null, false, false, true, true, true, false];
case FrequencyType.Weekly:
return new bool?[] { false, null, null, null, true, true, true, true, false };
return [false, null, null, null, true, true, true, true, false];
case FrequencyType.Monthly:
{
var row = new bool?[] { false, null, null, true, true, true, true, true, false };
bool?[] row = [false, null, null, true, true, true, true, true, false];

// Limit if BYMONTHDAY is present; otherwise, special expand for MONTHLY.
if (p.ByMonthDay.Count > 0)
Expand All @@ -77,7 +78,7 @@ from p in periods
}
case FrequencyType.Yearly:
{
var row = new bool?[] { true, true, true, true, true, true, true, true, false };
bool?[] row = [true, true, true, true, true, true, true, true, false];

// Limit if BYYEARDAY or BYMONTHDAY is present; otherwise,
// special expand for WEEKLY if BYWEEKNO present; otherwise,
Expand All @@ -91,7 +92,7 @@ from p in periods
return row;
}
default:
return new bool?[] { false, null, false, false, false, false, false, false, false };
return [false, null, false, false, false, false, false, false, false];
}
}
}
1 change: 0 additions & 1 deletion Ical.Net/Evaluation/RecurringEvaluator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
//

#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using Ical.Net.CalendarComponents;
Expand Down
Loading