Matthew wrote: > To me, this seems amazingly inefficient. If my weekly recurring >original event start date was Aug 1, 2006, the perl would have to loop >26 times to find the next event (in this case, Jan 23). > >Can anyone offer a better solution to this?
Yes: determine the day-of-week of the original event, and the week containing tomorrow, then put them together. With my Date::ISO8601 module this looks like: use Date::ISO8601 qw(ymd_to_cjdn cjdn_to_ywd ywd_to_cjdn present_ymd); my $today_cjdn = ymd_to_cjdn(2007,1,16); my $initial_cjdn = ymd_to_cjdn(2006,8,1); (undef, undef, my $repeat_dow) = cjdn_to_ywd($initial_cjdn); my($next_y, $next_w, $today_dow) = cjdn_to_ywd($today_cjdn + 1); if($today_dow > $repeat_dow) { ($next_y, $next_w, undef) = cjdn_to_ywd($today_cjdn + 8); } print present_ymd(ywd_to_cjdn($next_y, $next_w, $repeat_dow)), "\n"; I expect the same algorithm can be implemented using DateTime, but I'm not a regular user of that, sorry. -zefram