Skip to content

Conversation

@minichma
Copy link
Collaborator

@minichma minichma commented Mar 6, 2025

Several improvements:

  • Remove the seemingly unneeded includeReferenceDateInResults from Evaluate() et al as it shouldn't be needed as the expected behavior is pretty well defined in the RFC. Only exception: What to happen if an RRULE doesn't match DTSTART, in which case we don't include DTSTART as we already didn't before.
  • Introduce new EvaluationOptions type and pass it to Calendar.GetOccurrences() and related
  • Replace the hard-coded RecurrencePatternEvaluator.MaxIncrementCount with a new configuration property EvaluationOptions.MaxIncrementCount.
  • If the limit is hit, raise an MaxIncrementsExceededEvaluationException rather than stopping evaluation silently.

Fixes #747

@codecov
Copy link

codecov bot commented Mar 6, 2025

Codecov Report

Attention: Patch coverage is 67.64706% with 11 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
Ical.Net/CalendarCollection.cs 25% 3 Missing ⚠️
Ical.Net/CalendarComponents/Alarm.cs 0% 2 Missing ⚠️
Ical.Net/Evaluation/RecurrenceUtil.cs 33% 2 Missing ⚠️
Ical.Net/VTimeZoneInfo.cs 0% 2 Missing ⚠️
Ical.Net/Evaluation/RecurringEvaluator.cs 83% 0 Missing and 1 partial ⚠️
Ical.Net/Evaluation/TimeZoneInfoEvaluator.cs 0% 1 Missing ⚠️

❌ Your patch status has failed because the patch coverage (68%) is below the target coverage (80%). You can increase the patch coverage or adjust the target coverage.
❌ Your project status has failed because the head coverage (66%) is below the target coverage (80%). You can increase the head coverage or adjust the target coverage.

Impacted file tree graph

@@         Coverage Diff         @@
##           main   #750   +/-   ##
===================================
  Coverage    66%    66%           
===================================
  Files       105    104    -1     
  Lines      4631   4611   -20     
  Branches   1150   1146    -4     
===================================
- Hits       3055   3047    -8     
+ Misses     1139   1129   -10     
+ Partials    437    435    -2     
Files with missing lines Coverage Δ
Ical.Net/Calendar.cs 70% <100%> (ø)
Ical.Net/CalendarComponents/CalendarEvent.cs 75% <ø> (+<1%) ⬆️
Ical.Net/CalendarComponents/FreeBusy.cs 48% <100%> (ø)
Ical.Net/CalendarComponents/Journal.cs 64% <ø> (+4%) ⬆️
Ical.Net/CalendarComponents/RecurringComponent.cs 66% <100%> (+1%) ⬆️
Ical.Net/CalendarComponents/Todo.cs 66% <100%> (-1%) ⬇️
Ical.Net/DataTypes/PeriodList.cs 87% <100%> (-<1%) ⬇️
Ical.Net/Evaluation/Evaluator.cs 91% <ø> (ø)
Ical.Net/Evaluation/EventEvaluator.cs 88% <100%> (ø)
Ical.Net/Evaluation/RecurrencePatternEvaluator.cs 91% <100%> (+<1%) ⬆️
... and 7 more
🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@minichma minichma marked this pull request as ready for review March 6, 2025 17:19
@minichma minichma requested a review from axunonb March 6, 2025 17:20
@minichma
Copy link
Collaborator Author

minichma commented Mar 6, 2025

@axunonb Please have a look - I think its an improvement. The issues sonarcube is complaining about are legacy, so nothing to fix in this PR. The overall code coverage increase, so should be ok from that standpoint too.

TBD: The default for MaxIncrementCount changed from previously 1000 to indefinite. What do you think? (Should probably be mentioned in the release notes.)

Constructing the options instance might be better to be done via a Builder pattern, so we'd be more flexible when extending it in the future without risking breaking changes. We could also default to some default instance rather than passing null as the default but this would require some extra thoughts that I don't really have the time for right now. A default instance should probably be immutable, so the type as a whole should be immutable, which again would suggest using a Builder pattern. TBD


public override IEnumerable<Period> Evaluate(CalDateTime referenceDate, CalDateTime? periodStart, CalDateTime? periodEnd, bool includeReferenceDateInResults)
public override IEnumerable<Period> Evaluate(CalDateTime referenceDate, CalDateTime? periodStart, CalDateTime? periodEnd, EvaluationOptions options)
{
Copy link
Collaborator

Choose a reason for hiding this comment

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

No coverage, wondering when this method would get called

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Within Ical.Net not at all I assume, because the only place where it could be used is RecurringEvaluator, where we use Recurrable.RecurrenceDates.GetAllPeriodsByKind(). Remove?!

/// If the specified number of increments is exceeded without finding a recurrence, an
/// exception of type <see cref="Ical.Net.Evaluation.MaxIncrementsExceededEvaluationException"/> will be thrown.
/// </remarks>
public int? MaxIncrementCount { get; set; }
Copy link
Collaborator

@axunonb axunonb Mar 6, 2025

Choose a reason for hiding this comment

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

As it's not a counter, would sth. like NoPatternMatchLimit be more intuitive?
Likewise sth. like NoPatternMatchLimitExceededException?
and TestMaxIncrementCount method

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Certainly better!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Your new naming is the best

@axunonb
Copy link
Collaborator

axunonb commented Mar 6, 2025

Looks great!

TBD: The default for MaxIncrementCount changed from previously 1000 to indefinite.

We already had exchanged some thoughts about indefinite, so let's use it as the default, but add an explicit hints in our xmldoc about the risk. Same with release notes, sure.

options instance might be better to be done via a Builder pattern

Balancing benefit and related effort the current way should be appropriate.

MaxIncrementCount

Pls. consider the comments above.

@minichma minichma force-pushed the work/minichma/feature/evaluation_config branch from 4047773 to aa71c7f Compare March 8, 2025 14:23
@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 8, 2025

@minichma
Copy link
Collaborator Author

minichma commented Mar 8, 2025

@axunonb Thought a little about the naming, now choose MaxUnmatchedIncrementsLimit and EvaluationLimitExceededException, what do you think?

@minichma minichma requested a review from axunonb March 8, 2025 14:25
Copy link
Collaborator

@axunonb axunonb left a comment

Choose a reason for hiding this comment

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

Perfectr, thank you!

@minichma minichma merged commit fd4e75a into main Mar 9, 2025
6 of 8 checks passed
@minichma minichma deleted the work/minichma/feature/evaluation_config branch March 9, 2025 08:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Introduce EvaluationOptions for params like MaxIncrementCount

3 participants