Ah! nice. I don't fully understand DT:E:Recurrence yet...
Slight correction to both scripts:
The hours should be 13 and 17 instead of 1 and 5 (damn PM...).
Then yours should be (otherwise it picks up Saturdays too):
days => [1..5]
Which is more clear than mine anyway...
-ben
On Mon, Jun 16, 2003 at 11:49:16PM +0000, [EMAIL PROTECTED] wrote:
> Joshua Hoblitt said:
> > There must be a way to express the same semantic
> > meaning with fewer lines of code
>
> A slightly smaller version - specify days and hours
> in the same constructor.
>
> - Flavio S. Glock
>
> ---
> #!/usr/local/bin/perl -w
>
> use strict;
> use DateTime;
> use DateTime::Span;
> use DateTime::SpanSet;
> use DateTime::Event::Recurrence;
> use Carp;
>
> # Make a set representing mondays to fridays, with
> # the working hour restriction
> my $working_days =
> DateTime::SpanSet->from_sets
> (start_set => DateTime::Event::Recurrence->
> weekly( days => [1..6],hours => [9, 1]),
> end_set => DateTime::Event::Recurrence->
> weekly( days => [1..6],hours => [12, 5]),
> );
>
> # Make the date range
> my $date_range = DateTime::Span->from_datetimes
> (start => DateTime->new(
> year => 2003, month => 7, day => 1),
> end => DateTime->new(
> year => 2003, month => 7, day => 18));
>
> # Build the spanset of legal times
> my $legal = $working_days->intersection($date_range);
>
> ## Test code
> my $iter = $legal->iterator();
> while ( my $dt = $iter->next ) {
> printf "%s to %s\n",
> $dt->start->datetime,
> $dt->end->time;
> };
> ##
>
> # Now test the date
> my $dt = DateTime->new(year => 2003);
> croak "Bad date range" unless $legal->contains($dt);
>