Hi there,
I have some nice effects due to the fact that Time and AbtTimestamp perform strange roundings on their values of seconds. This is especially interesting when sending Time and AbtTimestamp instances over TCP/IP or persisting them in a file. What am I talking about:
Loot at Time>>#asSeconds
"Answer an Integer that is the number of
seconds since midnight of the receiver."
^millisecondsFromMidnight + 500 // 1000
Well, to my understanding, this method will answer a wrong number of seconds every time a second is in its second half. And that's exactly what's happening: if we persist the following (the method nextPut and getNext are just examples, but you get the idea):
aStream nextPut: myOriginalTime asSeconds
and later we create a Time instance by using:
myCopyTime := Time fromSeconds: aStream getNext
the following test will "randomly" be true or false, because the times differ by 1 second:
myCopyTime = my OriginalTime
I know I could use milliseconds, but not every imlementation of Time (look at VisualWorks, for example) will accept milliseconds. And for those, a wrongly rounded number of seconds is definitely wrong...
My expectation fro asSeconds would be that asSeconds returns me the number of fully passed seconds since midnight and not a random number between (number of fully passed seconds) and (number of fully passed seconds plus one)
The problem exists for timestamps as well, and there it is more of a problem, because we often use Timestamps for taking very exact times or for uniqueness of IDs...
Why does #asSeconds add 500 msecs before cutting off the microseconds???
Any thoughts?
Joachim