Testing out new UTCDateAndTime in Squeak 5.3 alpha

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Testing out new UTCDateAndTime in Squeak 5.3 alpha

Tim Johnson-2
Hi all,

I am testing out UTCDateAndTime via trunk.  I am happy with the results
so far, and intend to send along some notes in the near future.

One of my tests was refusing to pass, though, and I have narrowed it
down to this new behavior which I find kind of strange.

| d span |
d := DateAndTime now.
span := (DateAndTime now - 5 minutes) to: DateAndTime now.
span includes: d.  " false"


d := DateAndTime now.
span := (DateAndTime now - 5 minutes) to: (DateAndTime now + 1
milliSecond).
span includes: d.   " true"


d := DateAndTime now - 1 milliSecond.
span := (DateAndTime now - 5 minutes) to: (DateAndTime now).
span includes: d. " true"


What am I doing wrong?

I am running on OS X using Cog Spur VM 5.0-201803080952 (64-bit).

Thanks,
Tim J

Reply | Threaded
Open this post in threaded view
|

Re: Testing out new UTCDateAndTime in Squeak 5.3 alpha

Levente Uzonyi
Hi Tim,

The cause of the problem is that DateAndTime >> #to: creates a Timespan
which is a right-open interval (see Timespan >> #end) unlike Interval.
Your tests rely in the strictly increasing values returned by DateAndTime
>> #now, but that has been changed with the new default clockPolicy
#monotonicAllowDuplicates (see Time class >> #clockPolicy:).
If you evaluate [ Time clockPolicy: #monotonicForceNanosecondIncrement ],
then you'll get the old behavior. #monotonicForceMicrosecondIncrement will
also make your tests pass.
If you reused the d variable instead of creating multiple DateTime
instances, your test would not pass:

| d span |
Time clockPolicy: #monotonicForceMicrosecondIncrement.
d := DateAndTime now.
span := (d - 5 minutes) to: d.
span includes: d.  " false "

Levente

On Mon, 11 Mar 2019, Tim Johnson wrote:

> Hi all,
>
> I am testing out UTCDateAndTime via trunk.  I am happy with the results
> so far, and intend to send along some notes in the near future.
>
> One of my tests was refusing to pass, though, and I have narrowed it
> down to this new behavior which I find kind of strange.
>
> | d span |
> d := DateAndTime now.
> span := (DateAndTime now - 5 minutes) to: DateAndTime now.
> span includes: d.  " false"
>
>
> d := DateAndTime now.
> span := (DateAndTime now - 5 minutes) to: (DateAndTime now + 1
> milliSecond).
> span includes: d.   " true"
>
>
> d := DateAndTime now - 1 milliSecond.
> span := (DateAndTime now - 5 minutes) to: (DateAndTime now).
> span includes: d. " true"
>
>
> What am I doing wrong?
>
> I am running on OS X using Cog Spur VM 5.0-201803080952 (64-bit).
>
> Thanks,
> Tim J
>
>