
Thank you for the tips on the interval library. Unfortunately this doesn't achieve what i want. This will deliver the "same" results as the contains() member from the time_period class. The underlying problem is that the reference points are specific instances of time. A ptime isn't just say one o'clock (1:00). A ptime is actually 1:00 on a specific day. So one could easily make a time range for a single day. I was hoping for an easy way to have a time range for any day, or for a range of days (8:00 - 5:00 M-F). I have ideas on how to extend the classes to achieve this. However, I was hoping this already existed. Still, I appreciate the pointer to the interval class/library, I can envision usages for this in other areas of our code already. Regards, -=John On 12/17/2010 3:51 PM, Joachim Faulhaber wrote:
Hi John,
I was looking at the DateTime library for a scheduling module in my application. I was very excited to see time periods (time_period) and its method contains().
I could set up a time_period for say 8:00-17:00, and then when something happened I could create a ptime and see if the time_period contains my ptime. (i.e. did my action happen between 8:00 and 17:00.)
However, I realized that a time period is much more specific than I want. A time_period is tied to a specific date, i.e. 8:00-17:00 on Sep. 20 1999.
I read the documentation, and I didn't see (or missed) anything that might be what I would call an hour period -- a range of time that is independent of the date. I don't think it's a duration, because I understood that to mean the amount of time between two time points (i.e. +/- 5 hours).
I have some ideas on how I might extend this to achieve what I want, but before going that route, I wanted to double check if others have encountered this and if so how they resolved it. Was it done with a bit of the library that I'm overlooking? Or did you have to extend the class to achieve the desired results?
2010/12/17 John Rocha
: probably not. But maybe intervals and interval containers might be handy for scheduling problems as Jeff has pointed out. There is a code snippet that might be helpful: --------------------------------------- #include
#include using namespace std; using namespace boost; using namespace boost::icl; using namespace boost::posix_time;
void time_test() { ptime t_a = time_from_string("2010-12-24 19:30"); ptime t_b = time_from_string("2010-12-24 20:30"); time_duration a_2_b = t_b - t_a; cout<< "Duration of ["<< t_a<< ","<< t_b<< ") =" << a_2_b<< endl;
interval<ptime>::type a_b = interval<ptime>::right_open(t_a, t_b); cout<< "Duration of "<< a_b<< " =" << icl::size(a_b)<< endl; time_duration half = a_2_b / 2; ptime t_m = t_a + half;
cout<< a_b<< (icl::contains(a_b, t_m) ? " contains " : "does not contain ") << t_m<< endl; }
Boost.Icl is a new library on intervals and interval containers that will ship with the next release 1.46. Meanwhile you can find download information here: http://www.joachim-faulhaber.de
Maybe you might find some examples about date and time processing helpful: http://www.joachim-faulhaber.de/boost_icl/doc/libs/icl/doc/html/boost_icl/ex... http://www.joachim-faulhaber.de/boost_icl/doc/libs/icl/doc/html/boost_icl/ex... http://www.joachim-faulhaber.de/boost_icl/doc/libs/icl/doc/html/boost_icl/ex...
HTH Joachim
-- 2 much txting mks u 1 bad splr!!!!