How to create a closed time period with boost::posix_time

Boost date_time library provides very good interface to work with a temporal data. But because of the requirements for iterators compability, the periods are represented as a half-opened values. When passing the begin and end to the constructor, the second parameter will not belong to the created interval.

Sometimes a closed period could be needed, but I have failed to find in the documentation how to create it. After looking in the sources, I have found the way. To create the closed period just say the following:


using namespace boost::posix_time;
time_period tp(pBegin,
pLast + time_period::duration_type::unit());

where pBegin and pLast are ptime.

This will create the closed period tp, it's .last() method will return the exact value of pLast.