Returns the current time in milliseconds.
| 2314 | |
| 2315 | // Returns the current time in milliseconds. |
| 2316 | TimeInMillis GetTimeInMillis() { |
| 2317 | #if GTEST_OS_WINDOWS_MOBILE || defined(__BORLANDC__) |
| 2318 | // Difference between 1970-01-01 and 1601-01-01 in milliseconds. |
| 2319 | // http://analogous.blogspot.com/2005/04/epoch.html |
| 2320 | const TimeInMillis kJavaEpochToWinFileTimeDelta = |
| 2321 | static_cast<TimeInMillis>(116444736UL) * 100000UL; |
| 2322 | const DWORD kTenthMicrosInMilliSecond = 10000; |
| 2323 | |
| 2324 | SYSTEMTIME now_systime; |
| 2325 | FILETIME now_filetime; |
| 2326 | ULARGE_INTEGER now_int64; |
| 2327 | GetSystemTime(&now_systime); |
| 2328 | if (SystemTimeToFileTime(&now_systime, &now_filetime)) { |
| 2329 | now_int64.LowPart = now_filetime.dwLowDateTime; |
| 2330 | now_int64.HighPart = now_filetime.dwHighDateTime; |
| 2331 | now_int64.QuadPart = (now_int64.QuadPart / kTenthMicrosInMilliSecond) - |
| 2332 | kJavaEpochToWinFileTimeDelta; |
| 2333 | return now_int64.QuadPart; |
| 2334 | } |
| 2335 | return 0; |
| 2336 | #elif GTEST_OS_WINDOWS && !GTEST_HAS_GETTIMEOFDAY_ |
| 2337 | __timeb64 now; |
| 2338 | |
| 2339 | // MSVC 8 deprecates _ftime64(), so we want to suppress warning 4996 |
| 2340 | // (deprecated function) there. |
| 2341 | GTEST_DISABLE_MSC_DEPRECATED_PUSH_() |
| 2342 | _ftime64(&now); |
| 2343 | GTEST_DISABLE_MSC_DEPRECATED_POP_() |
| 2344 | |
| 2345 | return static_cast<TimeInMillis>(now.time) * 1000 + now.millitm; |
| 2346 | #elif GTEST_HAS_GETTIMEOFDAY_ |
| 2347 | struct timeval now; |
| 2348 | gettimeofday(&now, nullptr); |
| 2349 | return static_cast<TimeInMillis>(now.tv_sec) * 1000 + now.tv_usec / 1000; |
| 2350 | #else |
| 2351 | # error "Don't know how to get the current time on your system." |
| 2352 | #endif |
| 2353 | } |
| 2354 | |
| 2355 | // Utilities |
| 2356 |
no outgoing calls
no test coverage detected