Boost logo

Boost Users :

Subject: Re: [Boost-users] [DateTime] Daily Schedules
From: Joachim Faulhaber (afojgo_at_[hidden])
Date: 2010-12-17 18:51:02


Hi John,

2010/12/17 John Rocha <jrr_at_[hidden]>:
> 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 <boost/icl/ptime.hpp>
#include <boost/icl/interval.hpp>

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/examples/party.html
http://www.joachim-faulhaber.de/boost_icl/doc/libs/icl/doc/html/boost_icl/examples/time_grids_for_months_and_weeks.html
http://www.joachim-faulhaber.de/boost_icl/doc/libs/icl/doc/html/boost_icl/examples/man_power.html

HTH
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