123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- #ifndef DATE_TIME_FILETIME_FUNCTIONS_HPP__
- #define DATE_TIME_FILETIME_FUNCTIONS_HPP__
- #include <boost/date_time/compiler_config.hpp>
- #if defined(BOOST_HAS_FTIME)
- #if defined(BOOST_USE_WINDOWS_H)
- # include <windows.h>
- #endif
- #include <boost/cstdint.hpp>
- #include <boost/date_time/time.hpp>
- #include <boost/date_time/date_defs.hpp>
- namespace boost {
- namespace date_time {
- namespace winapi {
- #if !defined(BOOST_USE_WINDOWS_H)
- extern "C" {
- struct FILETIME
- {
- boost::uint32_t dwLowDateTime;
- boost::uint32_t dwHighDateTime;
- };
- struct SYSTEMTIME
- {
- boost::uint16_t wYear;
- boost::uint16_t wMonth;
- boost::uint16_t wDayOfWeek;
- boost::uint16_t wDay;
- boost::uint16_t wHour;
- boost::uint16_t wMinute;
- boost::uint16_t wSecond;
- boost::uint16_t wMilliseconds;
- };
- __declspec(dllimport) void __stdcall GetSystemTimeAsFileTime(FILETIME* lpFileTime);
- __declspec(dllimport) int __stdcall FileTimeToLocalFileTime(const FILETIME* lpFileTime, FILETIME* lpLocalFileTime);
- __declspec(dllimport) void __stdcall GetSystemTime(SYSTEMTIME* lpSystemTime);
- __declspec(dllimport) int __stdcall SystemTimeToFileTime(const SYSTEMTIME* lpSystemTime, FILETIME* lpFileTime);
- }
- #endif
- typedef FILETIME file_time;
- typedef SYSTEMTIME system_time;
- inline void get_system_time_as_file_time(file_time& ft)
- {
- #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205))
-
- file_time ft_utc;
- GetSystemTimeAsFileTime(&ft_utc);
- FileTimeToLocalFileTime(&ft_utc, &ft);
- #elif defined(BOOST_NO_GETSYSTEMTIMEASFILETIME)
- system_time st;
- GetSystemTime(&st);
- SystemTimeToFileTime(&st, &ft);
- #else
- GetSystemTimeAsFileTime(&ft);
- #endif
- }
-
- template< typename FileTimeT >
- inline boost::uint64_t file_time_to_microseconds(FileTimeT const& ft)
- {
-
- const uint64_t shift = 116444736000000000ULL;
- union {
- FileTimeT as_file_time;
- uint64_t as_integer;
- } caster;
- caster.as_file_time = ft;
- caster.as_integer -= shift;
- return (caster.as_integer / 10);
- }
- }
- template< typename TimeT, typename FileTimeT >
- inline
- TimeT time_from_ftime(const FileTimeT& ft)
- {
- typedef typename TimeT::date_type date_type;
- typedef typename TimeT::date_duration_type date_duration_type;
- typedef typename TimeT::time_duration_type time_duration_type;
-
-
-
-
-
- union {
- FileTimeT as_file_time;
- uint64_t as_integer;
- } caster;
- caster.as_file_time = ft;
- uint64_t sec = caster.as_integer / 10000000UL;
- uint32_t sub_sec = (caster.as_integer % 10000000UL)
- #if !defined(BOOST_DATE_TIME_POSIX_TIME_STD_CONFIG)
- / 10;
- #else
- * 100;
- #endif
-
- const uint32_t sec_per_day = 86400;
- uint32_t days = static_cast< uint32_t >(sec / sec_per_day);
- uint32_t tmp = static_cast< uint32_t >(sec % sec_per_day);
- uint32_t hours = tmp / 3600;
- tmp %= 3600;
- uint32_t minutes = tmp / 60;
- tmp %= 60;
- uint32_t seconds = tmp;
- date_duration_type dd(days);
- date_type d = date_type(1601, Jan, 01) + dd;
- return TimeT(d, time_duration_type(hours, minutes, seconds, sub_sec));
- }
- }}
- #endif
- #endif
|