Centralize logic to get current server time

A few different implementations of computing the current time were
spread out through the code base, most of them using gettimeofday().

This centralizes the logic in CUtil::GetTime() for easier maintenance,
and also allows all call sites to get the benefit of the clock_gettime()
code path on systems that support it.
This commit is contained in:
Tor Arne Vestbø
2016-07-05 18:40:42 +02:00
committed by Tor Arne Vestbø
parent 852c9832a0
commit 02bfb9eaf5
6 changed files with 32 additions and 34 deletions

View File

@@ -95,11 +95,7 @@ TEST(UtilsTest, ServerTime) {
CString str1 = CUtils::FormatServerTime(tv1);
EXPECT_EQ("2011-10-19T16:40:51.620Z", str1);
timeval now;
if (gettimeofday(&now, nullptr)) {
now.tv_sec = time(nullptr);
now.tv_usec = 0;
}
timeval now = CUtils::GetTime();
// Strip microseconds, server time is ms only
now.tv_usec = (now.tv_usec / 1000) * 1000;