Use std::chrono instead of gettimeofday

This commit is contained in:
Tim Wojtulewicz 2022-10-29 18:31:11 -07:00 committed by Tomer Lev
parent ef096eedf3
commit fbcb7bd2ec

View file

@ -910,17 +910,12 @@ string Ascii::Timestamp(double t)
time_t teatime = time_t(t); time_t teatime = time_t(t);
if ( ! teatime ) if ( ! teatime )
{ teatime = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
// Use wall clock.
struct timeval tv;
if ( gettimeofday(&tv, 0) < 0 )
Error("gettimeofday failed");
else
teatime = tv.tv_sec;
}
struct tm tmbuf; struct tm tmbuf;
struct tm* tm = localtime_r(&teatime, &tmbuf); struct tm* tm = localtime_r(&teatime, &tmbuf);
if ( tm == nullptr )
Error(util::fmt("localtime_r failed: %s", strerror(errno)));
char tmp[128]; char tmp[128];
const char* const date_fmt = "%Y-%m-%d-%H-%M-%S"; const char* const date_fmt = "%Y-%m-%d-%H-%M-%S";