diff options
| author | ZXShady | 2025-09-12 00:52:11 +0300 |
|---|---|---|
| committer | Martin Hořeňovský | 2025-10-04 22:10:36 +0200 |
| commit | a58df2d7c59b037adca33c66c28ac63323d33cd4 (patch) | |
| tree | 951e88281c4ddda452b81687e90fe3c41dc4bcb4 /src/catch2/catch_tostring.cpp | |
| parent | a9223b2bb363c6e33bf1532b9cba0a472a69a023 (diff) | |
| download | catch3-a58df2d7c59b037adca33c66c28ac63323d33cd4.tar.gz | |
Outline part of formatting system_clock's time_point into cpp file
Diffstat (limited to 'src/catch2/catch_tostring.cpp')
| -rw-r--r-- | src/catch2/catch_tostring.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/catch2/catch_tostring.cpp b/src/catch2/catch_tostring.cpp index 20b0a629..dad62410 100644 --- a/src/catch2/catch_tostring.cpp +++ b/src/catch2/catch_tostring.cpp @@ -63,6 +63,30 @@ namespace Detail { return n; } + std::string formatTimeT(std::time_t time) { +#ifdef _MSC_VER + std::tm timeInfo = {}; + const auto err = gmtime_s( &timeInfo, &time ); + if ( err ) { + return "gmtime from provided timepoint has failed. This " + "happens e.g. with pre-1970 dates using Microsoft libc"; + } +#else + std::tm* timeInfo = std::gmtime( &time ); +#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, timeStampSize - 1 ); + } + std::string convertIntoString(StringRef string, bool escapeInvisibles) { std::string ret; // This is enough for the "don't escape invisibles" case, and a good |