[Chrono] Is there any functions that convert Chrono's time_point and duration to their Ptime equivalents?

Hello, I have been trying to find in the boost libraries if there are any interoperability functions for Boost::Chrono and Boost::Posix_Time? Does anyone know if they exist and what class they are in? Thanks, Matt

Le 19/01/12 19:49, Matthew Jenks a écrit :
Hello,
I have been trying to find in the boost libraries if there are any interoperability functions for Boost::Chrono and Boost::Posix_Time? Does anyone know if they exist and what class they are in?
Hi, no, there aren't. You can get them from https://svn.boost.org/svn/boost/sandbox/conversion/boost/conversion/boost/ch... and https://svn.boost.org/svn/boost/sandbox/conversion/boost/conversion/boost/ch.... Of course, you should extract the code from to be independent of the proposed library TBoost.Conversion reviewed but without review results yet. template< typename Rep, typename Period> posix_time::time_duration operator()(chrono::duration<Rep, Period> const& from) { typedef chrono::duration<Rep, Period> src_duration_t; typedef chrono::nanoseconds duration_t; typedef duration_t::rep rep_t; rep_t d = chrono::duration_cast<duration_t>(from).count(); rep_t sec = d/1000000000; rep_t nsec = d%1000000000; return posix_time::seconds(static_cast<long long>(sec))+ #ifdef BOOST_DATE_TIME_HAS_NANOSECONDS posix_time::nanoseconds(nsec); #else posix_time::microseconds((nsec+500)/1000); #endif } template< typename Duration> posix_time::ptime operator()(const chrono::time_point<chrono::system_clock, Duration>& from) { typedef chrono::time_point<chrono::system_clock, Duration> time_point_t; typedef chrono::nanoseconds duration_t; typedef duration_t::rep rep_t; rep_t d = chrono::duration_cast<duration_t>(from.time_since_epoch()).count(); rep_t sec = d/1000000000; rep_t nsec = d%1000000000; return posix_time::from_time_t(0)+ posix_time::seconds(static_cast<long>(sec))+ #ifdef BOOST_DATE_TIME_HAS_NANOSECONDS posix_time::nanoseconds(nsec); #else posix_time::microseconds((nsec+500)/1000); #endif } HTH, Vicente
participants (2)
-
Matthew Jenks
-
Vicente J. Botet Escriba