vagabonding electron has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks,
I try to iterate over the generated set of datetimes in the following way:
What I need however is to generate only the hours between 07:00:00 and 22:00 :00.
I tried
I have not much experience with Datetime modules yet.
Please give me a hint.
Thanks in advance.
VE
I try to iterate over the generated set of datetimes in the following way:
This works.#!/usr/bin/perl use strict; use warnings; use DateTime; use DateTime::Event::Recurrence; use DateTime::Format::Strptime; my $strp = DateTime::Format::Strptime->new( pattern => '%Y-%m-%d %T', ); my $datf = qq{2012-01-01 04:00:00}; my $datt = qq{2012-01-02 23:00:00}; my $start= $strp->parse_datetime($datf); my $end = $strp->parse_datetime($datt); my $day_set = DateTime::Event::Recurrence->hourly(); my $it = $day_set->iterator ( start => $start->truncate(to=>"hour"), before => $end->truncate(to=>"hour"), ); while ( my $dt = $it->next() ) { print $dt->datetime(), "\n"; }
What I need however is to generate only the hours between 07:00:00 and 22:00 :00.
I tried
but this brings an error message "invalid argument 'hours' " - apparently one can use only the next low time step since it works with minutes=>[10, 30] for example.my $day_set = DateTime::Event::Recurrence->hourly( hours => [7, 22], );
I have not much experience with Datetime modules yet.
Please give me a hint.
Thanks in advance.
VE
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: A question to iterator in Datetime::Event::Recurrence
by Anonymous Monk on Apr 11, 2012 at 09:56 UTC | |
by vagabonding electron (Curate) on Apr 11, 2012 at 10:14 UTC | |
by Anonymous Monk on Apr 11, 2012 at 10:25 UTC | |
by vagabonding electron (Curate) on Apr 11, 2012 at 12:05 UTC | |
by fglock (Vicar) on Apr 11, 2012 at 12:22 UTC | |
| |
Re: A question to iterator in Datetime::Event::Recurrence
by fglock (Vicar) on Apr 11, 2012 at 12:07 UTC | |
by vagabonding electron (Curate) on Apr 11, 2012 at 13:12 UTC |
Back to
Seekers of Perl Wisdom