[squeak-dev] Same Dates are not equal

David T. Lewis lewis at mail.msen.com
Sun Jan 23 20:23:44 UTC 2022


Hello J??rg,

On Sun, Jan 23, 2022 at 07:35:24PM +0100, J??rg Belger wrote:
> Hello,
> 
> I found the following bug in Squeak, the two Dates should be normally the same, but the comparison gives <false>. 
> 
> 	| timestamp firstDate secondDate |
> 	timestamp := TimeStamp now.
> 	firstDate := timestamp asDate.
> 	secondDate := Date newDay: firstDate day month: firstDate monthIndex year: firstDate year.
> 	firstDate = secondDate
> 
> This happens because the <start> timestamp is not equal and differs in nanosecond value.
>

As Jaromir suggested, the behavior is intentional (not a bug),
although it is arguably also not right.

The confusion is because we model Date as a Duration, so two
Date instances should be equal only of their actual durations
are the same. The workaround is to force the dates to UTC if
they are to be compared.

There are actually a couple of problems with modeling Date as
a Duration. You have discovered one of them. The other reason
is that our implementation assumes a Date to be 24 hours in
duration, which is wrong if you want the Date to represent
the date in your local time zone. Due to daylight savings time
conventions, a date may be 23 hours or 25 hours in duration,
and adding one day to an instance of Date will thus sometimes
give the wrong local time representation.

Dave



More information about the Squeak-dev mailing list