[Pharo-project] Timespan #intersection: yields wrong result

Brent Pinkney brent at zamail.co.za
Tue May 3 20:44:02 CEST 2011


On Tuesday 03 May 2011 19:25:47 Johan Brichau wrote:
> Hi,
> 
> I traced a bug when working with timespans to the following issue illustrated in the code snippet below. 
> The last expression in the snippet yields false, although it should yield true (imho).
> 
> 	|start end span|
> 	start :=DateAndTime now.
> 	end := start + 1 hour.
> 	span := Timespan starting: start ending: end.
> 	(span intersection: span) = span  --> false
> 
> I think that the intersection of a span with itself, should be itself. The origin of the problem is that Timespan>>intersection: creates a new timespan roughly as follows:
> 
> 	Timespan starting: aBegin ending: self end.
> 
> But Timespan>>end returns the end time of the timespan minus the clockprecision. As such, the intersecting span is a nanosecond shorter than the one we would expect. This eventually yields wrong results when working with timespans.
> 
> The real question now is: should the implementation of Timespan>>intersection be changed -or- should Timespan>>end really return the (non-included) end time (that was passed when constructing it)?
Hi,

I wrote this Chronology stuff, so I can assure you that the behaviour is deliberate. You never want overlapping timespans. ever :)

Let me know if you want some more details.

Brent



More information about the Pharo-project mailing list