Ok, lets say that you want only "working hours" as legal times, so
9-12,1-5, M-F from July 1st to July 17th, 2003.
Most of the code below is building the ranges... I think youy would
have to do that anyway. The real bit that the module would do is the
intersection stuff, and that is a couple of lines.
I have included some test code to print out the legal ranges.
-ben
--
#!/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
my $working_days =
DateTime::SpanSet->from_sets
(start_set => DateTime::Event::Recurrence->weekly(days => 1),
end_set => DateTime::Event::Recurrence->weekly(days => 6),
);
# Make the working hour restriction
my $working_hours =
DateTime::SpanSet->from_sets
(start_set => DateTime::Event::Recurrence->daily(hours => [9, 1]),
end_set => DateTime::Event::Recurrence->daily(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)); # 1-17 inclusive
# Build the spanset of legal times
my $legal = $working_days->intersection($working_hours)
->intersection($date_range);
## Test code
my $iter = $legal->iterator();
while ( my $dt = $iter->next ) { # $dt is a DateTime::Span
printf "%s to %s\n", $dt->start->datetime, $dt->end->time;
};
##
# Now test the date
my $dt = DateTime->new(year => 2003); # Your date here
croak "Bad date range" unless $legal->contains($dt);
--
On Mon, Jun 16, 2003 at 08:42:14AM -1000, Joshua Hoblitt wrote:
> > my $safe_span = ...; # Whatever you need
> > my dt = DateTime->new(...);
> > croak "Bad date range" if $safe_span->contains($dt);
>
> In my [poor] example. But what if you only wanted to only accept time values from
> 11:00-18:00 across a span?
>
> > In fact you may want the span to be a spanset to accomodate more fine
> > grained controls. Is this useful enough to merit a class? I dunno.
>
> I think it could be useful - I'm just not that sure about the syntax.
>
> Cheers,
>
> -J
>
> --