> > 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.
That is a bit clearer - although it's alot more code then I'd want to inline in a program. It's something I would push off into a module. So perhaps something like DT::W::Validator should just be a very simple base class. So you would end up with something like: -- #!/usr/bin/env perl use strict; use Myproject::TimeValidator; my $dt = Myproject::TimeValidator->new( %hashofdtparams ); > --- package Myproject::TimeValidator > > use strict; use base qw( DateTime::Wrapper::Validator ); > 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 # probably something a bit more complex here # but the idea is to pass an iterator Setup( $working_days->intersection($date_range)->iterator() ); 1; __END__
