I've implemented an IEqualityComparer<DateTime>
which can compare two dates based on a tolerance value in milliseconds. If the difference between the two is less than the tolerance, they should be treated as equal.
The Equals
side is almost trivial to implement, however I have really no idea how I could implement the GetHashcode
to cooperate with the equality comparison.
The problem ccan be generalized for numbers as well: given two double
and a delta value, a similar equality comparer could be implemented and the similar GetHashcode
difficulties would arise.
Any idea would be appreciated.
EDIT
I know such an equality comparer is kind of tricky because such an equality operator would not be a transitive relation for example. Still, I'd love to hear some possible ideas or alternatives.