123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- #ifndef POSIX_TIME_CONVERSION_HPP___
- #define POSIX_TIME_CONVERSION_HPP___
- #include <cstring>
- #include <boost/cstdint.hpp>
- #include <boost/date_time/posix_time/ptime.hpp>
- #include <boost/date_time/posix_time/posix_time_duration.hpp>
- #include <boost/date_time/filetime_functions.hpp>
- #include <boost/date_time/c_time.hpp>
- #include <boost/date_time/time_resolution_traits.hpp> // absolute_value
- #include <boost/date_time/gregorian/conversion.hpp>
- namespace boost {
- namespace posix_time {
-
- inline
- ptime from_time_t(std::time_t t)
- {
- return ptime(gregorian::date(1970,1,1)) + seconds(t);
- }
-
- inline
- std::time_t to_time_t(ptime pt)
- {
- return (pt - ptime(gregorian::date(1970,1,1))).total_seconds();
- }
-
- inline
- std::tm to_tm(const boost::posix_time::ptime& t) {
- std::tm timetm = boost::gregorian::to_tm(t.date());
- boost::posix_time::time_duration td = t.time_of_day();
- timetm.tm_hour = static_cast<int>(td.hours());
- timetm.tm_min = static_cast<int>(td.minutes());
- timetm.tm_sec = static_cast<int>(td.seconds());
- timetm.tm_isdst = -1;
- return timetm;
- }
-
- inline
- std::tm to_tm(const boost::posix_time::time_duration& td) {
- std::tm timetm;
- std::memset(&timetm, 0, sizeof(timetm));
- timetm.tm_hour = static_cast<int>(date_time::absolute_value(td.hours()));
- timetm.tm_min = static_cast<int>(date_time::absolute_value(td.minutes()));
- timetm.tm_sec = static_cast<int>(date_time::absolute_value(td.seconds()));
- timetm.tm_isdst = -1;
- return timetm;
- }
-
- inline
- ptime ptime_from_tm(const std::tm& timetm) {
- boost::gregorian::date d = boost::gregorian::date_from_tm(timetm);
- return ptime(d, time_duration(timetm.tm_hour, timetm.tm_min, timetm.tm_sec));
- }
- #if defined(BOOST_HAS_FTIME)
-
-
- template< typename TimeT, typename FileTimeT >
- inline
- TimeT from_ftime(const FileTimeT& ft)
- {
- return boost::date_time::time_from_ftime<TimeT>(ft);
- }
- #endif
- } }
- #endif
|