id summary reporter owner description type status milestone component version severity resolution keywords cc 3471 microseconds constructor overflows Andrey Semashev Andrey Semashev "From the users ML: [http://lists.boost.org/boost-users/2008/10/41763.php] The boost::date_time::microseconds(...) constructor overflows the int64 size limits in intermediary calculations. The code below will reproduce the error (using VC++ 2008 and boost 1.36). {{{ ptime start(boost::gregorian::date(2000, 1, 1)); ptime end(boost::gregorian::date(2000, 5, 1)); time_duration td = end - start; ptime wrongEnd = start + microseconds(td.total_microseconds()); BOOST_CHECK_EQUAL(end, wrongEnd); }}} The microseconds constructor takes an int64 as input and the total_microseconds is well within its range. Inside the date_time::subsecond_duration the internal duration is calculated as {{{ ss*traits_type::res_adjust()/frac_of_second }}} Since the both res_adjust() and frac_of_second have the value 1000000, the result should be ss*1 but... the intermediary value ss*res_adjust overflows the int64 causing a negative number to be returned. Question is, is this by design or is it a bug? I'm rather new to boost::date_time and was hoping to replace our current datetime types with it. We are using millisecond timestamped data over long time series (years). I guess the simple solution would be to add parentheses around (res_adjust()/frac_of_second) assuming frac_of_second always divides res_adjust. However, there are similar issues when adding 200 years worth of seconds which overflows the int32 argument (but that's not of my immediate concern)." Patches closed Boost 1.43.0 date_time Boost 1.40.0 Problem fixed microseconds