Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Determine if a given DateTime is a member of a DateTime::Set

by hdb (Monsignor)
on May 13, 2013 at 08:48 UTC ( #1033266=note: print w/replies, xml ) Need Help??

in reply to Determine if a given DateTime is a member of a DateTime::Set

After testing a few alternatives, it seems to be that the issue is with DateTime::Set->from_recurrence. Manually populating a set seems to work.

</#!/usr/bin/perl -w use strict; use diagnostics; use DateTime; use DateTime::Set; my $date = DateTime->today(); my $date2 = $date->clone(); $date2->add('days' => 14 ); my $set1 = DateTime::Set->from_datetimes( dates => [ $date, $date2 ]); my $iter = $set1->iterator; while( my $d = $iter->next ) { print $d->datetime, "\n"; } my $date3 = $date->clone(); $date3->add('days' => 7); print $set1->contains( $date3 ),"\n"; # gives 0 correct! my $biweekly = DateTime::Set->from_recurrence( 'recurrence' => sub { return $_[0]->truncate('to' => 'day')->add('days' => 1 +4) }, 'after' => $date ); my $set4 = DateTime::Set->from_datetimes( dates => [ $date3 ] ); print $biweekly->contains( $set4 ), "\n"; # gives 1 wrong! print $set4->contains( $biweekly ), "\n"; # gives a warning

You said you had a solution already, but you could create the recurring dates yourself and then it should (hopefully) work.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1033266]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2023-03-20 13:44 GMT
Find Nodes?
    Voting Booth?
    Which type of climate do you prefer to live in?

    Results (59 votes). Check out past polls.