Brian O'Neill wrote:
> One way to handle zero-length intervals is do nothing special at all. 
> That is, when asking questions like "contains", "overlaps" and "abuts" 
> just do the comparisons as usual. Thus [9:00, 10:00) contains [9:00, 
> 9:00), abuts [9:00, 9:00), but it does not overlap. The zero length 
> interval [1:00, 2:00) is not contained.

I checked in two batches of interval code tonight. The first applied the 
followig rule - "a zero duration interval is equivalent to an infinite 
precision instant". This lead to:
- a zero duration instant contains itself
- a zero duration instant contains an instant of the same value
- a zero duration instant abuts itself
- a zero duration instant overlaps itself
This is essentially derived from the  [09:00,09:00.0000001) discussion.

I then checked in the code that was in Joda-Time v1.2. This applies the 
rule - "when comparing durations, the result state may be one and only 
one of abuts, a gap or overlaps". In essence this is the result of 
applying the simple formulae we used previously. This leads to:
- a zero duration instant contains nothing, not even itself
- a zero duration instant contains no instants
- a zero duration instant is contained at the start of a larger interval
- a zero duration instant abuts itself
- a zero duration instant does not overlap itself (abuts takes precedence)
- a zero duration instant does not overlap at the start of a larger 
interval (abuts takes precedence)
This is essentially derived from classic, simple formulae.


Both models have their intuitive parts and their non intuitive parts. 
The truth is that there is no right answer here. (The theoreticians 
don't agree based on reading the scholarly math papers, and have at 
least three models of intervals and their relationship to 
instants/timepoints/moments).

As such, I intend to choose the second of the two models. And I intend 
to do so for the primary reason that it is completely backwards 
compatible (as its the same code, save one bug fix). Changing the 
semantics of this would have been very difficult for users to test and 
could have broken apps in nasty ways.

Having said that, if we get to do a v2.0 with a new API, then we should 
think about modelling this properly now we know the difficulties.

Stephen

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Joda-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/joda-interest

Reply via email to