Re: Removing spans from a spanset with grep returns unexpected results?

[email protected] ("Flavio S. Glock") Tue, 15 Oct 2013 15:19:24 +0200
Newsgroups perl.datetime
Message-ID <CAHMRfDzYheZmDwCZVxT6Wm0fWERj5QM2e4DENCOJSTbN9_FgEw@mail.gmail.com>
Andreas:

Thanks for reporting - I've applied this fix:

diff --git a/lib/DateTime/SpanSet.pm b/lib/DateTime/SpanSet.pm
index 3b818e2..05ae726 100644
--- a/lib/DateTime/SpanSet.pm
+++ b/lib/DateTime/SpanSet.pm
@@ -61,7 +61,7 @@ sub grep {
         sub {
             local $_ = bless { set => $_[0]->clone }, 'DateTime::Span';
             my $result = $callback->();
-            return $_ if $result;
+            return $_->{set} if $result && $_;
             return;
         }
     );


I'm publishing the fixed DateTime-Set-0.33 to cpan.

Flávio S. Glock

2013/10/15 Andreas Isberg <[email protected]>:
> Hi Flavio,
>
> I attached a small script that can be run from a cgi-bin folder. I'm using
> perl v5.10.1.
>
> Kind regards,
> Andreas Isberg
>
>
> 2013/10/14 Flavio S. Glock <[email protected]>
>
>> Hi Andreas,
>> would you have a small test script that reproduces the problem?
>>
>> thanks
>> Flavio
>>
>>
>> 2013/10/14 Andreas Isberg <[email protected]>:
>> > Hi,
>> >
>> > I'm using the DateTime::SpanSet module and I'm looking for a way to
>> > reduce
>> > my set by removing spans containing an infinite value (more precise
>> > span->start and span->end).
>> > I've tried the following:
>> >
>> > $spanset = $spanset->grep(
>> > sub {
>> > return !($_->start->is_infinite() || $_->end->is_infinite());
>> > }
>> > );
>> >
>> > This returns a DateTime::SpanSet consisting of DateTime::Span items. So
>> > far
>> > so good.
>> > But the the start and end of each Span is itself a Span, and not
>> > DateTime
>> > objects as I was expecting.
>> >
>> > Any clues what I'm doing wrong?
>> >
>> > Kind regards,
>> > Andreas Isberg
>
>