Date Period Calculations
Calculates if a date is in an 'irregular' collection of periods using period calculation functions.
20020216/20020217
20020223/20020224
*/
#include "boost/date_time/gregorian/gregorian.hpp"
#include
#include
#include
typedef std::set date_period_set;
//Simple population of the exclusion set
date_period_set
generateExclusion()
{
using namespace boost::gregorian;
date_period periods_array[] =
{ date_period(date(2002,Feb,2), date(2002,Feb,4)),//weekend of 2nd-3rd
date_period(date(2002,Feb,9), date(2002,Feb,11)),
date_period(date(2002,Feb,16), date(2002,Feb,18)),
date_period(date(2002,Feb,23), date(2002,Feb,25)),
date_period(date(2002,Feb,12), date(2002,Feb,13))//a random holiday 2-12
};
const int num_periods = sizeof(periods_array)/sizeof(date_period);
date_period_set ps;
//insert the periods in the set
std::insert_iterator itr(ps, ps.begin());
std::copy(periods_array, periods_array+num_periods, itr );
return ps;
}
int main()
{
using namespace boost::gregorian;
date_period_set ps = generateExclusion();
std::cout << "Number Excluded Periods: " << ps.size() << std::endl;
date d(2002,Feb,16);
date_period_set::const_iterator i = ps.begin();
//print the periods, check for containment
for (;i != ps.end(); i++) {
std::cout << to_iso_string(*i) << std::endl;
//if date is in exclusion period then print it
if (i->contains(d)) {
std::cout << "In Exclusion Period: "
<< to_iso_string(d) << " --> " << to_iso_string(*i)
<< std::endl;
}
}
return 0;
}
]]>