FAQ
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

Search Discussions

  • Flavio S. Glock at Oct 15, 2013 at 1:19 pm
    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 <andreas@isberg.se>:
    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 <fglock@gmail.com>
    Hi Andreas,
    would you have a small test script that reproduces the problem?

    thanks
    Flavio


    2013/10/14 Andreas Isberg <andreas@isberg.se>:
    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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupdatetime @
categoriesperl
postedOct 14, '13 at 2:50p
activeOct 15, '13 at 1:19p
posts2
users2
websitemetacpan.org...

2 users in discussion

Flavio S. Glock: 1 post Andreas Isberg: 1 post

People

Translate

site design / logo © 2019 Grokbase