Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I dare come again out of the wood...

It seems that it is important that a DateTime::Set has both start and end point.

Here is my today's attempt with and without an end point and the output below is different (correct if end point is defined):

#!/usr/bin/perl use strict; use warnings; use DateTime; use DateTime::Set; my $start = DateTime->today(); my $end = DateTime->today()->add('days' => 90); my $biweekly = DateTime::Set->from_recurrence( 'recurrence' => sub { return $_[0]->add('days' => 14)->truncate('to' => 'day') }, 'start' => $start, 'end' => $end, # !!! This is critical. ); my $iter = $biweekly->iterator; print "This is the set with defined 'end': ", $/; while ( my $dt = $iter->next ) { print $dt->datetime, $/; }; print $/; print 'TESTING whether Date is in set...', $/; my $date = DateTime->today(); print $biweekly->contains($date), ' ', $date->ymd, $/; $date->add('days' => 7); print $biweekly->contains($date), ' ', $date->ymd, $/; $date->add('days' => 7); print $biweekly->contains($date), ' ', $date->ymd, $/; $date->add('days' => 7); print $biweekly->contains($date), ' ', $date->ymd, $/; $date->add('days' => 7); print $biweekly->contains($date), ' ', $date->ymd, $/; $date->add('days' => 7); print $biweekly->contains($date), ' ', $date->ymd, $/; print $/; print "This is the begin of the set with 'end' commented out: ", $/; $biweekly = DateTime::Set->from_recurrence( 'recurrence' => sub { return $_[0]->add('days' => 14)->truncate('to' => 'day') }, 'start' => $start, # 'end' => $end, # !!! This is critical. ); $iter = $biweekly->iterator; while ( my $dt = $iter->next ) { last if $dt > $end; # to avoid the infinite loop. print $dt->datetime, $/; }; print $/; print 'TESTING whether Date is in set...', $/; $date = DateTime->today(); print $biweekly->contains($date), ' ', $date->ymd, $/; $date->add('days' => 7); print $biweekly->contains($date), ' ', $date->ymd, $/; $date->add('days' => 7); print $biweekly->contains($date), ' ', $date->ymd, $/; $date->add('days' => 7); print $biweekly->contains($date), ' ', $date->ymd, $/; $date->add('days' => 7); print $biweekly->contains($date), ' ', $date->ymd, $/; $date->add('days' => 7); print $biweekly->contains($date), ' ', $date->ymd, $/;

The output:

C:\Perl\bin>perl N:\Perle\Learn\DateTime\pm_1033231_orig_analyse_003_h +.pl This is the set with defined 'end': 2013-05-14T00:00:00 2013-05-28T00:00:00 2013-06-11T00:00:00 2013-06-25T00:00:00 2013-07-09T00:00:00 2013-07-23T00:00:00 2013-08-06T00:00:00 TESTING whether Date is in set... 1 2013-05-14 0 2013-05-21 1 2013-05-28 0 2013-06-04 1 2013-06-11 0 2013-06-18 This is the begin of the set with 'end' commented out: 2013-05-14T00:00:00 2013-05-28T00:00:00 2013-06-11T00:00:00 2013-06-25T00:00:00 2013-07-09T00:00:00 2013-07-23T00:00:00 2013-08-06T00:00:00 TESTING whether Date is in set... 1 2013-05-14 1 2013-05-21 1 2013-05-28 1 2013-06-04 1 2013-06-11 1 2013-06-18

In reply to Re^3: Determine if a given DateTime is a member of a DateTime::Set by vagabonding electron
in thread Determine if a given DateTime is a member of a DateTime::Set by eibwen

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (6)
As of 2024-04-20 00:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found