Follow up of the discussion in https://github.com/ical-org/ical.net/pull/864/files#r2359270375
Calendar.GetOccurrences() is expected not to return duplicate occurrences, so it uses OrderedDistinct() for removing duplicates. The operator is used instead of just .Distinct() for performance reasons because it leverages the assumed fact that the sequence of occurrences is ordered. Due to the order it assumes that duplicate values are always returned by the enumerable adjacent to each other but this is not necessarily the case. Instances of Occurrence are considered equal if both, the Period and the Source are equal. However, the sequence of occurrences is only ordered by Occurrence.Period.StartTime but not by the other properties that are used for determining equality.
In particular
Period.Equals compares all, a Period's Start, End and Duration but CompareTo only compares the StartTime property
Occurrence.Equals compares the Period and Source property using Object.Equals while CompareTo only compares the Period and therefore only the Period.StartTime property.
(also compare this discussion https://github.com/orgs/ical-org/discussions/606#discussioncomment-11867080)
IMHO it is not clear what the best is to solve this issue. I see two main approaches:
- Fix
Equals vs CompareTo so they are consistent (i.e. equality of Equals matches that of CompareTo() == 0
- Let
OrderedDistinct() deal with non-perfect ordering.
While having a consistent implementation of Equals and CompareTo, this might not always be possible (as discussed here), so probably 1) will not be sufficient and 2) will be needed.
Ical.Net 5.1.0
Follow up of the discussion in https://github.com/ical-org/ical.net/pull/864/files#r2359270375
Calendar.GetOccurrences()is expected not to return duplicate occurrences, so it usesOrderedDistinct()for removing duplicates. The operator is used instead of just.Distinct()for performance reasons because it leverages the assumed fact that the sequence of occurrences is ordered. Due to the order it assumes that duplicate values are always returned by the enumerable adjacent to each other but this is not necessarily the case. Instances ofOccurrenceare considered equal if both, thePeriodand theSourceare equal. However, the sequence of occurrences is only ordered byOccurrence.Period.StartTimebut not by the other properties that are used for determining equality.In particular
Period.Equalscompares all, a Period's Start, End and Duration butCompareToonly compares theStartTimepropertyOccurrence.Equalscompares thePeriodandSourceproperty usingObject.EqualswhileCompareToonly compares thePeriodand therefore only thePeriod.StartTimeproperty.(also compare this discussion https://github.com/orgs/ical-org/discussions/606#discussioncomment-11867080)
IMHO it is not clear what the best is to solve this issue. I see two main approaches:
EqualsvsCompareToso they are consistent (i.e. equality ofEqualsmatches that ofCompareTo() == 0OrderedDistinct()deal with non-perfect ordering.While having a consistent implementation of Equals and CompareTo, this might not always be possible (as discussed here), so probably 1) will not be sufficient and 2) will be needed.
Ical.Net 5.1.0