>Btw, by recurring events I mean events which can be configured to occur >for example: every monday and thursday, last friday in month, >every second tuesday, every friday the 13th, and so on... >Much like crontab or MS-Outlook's recurrence appointments. > >Unfortunately, there is no such class in the Date-Time library. I don't >know, but maybe such a class doesn't fit in a library?
I believe it would be a perfect fit with the library. The only reason it isn't there is time. I would be happy to collaborate with you on building such an extension :-) >Anyhow, I think it would be really nice to say something like: >recurring_event<daily> wakeMeUp("09:45"); >recurring_event<weekly> trainingDays(monday,thursday); >recurring_event<weekly> cleaningDay(tuesday,every_2nd); >recurring_event<monthly> receiveSalary(friday,last_day_in_month); >recurring_event<yearly> santa(christmas_day); In general, what you want to do here is very similar to the generator concept. See http://www.boost.org/libs/date_time/doc/date_algorithms.html for some ideas. For example your receiveSalary on the last friday of the month is very similar to the 'last_kday_of_month' which performs the following calculation: last_kday_of_month lkm(Friday,Jan); date d = lkm.get_date(2002);//2002-Jan-28 date d2 = lkm.get_date(2003); //2003-Jan-31 >Does anyone have an idea or hint how to implement such a class (maybe >out of different boost-classes)? Otherwise I know one way to go, based >on the paper "Recurring Events" written by Martin Fowler and available >on his site martinfowler.com. I believe most of the tools you need are already in the library. It is really a matter of putting them together in a way that is useful to your application. For example recurring_event<daily> wakeMeUp("09:45"); is easily specified as a time duration offset from midnight. That is using namespace boost::gregorian; using namespace boost::posix_time; //warning -- untested code! class daily_event { daily_event(time_duration td) : offset_from_midnight(td) {} //use this to generate wakeup time for any date.... ptime getWakeUpTime(date d) { return ptime(d, offset_from_midnight); } private: time_duration offset_from_midnight; }; Jeff _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost