时间取整(向前,向后)
#include <boost/date_time/posix_time/posix_time.hpp>
typedef boost::posix_time::ptime BoostTM;
BoostTM roundUpToNextHour(const BoostTM& time)
{
if (time.time_of_day().minutes() != 0 || time.time_of_day().seconds() != 0)
{
BoostTM rounded_up;
rounded_up = time + boost::posix_time::hours(1);
rounded_up = boost::posix_time::ptime(rounded_up.date(), boost::posix_time::hours(rounded_up.time_of_day().hours()));
return rounded_up;
}
else
{
return time;
}
}
BoostTM roundDownToPrevHour(const BoostTM& time)
{
if (time.time_of_day().minutes() != 0 || time.time_of_day().seconds() != 0)
{
BoostTM rounded_down;
rounded_down = boost::posix_time::ptime(time.date(), boost::posix_time::hours(time.time_of_day().hours()));
return rounded_down;
}
else
{
return time;
}
}