Nodatime BclDateTimeZone EqualsImpl throws NotImplementedException

The EqualsImpl method in the Nodatime BclDateTimeZone class throws a NotImplementedException. It is documented to behave in this way - is there a reason for this?

If testing equality of two ZonedDateTimes that use a BclDateTimeZone this causes the exception to be thrown.

Is this a bug, it doesn't seem right?

Jon Skeet
people
quotationmark

It is documented to behave in this way - is there a reason for this?

Yup - it's basically very hard to determine zone equality in a general way. Suppose we have two BclDateTimeZone instances which wrap two distinct TimeZoneInfo values... we could:

  • Say they're not equal arbitrarily, even if they are logically equivalent
  • Compare them by ID (impossible in the PCL which doesn't support IDs, and broken under Mono why TimeZoneInfo.Local has an ID of Local IIRC)
  • Compare them for equality through history, which is very costly

I agree that it's a pain, and I think I'm planning on removing value equality on ZonedDateTime entirely in Noda Time 2.0, and make ZonedDateTime use reference equality.

If you want to compare time zones, a better alternative is likely to be the use of ZonedEqualityComparer to specify how you want them to be compared.

But the inability to compare ZonedDateTime values for equality when using BCL values is definitely nasty. I've raised a bug for that; I'm preparing a 1.3.1 release, and I might see if I can fix it there, rather than you having to wait for 2.0.

people

See more on this question at Stackoverflow