/* * Copyright Andrey Semashev 2012. * 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) */ #if (defined(_MSC_VER) && _MSC_VER > 1000) #pragma once #endif // _MSC_VER > 1000 #ifndef BOOST_DATE_TIME_THREAD_SUPPORT_HPP_INCLUDED_ #define BOOST_DATE_TIME_THREAD_SUPPORT_HPP_INCLUDED_ #include #include #include #include namespace boost { namespace detail { template< typename T > struct thread_time_traits< T, typename T::_is_boost_date_time_duration > { typedef time_duration_tag tag; static thread_duration to_thread_unit(T const& dur) { typedef typename T::traits_type traits_type; enum { conversion_ratio = traits_type::ticks_per_second >= thread_duration::subsecond_fraction ? traits_type::ticks_per_second / thread_duration::subsecond_fraction : thread_duration::subsecond_fraction / traits_type::ticks_per_second }; return thread_duration(traits_type::ticks_per_second >= thread_duration::subsecond_fraction ? dur.ticks() / conversion_ratio : dur.ticks() * conversion_ratio); } }; template< typename T > struct thread_time_traits< T, typename T::_is_boost_date_time_time_point > { typedef time_point_tag tag; static thread_time to_thread_unit(T const& point) { typedef typename T::date_type date_type; typedef typename T::time_duration_type time_duration_type; time_duration_type dur = point - T(date_type(1970, 1, 1)); time_t seconds = dur.total_seconds(); uint64_t fractional_seconds = dur.fractional_seconds(); typedef typename time_duration_type::traits_type traits_type; enum { conversion_ratio = traits_type::ticks_per_second >= thread_time::subsecond_fraction ? traits_type::ticks_per_second / thread_time::subsecond_fraction : thread_time::subsecond_fraction / traits_type::ticks_per_second }; return thread_time(seconds, traits_type::ticks_per_second >= thread_time::subsecond_fraction ? fractional_seconds / conversion_ratio : fractional_seconds * conversion_ratio); } }; } // namespace detail } // namespace boost #endif // BOOST_DATE_TIME_THREAD_SUPPORT_HPP_INCLUDED_