diff options
Diffstat (limited to 'boost/interprocess/sync/posix/ptime_to_timespec.hpp')
-rw-r--r-- | boost/interprocess/sync/posix/ptime_to_timespec.hpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/boost/interprocess/sync/posix/ptime_to_timespec.hpp b/boost/interprocess/sync/posix/ptime_to_timespec.hpp index 7d787353bd..65993de958 100644 --- a/boost/interprocess/sync/posix/ptime_to_timespec.hpp +++ b/boost/interprocess/sync/posix/ptime_to_timespec.hpp @@ -1,6 +1,6 @@ ////////////////////////////////////////////////////////////////////////////// // -// (C) Copyright Ion Gaztanaga 2005-2011. Distributed under the Boost +// (C) Copyright Ion Gaztanaga 2005-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) // @@ -11,6 +11,10 @@ #ifndef BOOST_INTERPROCESS_DETAIL_PTIME_TO_TIMESPEC_HPP #define BOOST_INTERPROCESS_DETAIL_PTIME_TO_TIMESPEC_HPP +#if defined(_MSC_VER) +# pragma once +#endif + #include <boost/interprocess/detail/posix_time_types_wrk.hpp> namespace boost { @@ -22,7 +26,9 @@ namespace ipcdetail { inline timespec ptime_to_timespec (const boost::posix_time::ptime &tm) { const boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1)); - boost::posix_time::time_duration duration (tm - epoch); + //Avoid negative absolute times + boost::posix_time::time_duration duration = (tm <= epoch) ? boost::posix_time::time_duration(epoch - epoch) + : boost::posix_time::time_duration(tm - epoch); timespec ts; ts.tv_sec = duration.total_seconds(); ts.tv_nsec = duration.total_nanoseconds() % 1000000000; |