[DateTime] Daily Schedules

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? Thanks in advance, -=John

John Rocha wrote:
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().
Have you looked at the new interval template library. The author just merged it to the release branch. IIRC, it's motivating example was just such a scheduling application, for which it has example code. Jeff

Hi Jeff,
2010/12/17 Jeff Flinn
John Rocha wrote:
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().
Have you looked at the new interval template library. The author just merged it to the release branch. IIRC, it's motivating example was just such a scheduling application, for which it has example code.
Thanks for promoting my library :) Cheers, Joachim -- Interval Container Library [Boost.Icl] http://www.joachim-faulhaber.de

Hi John,
2010/12/17 John Rocha
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?
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

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!!!!

2011/1/5 John Rocha
Thank you for the tips on the interval library.
Hi John, thank you for looking at Boost.Icl and for sharing your question. It helped me to spot a flaw in the interoperability between Boost.Icl and Boost.DateTime, so I could fix it before boost 1.46. is released :)
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.
As Igor pointed out, the kind of time that you are looking for is probably boost::posix_time::time_duration. While posix_time::ptime is related to a fixed time origin (1400-Jan-01 00:00:00), the starting point of a time_duration can be chosen or is given by different points in time according to the program logic which it is used in, like in your daily schedules, the beginning 00:00 of some (not a specific) day.
So one could easily make a time range for a single day.
Using Boost.Icl you can do it this way:
time_duration start = hours(8) + minutes(30);
time_duration stop = hours(17) + minutes(15);
icl::interval
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).
Should be possible with icl::interval
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.
That's nice to hear. I'd be happy if the Icl is useful for you. Best regards, Joachim -- Interval Container Library [Boost.Icl] http://www.joachim-faulhaber.de
participants (4)
-
Igor R
-
Jeff Flinn
-
Joachim Faulhaber
-
John Rocha