Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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

by hdb (Monsignor)
on May 13, 2013 at 08:48 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2024-04-25 02:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found