Boost logo

Boost Users :

Subject: Re: [Boost-users] [DateTime] Daily Schedules
From: Joachim Faulhaber (afojgo_at_[hidden])
Date: 2011-01-07 08:31:46


2011/1/5 John Rocha <jrr_at_[hidden]>:
> 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<time_duration>::type working_hours
        = icl::interval<time_duration>::right_open(start, stop);

cout << "working_hours: " << working_hours << endl;

As mentioned above I spotted that boost::posix_time::time_duration
lacks an in/decrement operator ++/-- that is required for interval
containers. Operator ++ increments an integral type on its least
steppable unit, also called "tick" in the field of time types. Unlike
the new Boost.Chrono duration type, time_duration from Boost.DateTime
does not implement this operator so I added adapter code to
boost/icl/ptime.hpp. [BTW may be it is time to fix this in
Boost.DateTime directly so DateTime and Chrono "tick in the same
way".]

I order to use that code you can patch your version of the Icl
replacing boost/icl/ptime.hpp with the latest version of that file
from the trunk.
http://svn.boost.org/svn/boost/trunk/boost/icl/ptime.hpp

Or you get the current version from the Boost trunk via SVN all together.
http://svn.boost.org/svn/boost/trunk/boost/icl/

> 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<time_duration> in different ways.

> 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

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net