[BUG] Empty spans/spansets have infinite duration?

[email protected] (Anton Berezin)
Newsgroups perl.datetime
Message-ID <[email protected]>
Hi,

It's a bit tricky to say which particular module needs to be changed to fix
this bug, hence I am not using RT for reporting it.  The good part is that
all candidate modules appear to have the same author.  :-)

The test case is as follows:

    #! /usr/bin/perl
    use strict;
    use warnings;
    
    use DateTime;
    use DateTime::Duration;
    use DateTime::Span;
    use Data::Dumper;
    
    my $bad_s = DateTime->new(year => 2009, month => 1, day => 12, hour => 1, minute => 0, second => 0);
    my $bad_e = DateTime->new(year => 2009, month => 1, day => 12, hour => 6, minute => 0, second => 0);
    
    my $bad = DateTime::Span->from_datetimes(start => $bad_s, end => $bad_e);
    my $good = $bad->complement;
    
    my $interest_s = DateTime->new(year => 2009, month => 1, day => 12, hour => 4, minute => 30, second => 0);
    my $interest_e = DateTime->new(year => 2009, month => 1, day => 12, hour => 5, minute => 0, second => 0);
    
    my $interest = DateTime::Span->from_datetimes(start => $interest_s, end => $interest_e);
    
    my $r = $interest->intersection($good);
    
    my $d = $r->duration;
    print Dumper $d;
    
    my $d0 = DateTime::Duration->new(seconds => 0);
    print Dumper $d0;

I would certainly expect for the duration $d of the empty set $r to be the
same duration as $d0, that is, zero seconds.  Instead it behaves more like
infinity.

Is that something that you might be interesting in fixing?

Thanks,
\Anton.
-- 
There is no beauty in entropy. -- Eliezer Yudkowsky
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.