http://www.perlmonks.org?node_id=591160

jking has asked for the wisdom of the Perl Monks concerning the following question:

My first post on pm. I've read all the docs and asked about documentation on Time::Period in the cb; I've googled and experimented... I still need a little bit of help. I'm trying to create a script that iterates over a time period and prints out a start and end time for each day in the range. The end result will hopefully be a textfile that resembles something like this:
2006-09-22 9:22am - 6:45pm 2006-09-25 9:20am - 6:15pm
In the following script, $return always returns -1. In the Time::Period pod, this means that inPeriod() is not getting a properly formed value as it's input. Here's my code:
#!/usr/bin/perl -w use strict; use DateTime; use DateTime::Span; use DateTime::Set; use Time::Period; my $start_date = DateTime->new( year => 2006, month => 9, day => 10, hour => 9 ); my $end_date = DateTime->new( year => 2006, month => 12, day => 20, hour => 18 ); my $span = DateTime::Span->from_datetimes( start => $start_date, end = +> $end_date ); my $days = DateTime::Set->from_recurrence ( span => $span, recurrence => sub { return $_[0]->truncate( to => 'day' )->add( days => 1 ) }, ); my $iter = $days->iterator; while (my $dt = $iter->next) { my $result = inPeriod( $dt->datetime, "wd {Mon-Fri}" ); if ($result) { printf("TRUE: %s -- \$result: %d\n", $dt->ymd, $result); } }