1
0
mirror of https://github.com/catchorg/Catch2.git synced 2025-01-27 09:46:35 +00:00

Compare commits

...

2 Commits

Author SHA1 Message Date
Martin Hořeňovský
2dbe63a6ba
Merge pull request #2165 from catchorg/devel-gmtime-fixup
Use gmtime_r instead of gmtime when compiling for posixy platforms
2021-01-27 19:55:41 +01:00
Martin Hořeňovský
477540760a
Use gmtime_r instead of gmtime when compiling for posixy platforms 2021-01-27 11:49:52 +01:00

View File

@ -22,28 +22,22 @@ namespace Catch {
namespace {
std::string getCurrentTimestamp() {
// Beware, this is not reentrant because of backward compatibility issues
// Also, UTC only, again because of backward compatibility (%z is C++11)
time_t rawtime;
std::time(&rawtime);
auto const timeStampSize = sizeof("2017-01-16T17:06:45Z");
#ifdef _MSC_VER
std::tm timeInfo = {};
#ifdef _MSC_VER
gmtime_s(&timeInfo, &rawtime);
#else
std::tm* timeInfo;
timeInfo = std::gmtime(&rawtime);
gmtime_r(&rawtime, &timeInfo);
#endif
auto const timeStampSize = sizeof("2017-01-16T17:06:45Z");
char timeStamp[timeStampSize];
const char * const fmt = "%Y-%m-%dT%H:%M:%SZ";
#ifdef _MSC_VER
std::strftime(timeStamp, timeStampSize, fmt, &timeInfo);
#else
std::strftime(timeStamp, timeStampSize, fmt, timeInfo);
#endif
return std::string(timeStamp);
}