(Repost - was: Re: RFC Events Calendar)
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,
);
$weekend_set = DateTime::Event::Recurrence->weekly(
days => [ 6, 7 ],
);
> # subtract days from "payday" events,
> # such that they never fall in a weekend
> $payday_set->add_duration_while(
> condition => $weekend_set,
> duration => DT::Duration->new( days => -1 ),
> }
Result: $payday_set is a set of "last day of the month that is not a
weekend"
You can already do this using a DateTime::Event::ICal specification, but
'add_duration_while' is more powerful.
Another example: postpone payday if it is a weekend:
$payday_set->add_duration_while(
condition => $weekend_set,
duration => DT::Duration->new( days => 1 ),
}
- Flavio S. Glock