]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/interprocess/include/boost/interprocess/sync/posix/ptime_to_timespec.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / interprocess / include / boost / interprocess / sync / posix / ptime_to_timespec.hpp
1 //////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2005-2012. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // See http://www.boost.org/libs/interprocess for documentation.
8 //
9 //////////////////////////////////////////////////////////////////////////////
10
11 #ifndef BOOST_INTERPROCESS_DETAIL_PTIME_TO_TIMESPEC_HPP
12 #define BOOST_INTERPROCESS_DETAIL_PTIME_TO_TIMESPEC_HPP
13
14 #ifndef BOOST_CONFIG_HPP
15 # include <boost/config.hpp>
16 #endif
17 #
18 #if defined(BOOST_HAS_PRAGMA_ONCE)
19 # pragma once
20 #endif
21
22 #include <boost/interprocess/detail/posix_time_types_wrk.hpp>
23
24 namespace boost {
25
26 namespace interprocess {
27
28 namespace ipcdetail {
29
30 inline timespec ptime_to_timespec (const boost::posix_time::ptime &tm)
31 {
32 const boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
33 //Avoid negative absolute times
34 boost::posix_time::time_duration duration = (tm <= epoch) ? boost::posix_time::time_duration(epoch - epoch)
35 : boost::posix_time::time_duration(tm - epoch);
36 timespec ts;
37 ts.tv_sec = duration.total_seconds();
38 ts.tv_nsec = duration.total_nanoseconds() % 1000000000;
39 return ts;
40 }
41
42 } //namespace ipcdetail {
43
44 } //namespace interprocess {
45
46 } //namespace boost {
47
48 #endif //ifndef BOOST_INTERPROCESS_DETAIL_PTIME_TO_TIMESPEC_HPP