////////////////////////////////////////////////////////////////////////////// // // (C) Copyright Vicente J. Botet Escriba 2009. Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // // See http://www.boost.org/libs/synchro for documentation. // ////////////////////////////////////////////////////////////////////////////// #ifndef BOOST_CONVERT_TO_CHRONO_TIME_POINT_TO_POSIX_TIME_PTIME__HPP #define BOOST_CONVERT_TO_CHRONO_TIME_POINT_TO_POSIX_TIME_PTIME__HPP #include #include #include namespace boost { namespace partial_specialization_workaround { template < class Clock, class Duration> struct convert_to > { inline static posix_time::ptime apply(const chrono::time_point& from) { typedef chrono::time_point time_point_t; typedef chrono::nanoseconds duration_t; typedef duration_t::rep rep_t; rep_t d = chrono::duration_cast(from.time_since_epoch()).count(); rep_t sec = d/1000000000; rep_t nsec = d%1000000000; return boost::posix_time::from_time_t(0)+ boost::posix_time::seconds(static_cast(sec))+ #ifdef BOOST_DATE_TIME_HAS_NANOSECONDS boost::posix_time::nanoseconds(nsec); #else boost::posix_time::microseconds((nsec+500)/1000); #endif } inline static void apply(const chrono::time_point& from, posix_time::ptime& to) { to = apply(from); } }; template < class Clock, class Duration> struct convert_to, posix_time::ptime> { inline static chrono::time_point apply(const posix_time::ptime& from) { boost::posix_time::time_duration const time_since_epoch=from-boost::posix_time::from_time_t(0); chrono::time_point t=chrono::system_clock::from_time_t(time_since_epoch.total_seconds()); long nsec=time_since_epoch.fractional_seconds()*(1000000000/time_since_epoch.ticks_per_second()); return t+chrono::nanoseconds(nsec); } inline static void apply(const posix_time::ptime& from, chrono::time_point& to) { to = apply(from); } }; } } #endif