Re: [BUG] Empty spans/spansets have infinite duration?

[email protected] ("Flavio S. Glock")
Newsgroups perl.datetime
Message-ID <[email protected]>
Fixed in DateTime::Set 0.27

0.27   2009-04-02
- fixed DateTime::Spanset duration() method.
  Reported by Anton Berezin <[email protected]>

Flávio S. Glock

2009/4/2 Flavio S. Glock <[email protected]>:
> 2009/4/2 Anton Berezin <[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.
>
> This seems to be caused by a previous DateTime::Span fix that went wrong:
>
>    eval {
>        local $SIG{__DIE__};   # don't want to trap this (rt ticket 5434)
>        $dur = $_[0]->end->subtract_datetime_absolute( $_[0]->start )
>    };
>
> (start and end are not defined in this case)
>
>>
>> Is that something that you might be interesting in fixing?
>
> yes! thanks for reporting.
>
> Flávio S. Glock
>
>> 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.