ptime_to_timespec.hpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. #ifndef BOOST_INTERPROCESS_DETAIL_PTIME_TO_TIMESPEC_HPP
  11. #define BOOST_INTERPROCESS_DETAIL_PTIME_TO_TIMESPEC_HPP
  12. #include <boost/interprocess/detail/posix_time_types_wrk.hpp>
  13. namespace boost {
  14. namespace interprocess {
  15. namespace ipcdetail {
  16. inline timespec ptime_to_timespec (const boost::posix_time::ptime &tm)
  17. {
  18. const boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
  19. boost::posix_time::time_duration duration (tm - epoch);
  20. timespec ts;
  21. ts.tv_sec = duration.total_seconds();
  22. ts.tv_nsec = duration.total_nanoseconds() % 1000000000;
  23. return ts;
  24. }
  25. } //namespace ipcdetail {
  26. } //namespace interprocess {
  27. } //namespace boost {
  28. #endif //ifndef BOOST_INTERPROCESS_DETAIL_PTIME_TO_TIMESPEC_HPP