Ticket #1740: date_time.patch
File date_time.patch, 6.8 KB (added by , 14 years ago) |
---|
-
boost/date_time/filetime_functions.hpp
17 17 18 18 #include <boost/date_time/compiler_config.hpp> 19 19 #if defined(BOOST_HAS_FTIME) // skip this file if no FILETIME 20 #include <windows.h> 20 21 # if defined( BOOST_USE_WINDOWS_H ) 22 # include <windows.h> 23 # else 24 25 struct _FILETIME; 26 typedef struct _FILETIME FILETIME; 27 28 # endif // !BOOST_USE_WINDOWS_H 29 21 30 #include <boost/cstdint.hpp> 22 31 #include <boost/date_time/time.hpp> 23 32 … … 45 54 const uint64_t OFFSET = (c1 << 32) + c2; 46 55 const long sec_pr_day = 86400; // seconds per day 47 56 48 uint64_t filetime = ft.dwHighDateTime;49 filetime <<= 32;50 filetime += ft.dwLowDateTime;57 uint64_t filetime = *reinterpret_cast<const uint64_t*>(&ft); 58 //filetime <<= 32; 59 //filetime += ft.dwLowDateTime; 51 60 filetime -= OFFSET; // filetime is now 100-nanos since 1970-Jan-01 52 61 53 62 uint64_t sec = filetime / 10000000; -
boost/date_time/microsec_time_clock.hpp
21 21 #include "boost/shared_ptr.hpp" 22 22 23 23 #ifdef BOOST_HAS_FTIME 24 #include <windows.h> 25 #endif 24 # if defined( BOOST_USE_WINDOWS_H ) 25 # include <windows.h> 26 # else 27 28 struct _FILETIME; 29 struct _SYSTEMTIME; 30 31 typedef struct _FILETIME FILETIME; 32 33 typedef struct _FILETIME *PFILETIME; 34 35 typedef struct _FILETIME *LPFILETIME; 36 37 typedef struct _SYSTEMTIME SYSTEMTIME; 38 39 typedef struct _SYSTEMTIME *PSYSTEMTIME; 40 41 typedef struct _SYSTEMTIME *LPSYSTEMTIME; 42 43 extern "C" __declspec(dllimport) void __stdcall GetSystemTimeAsFileTime( 44 LPFILETIME lpSystemTimeAsFileTime 45 ); 46 47 extern "C" __declspec(dllimport) int __stdcall FileTimeToLocalFileTime( 48 const FILETIME *lpFileTime, 49 LPFILETIME lpLocalFileTime 50 ); 51 52 extern "C" __declspec(dllimport) void __stdcall GetSystemTime( 53 LPSYSTEMTIME lpSystemTime 54 ); 55 56 extern "C" __declspec(dllimport) int __stdcall SystemTimeToFileTime( 57 const SYSTEMTIME *lpSystemTime, 58 LPFILETIME lpFileTime 59 ); 60 # endif // !BOOST_USE_WINDOWS_H 61 #endif //BOOST_HAS_FTIME 26 62 27 63 #ifdef BOOST_DATE_TIME_HAS_HIGH_PRECISION_CLOCK 28 64 … … 66 102 private: 67 103 // we want this enum available for both platforms yet still private 68 104 enum TZ_FOR_CREATE { LOCAL, GMT }; 69 105 70 106 public: 71 107 72 108 #ifdef BOOST_HAS_GETTIMEOFDAY … … 82 118 } 83 119 84 120 private: 85 121 static time_type create_time(TZ_FOR_CREATE tz) { 86 122 timeval tv; 87 123 gettimeofday(&tv, 0); //gettimeofday does not support TZ adjust on Linux. 88 124 std::time_t t = tv.tv_sec; … … 114 150 #ifdef BOOST_HAS_FTIME 115 151 //! Return the local time based on computer clock settings 116 152 static time_type local_time() { 117 F ILETIME ft;153 FAKE_FILETIME ft; 118 154 #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205)) 119 155 // Some runtime library implementations expect local times as the norm for ctime. 120 F ILETIME ft_utc;121 GetSystemTimeAsFileTime( &ft_utc);122 FileTimeToLocalFileTime( &ft_utc,&ft);156 FAKE_FILETIME ft_utc; 157 GetSystemTimeAsFileTime( reinterpret_cast<FILETIME*>(&ft_utc) ); 158 FileTimeToLocalFileTime( reinterpret_cast<FILETIME*>(&ft_utc), reinterpret_cast<FILETIME*>(&ft) ); 123 159 #elif defined(BOOST_NO_GETSYSTEMTIMEASFILETIME) 124 SYSTEMTIME st;160 FAKE_SYSTEMTIME st; 125 161 GetSystemTime( &st ); 126 SystemTimeToFileTime( &st, &ft);162 SystemTimeToFileTime( reinterpret_cast<SYSTEMTIME*>(&st), reinterpret_cast<FILETIME*>(&ft) ); 127 163 #else 128 GetSystemTimeAsFileTime( &ft);164 GetSystemTimeAsFileTime( reinterpret_cast<FILETIME*>(&ft) ); 129 165 #endif 130 return create_time( ft, LOCAL);166 return create_time( reinterpret_cast<FILETIME&>(ft), LOCAL); 131 167 } 132 168 133 169 //! Return the UTC time based on computer settings 134 170 static time_type universal_time() { 135 F ILETIME ft;171 FAKE_FILETIME ft; 136 172 #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205)) 137 173 // Some runtime library implementations expect local times as the norm for ctime. 138 F ILETIME ft_utc;139 GetSystemTimeAsFileTime( &ft_utc);140 FileTimeToLocalFileTime( &ft_utc,&ft);174 FAKE_FILETIME ft_utc; 175 GetSystemTimeAsFileTime( reinterpret_cast<FILETIME*>(&ft_utc) ); 176 FileTimeToLocalFileTime( reinterpret_cast<FILETIME*>(&ft_utc), reinterpret_cast<FILETIME*>(&ft) ); 141 177 #elif defined(BOOST_NO_GETSYSTEMTIMEASFILETIME) 142 SYSTEMTIME st;143 GetSystemTime( &st);144 SystemTimeToFileTime( &st, &ft);178 FAKE_SYSTEMTIME st; 179 GetSystemTime( reinterpret_cast<SYSTEMTIME*>(&st) ); 180 SystemTimeToFileTime( reinterpret_cast<SYSTEMTIME*>(&st), reinterpret_cast<FILETIME*>(&ft) ); 145 181 #else 146 GetSystemTimeAsFileTime( &ft);182 GetSystemTimeAsFileTime( reinterpret_cast<FILETIME*>(&ft) ); 147 183 #endif 148 return create_time( ft, GMT);184 return create_time( reinterpret_cast<FILETIME&>(ft), GMT); 149 185 } 150 186 151 187 private: 152 static time_type create_time(FILETIME& ft, TZ_FOR_CREATE tz) { 188 #if defined( BOOST_USE_WINDOWS_H ) 189 typedef FILETIME FAKE_FILETIME; 190 typedef SYSTEMTIME FAKE_SYSTEMTIME; 191 #else 192 struct FAKE_FILETIME { 193 unsigned long dwLowDateTime; 194 unsigned long dwHighDateTime; 195 }; 196 197 struct FAKE_SYSTEMTIME { 198 unsigned short wYear; 199 unsigned short wMonth; 200 unsigned short wDayOfWeek; 201 unsigned short wDay; 202 unsigned short wHour; 203 unsigned short wMinute; 204 unsigned short wSecond; 205 unsigned short wMilliseconds; 206 }; 207 #endif 208 209 static time_type create_time(FILETIME& ft, TZ_FOR_CREATE tz) { 153 210 // offset is difference (in 100-nanoseconds) from 154 211 // 1970-Jan-01 to 1601-Jan-01 155 212 boost::uint64_t c1 = 27111902; 156 213 boost::uint64_t c2 = 3577643008UL; // 'UL' removes compiler warnings 157 214 const boost::uint64_t OFFSET = (c1 << 32) + c2; 158 215 159 boost::uint64_t filetime = ft.dwHighDateTime;160 filetime = filetime << 32;161 filetime += ft.dwLowDateTime;216 boost::uint64_t filetime = *reinterpret_cast<boost::uint64_t*>(&ft); 217 //filetime = filetime << 32; 218 //filetime += ft.dwLowDateTime; 162 219 filetime -= OFFSET; 163 220 // filetime now holds 100-nanoseconds since 1970-Jan-01 164 221 -
libs/date_time/test/posix_time/testmicrosec_time_clock.cpp
9 9 #include "boost/date_time/microsec_time_clock.hpp" 10 10 #include "boost/date_time/testfrmwk.hpp" 11 11 12 //For SYSTEMTIME and GetSystemTime definitions 13 #if defined(BOOST_HAS_FTIME) 14 # include <windows.h> 15 #endif 12 16 13 17 int 14 18 main()