The right answer is "use DateTime::Business::xxx"
Now how about:

  sub no_holiday {
    return $_[0] unless  ... # lookup holidays 
    return undef;
  }

  my $prime_set = DateTime::SpanSet->from_set_and_duration( 
    set => DT::E::Recurrence->weekly(
      days => [1..5], hours => 8 )->iterate( \&no_holiday ),
    hours => 11 );

  my $duration = $prime_set->intersection( $downtime_set )->duration;

- Flavio S. Glock


Ben Bennett wrote:
> 
> Why do you hate me :-)
> 
> I have no idea how to handle this easily... is a bunch of sets the
> right answer?  Seems gross.
> 
>        -ben
> 
> On Mon, Oct 13, 2003 at 01:00:09PM -0300, Flavio S. Glock wrote:
> > How about a question for the FAQ?
> >
> > http://perlmonks.org/index.pl?node_id=298788
> > >
> > > Calculate down time of devices in prime time (only working hours, excluding 
> > > p_holidays)
> > >  by albertc on Oct 13, 2003 at 05:00 GMT+3
> > >
> > > I have up & down datetime data for devices, I need a function that will provide 
> > > the
> > > downtime within the primetime period. Input will be d_time, u_time, stime 
> > > (starting time
> > > for Primetime, 08:00:00), etime (endtime for PrimeTime, 18:59:59). The function 
> > > also
> > > needs to remove downtime that occured on a public holiday and over weekends! 
> > > Public
> > > holidays will be read from mysql table with Datetime record of each public 
> > > holiday.

Reply via email to