Skip to content

Commit

Permalink
Fix C++23 getDateTime()
Browse files Browse the repository at this point in the history
  • Loading branch information
kimwalisch committed Feb 14, 2024
1 parent b7ff936 commit d371315
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/app/stressTest.cpp
Expand Up @@ -187,16 +187,19 @@ std::string getDateTime()
#if __cplusplus >= 202301L
std::tm result;
std::time_t currentTime = std::time(nullptr);
if (std::localtime_r(&currentTime, &result) == nullptr)
if (localtime_r(&currentTime, &result) == nullptr)
return "";

std::ostringstream oss;
oss << std::put_time(result, "[%b %d %H:%M] ");
oss << std::put_time(&result, "[%b %d %H:%M] ");
return oss.str();
#else
// Not thread safe
#pragma warning(disable : 4996)

// Not thread safe.
// But we lock a mutex before calling getDateTime()
// hence this is not an issue for us.
#if defined(_MSC_VER)
#pragma warning(disable : 4996)
#endif
std::time_t currentTime = std::time(nullptr);
std::tm *currentDateTime = std::localtime(&currentTime);
std::ostringstream oss;
Expand Down

0 comments on commit d371315

Please sign in to comment.