[plt-scheme] Time Base

From: John Clements (clements at brinckerhoff.org)
Date: Wed Dec 16 01:30:56 EST 2009

On Dec 15, 2009, at 6:01 PM, Doug Williams wrote:

> The easiest thing to see immediately is that (date-nanosecond (current-date)) always returns a value smaller than 10,000,000, which is 100 times to small. Try the following which returns the minimum and maximum such values - it takes a while because of the random sleeps.
> 
> (for/fold ((minimum +inf.0)
>            (maximum -inf.0))
>           ((i (in-range 1000)))
>   (let ((nanosecond (date-nanosecond (current-date))))
>     (sleep (/ (random) 10.0))
>     (values (min nanosecond minimum) (max nanosecond maximum))))
> 
> You'll get something like:
> 
> 0.0
> 9840000.0

Many thanks. I massaged this into this test case

(check-within (let ([t (date-nanosecond (current-date))])
                               (sleep 0.5)
                               (abs (- (date-nanosecond (current-date)) t)))
                             (* 1/2  (expt 10 9))
                             (* 1/10 (expt 10 9)))

... which fails, as expected.

John Clements

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2484 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20091215/37fb7c45/attachment.p7s>

Posted on the users mailing list.