[BUG] Chronology DateAndTime class>>now returns incorrect time

Avi Bryant avi at beta4.com
Sun Feb 22 03:34:52 UTC 2004


On Feb 21, 2004, at 10:04 AM, Timothy Rowledge wrote:

>
> On Feb 21, 2004, at 6:47 AM, Hans-Martin Mosner wrote:
>> The problem is that DateAndTime class>>now incorrectly assumes that 
>> the millisecondClockValue only counts from 0 to 999 within one step 
>> of the totalSeconds.
>> But the millisecondClockValue just counts up from the system startup, 
>> and is not even synchronized to totalSeconds (so taking 
>> millisecondClockValue\\1000 does not help).
> Oh good grief. That was a really silly assumption on somebody's part.

Of course it is possible, if you're willing to wait for it, to 
calibrate against the millisecondClockValue.  This seems to work pretty 
well:

getMillisecondOffset
    |lastSecond|
    lastSecond := Time totalSeconds.
    [lastSecond = Time totalSeconds]
        whileTrue: [(Delay forMilliseconds: 1) wait].
    ^ Time millisecondClockValue \\ 1000.

If we wanted greater accuracy we could average over a longer period of 
time.  I guess if we forked off a process that did this for a few 
seconds when we started the image, we could get fairly accurate 
millisecond precision from then on...




More information about the Squeak-dev mailing list