Nodatime BclDateTimeZone EqualsImpl throws NotImplementedException

The method EqualsImpl

in the Nodatime class BclDateTimeZone

calls a NotImplementedException

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

If the equality test is two ZonedDateTime

that use BclDateTimeZone

, this throws an exception.

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

+3


source to share


2 answers


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

Yup - it is generally very difficult to determine the equality of the zone in general terms. Suppose we have two instances BclDateTimeZone

that carry two different values TimeZoneInfo

... we could:

  • They are said to be not arbitrarily equal, even if they are logically equivalent
  • Compare them by ID (not possible in PCL, which does not support IDs, and is split into Mono, why TimeZoneInfo.Local

    has Local

    IIRC ID )
  • Compare them for equality through history, which is very expensive.


I agree that this is a pain, and I think I plan to remove value equality ZonedDateTime

entirely in Noda Time 2.0 and make ZonedDateTime

use of reference equality.

If you want to compare time zones, a better alternative would probably be to use ZonedEqualityComparer

to indicate how you want them to be compared.

But the inability to compare values ZonedDateTime

for equality when using BCL values ​​is definitely nasty. I raised a bug ; I am preparing version 1.3.1 and I can check if I can fix it instead of waiting for 2.0.

+2


source


After trying to enter failed unit tests to prove this error, I found it difficult to reproduce.

Comparing ZonedDateTime

with BclDateTimeZone

at different offsets is not a problem. Comparison ZonedDateTime

with different is LocalDateTime

not a problem.

I could see from the source that comparison ZonedDateTime

Zone

only comes into play if the tags LocalDateTime

and Offset

are equal.

My problem came when I was using two different references BclDateTimeZone

at the same offset. I did it using DateTimeZoneProviders.Bcl.GetSystemDefault()

one place and BclDateTimeZone.ForSystemDefault()

another. Needless to say, they now call common code.

I have this failed test where I am comparing two ZonedDateTime

with different ones DateTimeZone

at the same offset:



ZonedDateTime dtzOne = new ZonedDateTime(Instant.FromUtc(2014, 11, 11, 21, 00), DateTimeZoneProviders.Bcl.GetZoneOrNull("Greenwich Standard Time"));
ZonedDateTime dtzTwo = new ZonedDateTime(Instant.FromUtc(2014, 11, 11, 21, 00), DateTimeZoneProviders.Bcl.GetZoneOrNull("GMT Standard Time"));

Assert.That(dtzOne, Is.Not.EqualTo(dtzTwo));

      

This test throws an exception:

System.NotImplementedException : The method or operation is not implemented.
   at NodaTime.TimeZones.BclDateTimeZone.EqualsImpl(DateTimeZone zone)
   at NodaTime.DateTimeZone.Equals(DateTimeZone obj)
   at NodaTime.ZonedDateTime.Equals(ZonedDateTime other)

      

I can work around this problem easily, but it is probably worth fixing.

0


source







All Articles