This code resembles a standard DateTime::Event module
implementation.

  http://datetime.perl.org/developer/event.html

I think 95% of the work could be done by reusing one
of these modules:

  DateTime::Set "from_recurrence" method
    - to start from scratch
  DateTime::Event::Recurrence 
  DateTime::Event::ICal 
  DateTime::Format::ICal
    - highest level of abstraction

If you are planning on using a database backend, I'd
suggest you base your implementation on DateTime::Set
"from_recurrence".

> The psuedo-code algorithm for DateTime::Business
functions looks like
> 
> sub add_business_days {
> my ($self, $days) = @_;
> return $self->crement_business_days(days);
> }
> 
> sub subtract_business_days {
> my ($self, $days) = @_;
> return $self->crement_business_days(days*-1);
> }
> 
> sub crement_business_days {
> my ($self, $days) = @_;
> ## This duration could be a static class member to
save time and space
> my $duration=DateTime::Duration->new( days    => 1);
> 
> my $crement = $days/abs($days);
> while ($days) {
>     $crement > 0 ?  $self->add_duration($duration) :
> $self->subtract_duration($duration);
>     $days -= $crement;
>     ## This is the part that skips non-business
days by doing the
> 'crement w/o adjusting the $days_to_crement.
>     while (!$self->is_a_business_day()) {
>         $crement > 0 ? 
$self->add_duration($duration) :
> $self->subtract_duration($duration);
>     }
> return $self;
> }

- Flavio S. Glock


Reply via email to