From: Amos Jeffries Date: Tue, 26 Mar 2024 20:17:04 +0000 (+0000) Subject: Refactor portions of getCurrentTime() to use std::chrono (#1755) X-Git-Tag: SQUID_7_0_1~159 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3d0d2c1a6ba0efb2789710635a7d9f692e49b3b0;p=thirdparty%2Fsquid.git Refactor portions of getCurrentTime() to use std::chrono (#1755) POSIX.1-2008 marks gettimeofday() as obsolete. --- diff --git a/src/time/gadgets.cc b/src/time/gadgets.cc index 3ab1b87bcf..d542dfacd4 100644 --- a/src/time/gadgets.cc +++ b/src/time/gadgets.cc @@ -11,6 +11,7 @@ #include "squid.h" #include "time/gadgets.h" +#include #include #include @@ -21,12 +22,11 @@ time_t squid_curtime = 0; time_t getCurrentTime() { -#if GETTIMEOFDAY_NO_TZP - gettimeofday(¤t_time); -#else + using namespace std::chrono; + const auto now = system_clock::now().time_since_epoch(); - gettimeofday(¤t_time, nullptr); -#endif + current_time.tv_sec = duration_cast(now).count(); + current_time.tv_usec = duration_cast(now).count() % 1000000; current_dtime = (double) current_time.tv_sec + (double) current_time.tv_usec / 1000000.0;