'From Squeak3.10beta of 22 July 2007 [latest update: #7159] on 23 May 2008 at 2:40:59 pm'! "Change Set: 7171subsecondClockAndSecondsAsInteger-M7036-klc Date: 23 May 2008 Author: Ken Causey This changeset covers two time related issues and includes a test for each of them. 1. An earlier update inadvertently removed support for subsecond precision in DateAndTime. This is added back. 2. Related to the added support for subsecond precision Duration>>seconds started returning fractional seconds which was deemed to be against the protocol. The calculation that took nanoseconds into account was removed."! !DateAndTime class methodsFor: 'ansi protocol' stamp: 'KLC 5/9/2008 20:13'! now | nanoTicks msm | nanoTicks := (msm := self milliSecondsSinceMidnight) * 1000000. (LastTick < nanoTicks) ifTrue: [ LastTick := nanoTicks. ^ self todayAtMilliSeconds: msm]. LastTickSemaphore critical: [ LastTick _ LastTick + 1. ^ self todayAtNanoSeconds: LastTick] " [ 10000 timesRepeat: [ self now. ] ] timeToRun / 10000.0 . If calls to DateAndTime-c-#now are within a single millisecond the semaphore code to ensure that (self now <= self now) slows things down considerably by a factor of about 20. The actual speed of a single call to DateAndTime-now in milliseconds is demonstrated by the unguarded method below. [ 100000 timesRepeat: [ self todayAtMilliSeconds: (self milliSecondsSinceMidnight) ] ] timeToRun / 100000.0 . 0.00494 0.00481 0.00492 0.00495 " ! ! !DateAndTimeTest methodsFor: 'Tests' stamp: 'KLC 5/9/2008 20:37'! testPrecision "Verify that the clock is returning a value with accuracy of better than 1 second. For now it seems sufficient to get two values and verify they are not the same." self assert: (DateAndTime now ~= DateAndTime now) ! ! !Duration methodsFor: 'ansi protocol' stamp: 'KLC 5/12/2008 13:42'! seconds "Answer the number of seconds the receiver represents." ^seconds rem: SecondsInMinute! ! !DurationTest methodsFor: 'testing' stamp: 'KLC 5/12/2008 13:41'! testSeconds self assert: aDuration seconds = 4. self assert: (Duration nanoSeconds: 2) seconds = 0. self assert: (Duration nanoSeconds: 999999999) seconds = 0. self assert: (Duration nanoSeconds: 1000000001) seconds = 1. self assert: (Duration seconds: 2) seconds = 2. self assert: (Duration days: 1 hours: 2 minutes: 3 seconds:4) seconds = 4. self deny: (Duration days: 1 hours: 2 minutes: 3 seconds:4) seconds = (1*24*60*60+(2*60*60)+(3*60)+4). ! !