Flavio S. Glock wrote:
>
> > How about having a generic method that anticipates or
> > postpones an event, if it falls in an invalid date.
> > For example:
>
> $payday_set = DateTime::Event::Recurrence->monthly(
> days => -1,
> );
>
[...]
> > # subtract days from "payday" events,
> > # such that they never fall in a weekend
Another way to do it:
$payday_set->iterate(
sub {
my $dt = shift;
my $dow = $dt->day_of_week;
$dt->add( days => 5 - $dow ) if $dow > 5;
return $dt;
}
);
> Result: $payday_set is a set of "last day of the month that is not a
> weekend"
Another one: move or delete holidays such that they don't fall in the
middle of the week:
$holiday_set->iterate(
sub {
my $dt = shift;
my $dow = $dt->day_of_week;
return undef if $dow == 3; # delete this event
return $dt->add( days => 1 ) if $dow == 4;
return $dt->add( days => -1 ) if $dow == 2;
return $dt; # don't move
}
);
- Flavio S. Glock