Returns the current time in milliseconds.
| 2291 | |
| 2292 | // Returns the current time in milliseconds. |
| 2293 | TimeInMillis GetTimeInMillis() { |
| 2294 | #if GTEST_OS_WINDOWS_MOBILE || defined(__BORLANDC__) |
| 2295 | // Difference between 1970-01-01 and 1601-01-01 in milliseconds. |
| 2296 | // http://analogous.blogspot.com/2005/04/epoch.html |
| 2297 | const TimeInMillis kJavaEpochToWinFileTimeDelta = |
| 2298 | static_cast<TimeInMillis>(116444736UL) * 100000UL; |
| 2299 | const DWORD kTenthMicrosInMilliSecond = 10000; |
| 2300 | |
| 2301 | SYSTEMTIME now_systime; |
| 2302 | FILETIME now_filetime; |
| 2303 | ULARGE_INTEGER now_int64; |
| 2304 | // TODO(kenton@google.com): Shouldn't this just use |
| 2305 | // GetSystemTimeAsFileTime()? |
| 2306 | GetSystemTime(&now_systime); |
| 2307 | if (SystemTimeToFileTime(&now_systime, &now_filetime)) { |
| 2308 | now_int64.LowPart = now_filetime.dwLowDateTime; |
| 2309 | now_int64.HighPart = now_filetime.dwHighDateTime; |
| 2310 | now_int64.QuadPart = (now_int64.QuadPart / kTenthMicrosInMilliSecond) - |
| 2311 | kJavaEpochToWinFileTimeDelta; |
| 2312 | return now_int64.QuadPart; |
| 2313 | } |
| 2314 | return 0; |
| 2315 | #elif GTEST_OS_WINDOWS && !GTEST_HAS_GETTIMEOFDAY_ |
| 2316 | __timeb64 now; |
| 2317 | |
| 2318 | // MSVC 8 deprecates _ftime64(), so we want to suppress warning 4996 |
| 2319 | // (deprecated function) there. |
| 2320 | // TODO(kenton@google.com): Use GetTickCount()? Or use |
| 2321 | // SystemTimeToFileTime() |
| 2322 | GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996) |
| 2323 | _ftime64(&now); |
| 2324 | GTEST_DISABLE_MSC_WARNINGS_POP_() |
| 2325 | |
| 2326 | return static_cast<TimeInMillis>(now.time) * 1000 + now.millitm; |
| 2327 | #elif GTEST_HAS_GETTIMEOFDAY_ |
| 2328 | struct timeval now; |
| 2329 | gettimeofday(&now, NULL); |
| 2330 | return static_cast<TimeInMillis>(now.tv_sec) * 1000 + now.tv_usec / 1000; |
| 2331 | #elif GTEST_OS_BARE_METAL |
| 2332 | return static_cast<TimeInMillis>(clock()); |
| 2333 | #else |
| 2334 | # error "Don't know how to get the current time on your system." |
| 2335 | #endif |
| 2336 | } |
| 2337 | |
| 2338 | // Utilities |
| 2339 |
no test coverage detected