Hi there,
I just stumbled across some interesting thing that was embedded in a longer story in a customer project which migrates from VisualAge to VA Smalltalk. In order to decide whether an object can or must be updated in the database, they want to find out whether a Timestamp is in the same second as a newly created one. Thus updates shouldn't be possible more often than once a second.
The old implementation modified existing timestamps by setting the millieconds to zero. (well, it did something more complicated than that, but...).
So I suggested we just use totalSeconds of two timestamps to find out whether they represent the same second. And looking at totalSeconds in AbtTimestamp, that looks just rigt. It returns the Date's asSeconds plus the Time's asSeconds. So far so good.
But things went crazy. Two Timestamps that had been equal for years were not any more.
I dug down a little deeper and found this:
Time>>#asSeconds
"Answer an Integer that is the number of
seconds since midnight of the receiver."
^millisecondsFromMidnight + 500 // 1000
What....? The seconds are ROUNDED? So if we use #totalSeconds to compare two AbtTimestamps they are only equal if they are in the same half of a second?
I would say this is not only surprising, it even doesn't match well with the method's comment. And I'd go so far as to say it is wrong. I would assume that at 18:12:34.953 the number of seconds since midnight is the same number as at 18:12:34.000 and not one more, just because the second is always over.
Does this make sense at all? What is the idea behind this?
Joachim