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);
}
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.