The equals method compares three things on DateTime: - the long milliseconds value - the chronology - the time zone (within the chronology)
The time zone comparison is done based on the time zone id, such as America/Los_Angeles. However, the toString() only output the time zone offset (eg -07:00) which can be the same for multiple zone ids. This probably explains the difference with the command line - it uses a different time zone environment variable. When you switch to explicitly taking control of the zone you solve the problem, because you are forcing both objects to have the same zone. At a guess, I'd suggest one part of your app is using 'Los_Angeles' and another is using '-07:00'. To check, simply toString the chronology of each object. Stephen Kevin Bourrillion wrote: > There's something weird about comparing DateTimes for equality. > Sometimes the equality comparison can fail even though the toString() > of each comes out absolutely identical. > > junit.framework.AssertionFailedError: > expected:<2004-09-27T06:00:00.000-07:00> but > was:<2004-09-27T06:00:00.000-07:00> > > This equals/toString mismatch in and of itself is a confusing > situation. But I'm also confused by the remedy -- when I change one > of the DateTimes from the one-arg constructor to the two (passing > America/Los_Angeles for the zone), that fixes it. But it already knew > the time zone before (see the -07:00 in the output above)! Whaa? > > And I'm even further confused as to why this only fails when I run the > test from within my IDE, but never at the command-line. Some System > property or environment variable or _something_ must be influencing it > somehow?? > > thanks, > K > > > > > >------------------------------------------------------------------------ > >_______________________________________________ >Joda-interest mailing list >[email protected] >https://lists.sourceforge.net/lists/listinfo/joda-interest > > _______________________________________________ Joda-interest mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/joda-interest
