The problem is in the truncate('to' => 'day') step.
What you need is to truncate to "14th day", which is not that easy.
Do you think you can do with DateTime::Event::Recurrence or DateTime::Event::ICal? These modules provide a large set of recurrence modes.
#!/usr/bin/perl
use strict;
use warnings;
use DateTime::Event::Recurrence;
print "DateTime::Event::Recurrence: ", $/;
my $start = DateTime->today();
my $biweekly = DateTime::Event::Recurrence->daily(
interval => 14,
start => $start,
);
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, $/;
output:
DateTime::Event::Recurrence:
TESTING whether Date is in set...
1 2013-05-15
0 2013-05-22
1 2013-05-29
0 2013-06-05
1 2013-06-12
0 2013-06-19
-
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.