ical.net icon indicating copy to clipboard operation
ical.net copied to clipboard

An error occurred while comparing two IDateTime values.

Open l4nk4b3l opened this issue 7 years ago • 1 comments

I found an error comparing two dates with different formats.

bei Ical.Net.DataTypes.CalDateTime.CompareTo(IDateTime dt) bei System.Collections.Generic.GenericComparer1.Compare(T x, T y) bei System.Linq.EnumerableSorter2.CompareKeys(Int32 index1, Int32 index2) bei System.Linq.EnumerableSorter1.QuickSort(Int32[] map, Int32 left, Int32 right) bei System.Linq.EnumerableSorter1.Sort(TElement[] elements, Int32 count) bei System.Linq.OrderedEnumerable1.<GetEnumerator>d__1.MoveNext() bei System.Collections.Generic.List1..ctor(IEnumerable1 collection) bei System.Linq.Enumerable.ToList[TSource](IEnumerable1 source)

Example Code: `List<Ical.Net.DataTypes.CalDateTime> dates = new List<Ical.Net.DataTypes.CalDateTime>(); dates.Add(new Ical.Net.DataTypes.CalDateTime(DateTime.Today)); dates.Add(new Ical.Net.DataTypes.CalDateTime(DateTime.Today.ToUniversalTime()));

var datesSorted = dates.OrderBy(d => d).ToList();`

l4nk4b3l avatar Jan 12 '18 10:01 l4nk4b3l

Issue still exists in 4.1.11. The problem appears if the compared dates represent the same instant but in different timezones. In this case the CalDateTime.CompareTo considers the values neither as greater, nor as less nor as equal, which results in throw new Exception("An error occurred while comparing two IDateTime values.");. See here.

Expected: Let CalDateTime.CompareTo consider two values as equal if they represent the same instant in different timezones.

minichma avatar May 11 '20 16:05 minichma