]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/time/gadgets.cc
Refactor portions of getCurrentTime() to use std::chrono (#1755)
[thirdparty/squid.git] / src / time / gadgets.cc
index 3ab1b87bcfcbbcfe8ce6396ee252e50c06232a19..d542dfacd4ff738f1ca697568ac5c7a3692169ba 100644 (file)
@@ -11,6 +11,7 @@
 #include "squid.h"
 #include "time/gadgets.h"
 
+#include <chrono>
 #include <iomanip>
 #include <ostream>
 
@@ -21,12 +22,11 @@ time_t squid_curtime = 0;
 time_t
 getCurrentTime()
 {
-#if GETTIMEOFDAY_NO_TZP
-    gettimeofday(&current_time);
-#else
+    using namespace std::chrono;
+    const auto now = system_clock::now().time_since_epoch();
 
-    gettimeofday(&current_time, nullptr);
-#endif
+    current_time.tv_sec = duration_cast<seconds>(now).count();
+    current_time.tv_usec = duration_cast<microseconds>(now).count() % 1000000;
 
     current_dtime = (double) current_time.tv_sec +
                     (double) current_time.tv_usec / 1000000.0;