recurring system
Hey guys, Does anyone have, already made, some type of recurring events module? We have our in-house function that works with singular weekly and singular monthly events but we'd like to branch into daily, bi-daily, bi-weekly, bi-monthly, every X weeks, every X days, etc. Our current logic for calculating the next event for a weekly event is thus: Take the original time stamp of the event. Compare that to current time. If eventTimeStamp is greater than current time, return that date/time. Otherwise, add 1 week to eventTimeStamp and compare again. Loop until eventTimeStamp is greater than current time. 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? Thanks, Matthew
Re: recurring system
Well that was easy. Thanks Rick. I should have looked on cpan before emailing. -Matthew Rick Measham wrote: Matthew wrote: Hey guys, Does anyone have, already made, some type of recurring events module? We have our in-house function that works with singular weekly and singular monthly events but we'd like to branch into daily, bi-daily, bi-weekly, bi-monthly, every X weeks, every X days, etc. Like DateTime::Event::Recurrence? my $bi_daily_at_10_30am_set = DateTime::Event::Recurrence-daily( interval = 2, hours = 10, minutes = 30 ); http://search.cpan.org/dist/DateTime-Event-Recurrence/lib/DateTime/Event/Recurrence.pm Cheers! Rick Measham
Re: recurring system
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