5 // Copyright (c) 2003-2016 Christopher M. Kohlhoff (chris at kohlhoff dot com)
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
11 #ifndef BOOST_ASIO_TIME_TRAITS_HPP
12 #define BOOST_ASIO_TIME_TRAITS_HPP
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
18 #include <boost/asio/detail/socket_types.hpp> // Must come before posix_time.
20 #if defined(BOOST_ASIO_HAS_BOOST_DATE_TIME) \
21 || defined(GENERATING_DOCUMENTATION)
23 #include <boost/date_time/posix_time/posix_time_types.hpp>
25 #include <boost/asio/detail/push_options.hpp>
30 /// Time traits suitable for use with the deadline timer.
31 template <typename Time>
34 /// Time traits specialised for posix_time.
36 struct time_traits<boost::posix_time::ptime>
39 typedef boost::posix_time::ptime time_type;
41 /// The duration type.
42 typedef boost::posix_time::time_duration duration_type;
44 /// Get the current time.
45 static time_type now()
47 #if defined(BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK)
48 return boost::posix_time::microsec_clock::universal_time();
49 #else // defined(BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK)
50 return boost::posix_time::second_clock::universal_time();
51 #endif // defined(BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK)
54 /// Add a duration to a time.
55 static time_type add(const time_type& t, const duration_type& d)
60 /// Subtract one time from another.
61 static duration_type subtract(const time_type& t1, const time_type& t2)
66 /// Test whether one time is less than another.
67 static bool less_than(const time_type& t1, const time_type& t2)
72 /// Convert to POSIX duration type.
73 static boost::posix_time::time_duration to_posix_duration(
74 const duration_type& d)
83 #include <boost/asio/detail/pop_options.hpp>
85 #endif // defined(BOOST_ASIO_HAS_BOOST_DATE_TIME)
86 // || defined(GENERATING_DOCUMENTATION)
88 #endif // BOOST_ASIO_TIME_TRAITS_HPP